mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-05-02 00:23:07 +00:00
chore: change datatype converstion
This commit is contained in:
parent
afcbf0a544
commit
6b3e26b5f8
@ -68,7 +68,7 @@ type
|
|||||||
keystorePassword*: Option[string]
|
keystorePassword*: Option[string]
|
||||||
registrationHandler*: Option[RegistrationHandler]
|
registrationHandler*: Option[RegistrationHandler]
|
||||||
latestProcessedBlock*: BlockNumber
|
latestProcessedBlock*: BlockNumber
|
||||||
merkleProofCache*: seq[UInt256]
|
merkleProofCache*: array[20, UInt256]
|
||||||
|
|
||||||
proc setMetadata*(
|
proc setMetadata*(
|
||||||
g: OnchainGroupManager, lastProcessedBlock = none(BlockNumber)
|
g: OnchainGroupManager, lastProcessedBlock = none(BlockNumber)
|
||||||
@ -106,7 +106,7 @@ proc fetchMerkleProofElements*(
|
|||||||
debug "------ checking if membership index is validity ------",
|
debug "------ checking if membership index is validity ------",
|
||||||
membershipIndex = membershipIndex,
|
membershipIndex = membershipIndex,
|
||||||
membershipIndexUint256 = membershipIndexUint256,
|
membershipIndexUint256 = membershipIndexUint256,
|
||||||
currentCommitmentIndex = currentCommitmentIndex,
|
currentCommitmentIndex = currentCommitmentIndex,
|
||||||
index40 = index40
|
index40 = index40
|
||||||
|
|
||||||
if membershipIndexUint256 >= currentCommitmentIndex:
|
if membershipIndexUint256 >= currentCommitmentIndex:
|
||||||
@ -135,13 +135,16 @@ proc fetchMerkleProofElements*(
|
|||||||
|
|
||||||
let responseBytes = await g.ethRpc.get().provider.eth_call(tx, "latest")
|
let responseBytes = await g.ethRpc.get().provider.eth_call(tx, "latest")
|
||||||
|
|
||||||
var merkleProof: seq[UInt256]
|
var merkleProof: array[20, UInt256]
|
||||||
|
|
||||||
for i in 0 .. 19:
|
for i in 0 ..< 20:
|
||||||
let startindex = 32 + (i * 32) # skip initial 32 bytes for the array offset
|
merkleProof[i] = UInt256.fromBytes(newSeq[byte](32))
|
||||||
|
|
||||||
|
for i in 0 ..< 20:
|
||||||
|
let startindex = 32 + (i * 32)
|
||||||
if startindex + 32 <= responseBytes.len:
|
if startindex + 32 <= responseBytes.len:
|
||||||
let elementbytes = responseBytes[startindex ..< startindex + 32]
|
let elementbytes = responseBytes[startindex ..< startindex + 32]
|
||||||
merkleProof.add(UInt256.fromBytesBE(elementbytes))
|
merkleProof[i] = UInt256.fromBytesBE(elementbytes)
|
||||||
|
|
||||||
return ok(merkleProof)
|
return ok(merkleProof)
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
@ -379,8 +382,8 @@ proc toArray32*(s: seq[byte]): array[32, byte] =
|
|||||||
discard output.copyFrom(s)
|
discard output.copyFrom(s)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
proc toArray32Seq*(values: seq[UInt256]): seq[array[32, byte]] =
|
proc toArray32Seq*(values: array[20, UInt256]): seq[array[32, byte]] =
|
||||||
## Converts a MerkleProof (array of 20 UInt256 values) to a sequence of 32-byte arrays
|
## Converts a MerkleProof (fixed array of 20 UInt256 values) to a sequence of 32-byte arrays
|
||||||
result = newSeqOfCap[array[32, byte]](values.len)
|
result = newSeqOfCap[array[32, byte]](values.len)
|
||||||
for value in values:
|
for value in values:
|
||||||
result.add(value.toBytesLE())
|
result.add(value.toBytesLE())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user