-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add txid-based eligibility proof check for incentivization PoC (#…
- Loading branch information
1 parent
e89c368
commit 222e15d
Showing
7 changed files
with
104 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import | ||
std/options, | ||
std/strscans, | ||
std/sequtils, | ||
testutils/unittests, | ||
chronicles, | ||
chronos, | ||
libp2p/crypto/crypto | ||
|
||
import stew/results, libp2p/peerid | ||
|
||
import | ||
../../../waku/incentivization/rpc, | ||
../../../waku/incentivization/rpc_codec, | ||
../../../waku/incentivization/common, | ||
../../../waku/incentivization/txid_proof | ||
|
||
|
||
proc isEligible*(eligibilityProof: EligibilityProof): Future[bool] {.async.} = | ||
result = await txidEligiblityCriteriaMet(eligibilityProof) | ||
|
||
proc genDummyResponseWithEligibilityStatus*(proofValid: bool, requestId: string = ""): DummyResponse = | ||
let eligibilityStatus = genEligibilityStatus(proofValid) | ||
result.requestId = requestId | ||
result.eligibilityStatus = eligibilityStatus | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import | ||
std/options, | ||
chronos, | ||
web3, | ||
stew/byteutils | ||
|
||
import ../../../waku/incentivization/rpc | ||
|
||
# a random confirmed txis (Sepolia) | ||
const TxHashExisting* = TxHash.fromHex( | ||
"0xc1be5f442d3688a8d3e4b5980a73f15e4351358e0f16e2fdd99c2517c9cf6270" | ||
) | ||
const TxHashNonExisting* = TxHash.fromHex( | ||
"0x0000000000000000000000000000000000000000000000000000000000000000" | ||
) | ||
|
||
const EthClient = "https://sepolia.infura.io/v3/470c2e9a16f24057aee6660081729fb9" | ||
|
||
proc genTxIdEligibilityProof*(txIdExists: bool): EligibilityProof = | ||
let txHash: TxHash = ( | ||
if txIdExists: | ||
TxHashExisting | ||
else: | ||
TxHashNonExisting) | ||
let txHashAsBytes = @(txHash.bytes()) | ||
EligibilityProof(proofOfPayment: some(txHashAsBytes)) | ||
|
||
proc genDummyRequestWithTxIdEligibilityProof*(proofValid: bool, requestId: string = ""): DummyRequest = | ||
let eligibilityProof = genTxIdEligibilityProof(proofValid) | ||
result.requestId = requestId | ||
result.eligibilityProof = eligibilityProof | ||
|
||
proc checkTxIdExists(txHash: TxHash): Future[bool] {.async.} = | ||
let web3 = await newWeb3(EthClient) | ||
try: | ||
discard await web3.provider.eth_getTransactionByHash(txHash) | ||
result = true | ||
except ValueError as e: | ||
result = false | ||
await web3.close() | ||
result | ||
|
||
proc txidEligiblityCriteriaMet*(eligibilityProof: EligibilityProof): Future[bool] {.async.} = | ||
if eligibilityProof.proofOfPayment.isNone(): | ||
return false | ||
let txHash = TxHash.fromHex(byteutils.toHex(eligibilityProof.proofOfPayment.get())) | ||
let txExists = await checkTxIdExists(txHash) | ||
return txExists |