chore(rln-relay-v2): use rln-v2 contract code (#2381)

* chore(rln-relay-v2): use rln-v2 contract code

* fix: reduced duped code
This commit is contained in:
Aaryamann Challani 2024-01-30 23:28:30 +05:30 committed by GitHub
parent 761ce7b10a
commit c55ca06756
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 43 additions and 122 deletions

View File

@ -119,7 +119,11 @@ clean: | clean-libbacktrace
.PHONY: librln
LIBRLN_BUILDDIR := $(CURDIR)/vendor/zerokit
ifeq ($(RLN_V2),true)
LIBRLN_VERSION := v0.4.1
else
LIBRLN_VERSION := v0.3.4
endif
ifeq ($(OS),Windows_NT)
LIBRLN_FILE := rln.lib
@ -134,6 +138,10 @@ $(LIBRLN_FILE):
librln: | $(LIBRLN_FILE)
$(eval NIM_PARAMS += --passL:$(LIBRLN_FILE) --passL:-lm)
ifeq ($(RLN_V2),true)
$(eval NIM_PARAMS += -d:rln_v2)
endif
clean-librln:
cargo clean --manifest-path vendor/zerokit/rln/Cargo.toml

View File

@ -40,6 +40,7 @@ proc generateCredentials(rlnInstance: ptr RLN, n: int): seq[IdentityCredential]
# a util function used for testing purposes
# it deploys membership contract on Ganache (or any Eth client available on EthClient address)
# must be edited if used for a different contract than membership contract
# <the difference between this and rln-v1 is that there is no need to deploy the poseidon hasher contract>
proc uploadRLNContract*(ethClientAddress: string): Future[Address] {.async.} =
let web3 = await newWeb3(ethClientAddress)
debug "web3 connected to", ethClientAddress
@ -53,27 +54,33 @@ proc uploadRLNContract*(ethClientAddress: string): Future[Address] {.async.} =
let balance = await web3.provider.eth_getBalance(web3.defaultAccount, "latest")
debug "Initial account balance: ", balance
# deploy the poseidon hash contract and gets its address
let
hasherReceipt = await web3.deployContract(PoseidonHasherCode)
hasherAddress = hasherReceipt.contractAddress.get
debug "hasher address: ", hasherAddress
when defined(rln_v2):
# deploy registry contract with its constructor inputs
let receipt = await web3.deployContract(RegistryContractCode)
else:
# deploy the poseidon hash contract and gets its address
let
hasherReceipt = await web3.deployContract(PoseidonHasherCode)
hasherAddress = hasherReceipt.contractAddress.get
debug "hasher address: ", hasherAddress
# encode registry contract inputs to 32 bytes zero-padded
let
hasherAddressEncoded = encode(hasherAddress).data
# this is the contract constructor input
contractInput = hasherAddressEncoded
# encode registry contract inputs to 32 bytes zero-padded
let
hasherAddressEncoded = encode(hasherAddress).data
# this is the contract constructor input
contractInput = hasherAddressEncoded
debug "encoded hasher address: ", hasherAddressEncoded
debug "encoded contract input:", contractInput
debug "encoded hasher address: ", hasherAddressEncoded
debug "encoded contract input:", contractInput
# deploy registry contract with its constructor inputs
let receipt = await web3.deployContract(RegistryContractCode,
contractInput = contractInput)
# deploy registry contract with its constructor inputs
let receipt = await web3.deployContract(RegistryContractCode,
contractInput = contractInput)
let contractAddress = receipt.contractAddress.get()
debug "Address of the deployed registry contract: ", contractAddress
let registryContract = web3.contractSender(WakuRlnRegistry, contractAddress)
@ -88,7 +95,6 @@ proc uploadRLNContract*(ethClientAddress: string): Future[Address] {.async.} =
return contractAddress
proc createEthAccount(): Future[(keys.PrivateKey, Address)] {.async.} =
let web3 = await newWeb3(EthClient)
let accounts = await web3.provider.eth_accounts()

File diff suppressed because one or more lines are too long