mirror of https://github.com/waku-org/nwaku.git
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:
parent
761ce7b10a
commit
c55ca06756
8
Makefile
8
Makefile
|
@ -119,7 +119,11 @@ clean: | clean-libbacktrace
|
||||||
.PHONY: librln
|
.PHONY: librln
|
||||||
|
|
||||||
LIBRLN_BUILDDIR := $(CURDIR)/vendor/zerokit
|
LIBRLN_BUILDDIR := $(CURDIR)/vendor/zerokit
|
||||||
|
ifeq ($(RLN_V2),true)
|
||||||
|
LIBRLN_VERSION := v0.4.1
|
||||||
|
else
|
||||||
LIBRLN_VERSION := v0.3.4
|
LIBRLN_VERSION := v0.3.4
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
LIBRLN_FILE := rln.lib
|
LIBRLN_FILE := rln.lib
|
||||||
|
@ -134,6 +138,10 @@ $(LIBRLN_FILE):
|
||||||
|
|
||||||
librln: | $(LIBRLN_FILE)
|
librln: | $(LIBRLN_FILE)
|
||||||
$(eval NIM_PARAMS += --passL:$(LIBRLN_FILE) --passL:-lm)
|
$(eval NIM_PARAMS += --passL:$(LIBRLN_FILE) --passL:-lm)
|
||||||
|
ifeq ($(RLN_V2),true)
|
||||||
|
$(eval NIM_PARAMS += -d:rln_v2)
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
clean-librln:
|
clean-librln:
|
||||||
cargo clean --manifest-path vendor/zerokit/rln/Cargo.toml
|
cargo clean --manifest-path vendor/zerokit/rln/Cargo.toml
|
||||||
|
|
|
@ -40,6 +40,7 @@ proc generateCredentials(rlnInstance: ptr RLN, n: int): seq[IdentityCredential]
|
||||||
# a util function used for testing purposes
|
# a util function used for testing purposes
|
||||||
# it deploys membership contract on Ganache (or any Eth client available on EthClient address)
|
# 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
|
# 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.} =
|
proc uploadRLNContract*(ethClientAddress: string): Future[Address] {.async.} =
|
||||||
let web3 = await newWeb3(ethClientAddress)
|
let web3 = await newWeb3(ethClientAddress)
|
||||||
debug "web3 connected to", 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")
|
let balance = await web3.provider.eth_getBalance(web3.defaultAccount, "latest")
|
||||||
debug "Initial account balance: ", balance
|
debug "Initial account balance: ", balance
|
||||||
|
|
||||||
# deploy the poseidon hash contract and gets its address
|
when defined(rln_v2):
|
||||||
let
|
# deploy registry contract with its constructor inputs
|
||||||
hasherReceipt = await web3.deployContract(PoseidonHasherCode)
|
let receipt = await web3.deployContract(RegistryContractCode)
|
||||||
hasherAddress = hasherReceipt.contractAddress.get
|
else:
|
||||||
debug "hasher address: ", hasherAddress
|
# 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
|
# encode registry contract inputs to 32 bytes zero-padded
|
||||||
let
|
let
|
||||||
hasherAddressEncoded = encode(hasherAddress).data
|
hasherAddressEncoded = encode(hasherAddress).data
|
||||||
# this is the contract constructor input
|
# this is the contract constructor input
|
||||||
contractInput = hasherAddressEncoded
|
contractInput = hasherAddressEncoded
|
||||||
|
|
||||||
|
|
||||||
debug "encoded hasher address: ", hasherAddressEncoded
|
debug "encoded hasher address: ", hasherAddressEncoded
|
||||||
debug "encoded contract input:", contractInput
|
debug "encoded contract input:", contractInput
|
||||||
|
|
||||||
# deploy registry contract with its constructor inputs
|
# deploy registry contract with its constructor inputs
|
||||||
let receipt = await web3.deployContract(RegistryContractCode,
|
let receipt = await web3.deployContract(RegistryContractCode,
|
||||||
contractInput = contractInput)
|
contractInput = contractInput)
|
||||||
|
|
||||||
let contractAddress = receipt.contractAddress.get()
|
let contractAddress = receipt.contractAddress.get()
|
||||||
|
|
||||||
debug "Address of the deployed registry contract: ", contractAddress
|
debug "Address of the deployed registry contract: ", contractAddress
|
||||||
|
|
||||||
let registryContract = web3.contractSender(WakuRlnRegistry, contractAddress)
|
let registryContract = web3.contractSender(WakuRlnRegistry, contractAddress)
|
||||||
|
@ -88,7 +95,6 @@ proc uploadRLNContract*(ethClientAddress: string): Future[Address] {.async.} =
|
||||||
|
|
||||||
return contractAddress
|
return contractAddress
|
||||||
|
|
||||||
|
|
||||||
proc createEthAccount(): Future[(keys.PrivateKey, Address)] {.async.} =
|
proc createEthAccount(): Future[(keys.PrivateKey, Address)] {.async.} =
|
||||||
let web3 = await newWeb3(EthClient)
|
let web3 = await newWeb3(EthClient)
|
||||||
let accounts = await web3.provider.eth_accounts()
|
let accounts = await web3.provider.eth_accounts()
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue