secp: requiresInit
This commit is contained in:
parent
05f2a17ba4
commit
806547ddd1
13
web3.nim
13
web3.nim
|
@ -19,7 +19,7 @@ type
|
||||||
provider*: RpcClient
|
provider*: RpcClient
|
||||||
subscriptions*: Table[string, Subscription]
|
subscriptions*: Table[string, Subscription]
|
||||||
defaultAccount*: Address
|
defaultAccount*: Address
|
||||||
privateKey*: PrivateKey
|
privateKey*: Option[PrivateKey]
|
||||||
onDisconnect*: proc() {.gcsafe.}
|
onDisconnect*: proc() {.gcsafe.}
|
||||||
|
|
||||||
Sender*[T] = ref object
|
Sender*[T] = ref object
|
||||||
|
@ -724,16 +724,13 @@ proc getJsonLogs*(s: Sender,
|
||||||
|
|
||||||
s.web3.provider.eth_getLogs(options)
|
s.web3.provider.eth_getLogs(options)
|
||||||
|
|
||||||
proc signatureEnabled(w: Web3): bool {.inline.} =
|
|
||||||
w.privateKey.verify()
|
|
||||||
|
|
||||||
proc send*(web3: Web3, c: EthSend): Future[TxHash] {.async.} =
|
proc send*(web3: Web3, c: EthSend): Future[TxHash] {.async.} =
|
||||||
if web3.signatureEnabled():
|
if web3.privateKey.isSome():
|
||||||
var cc = c
|
var cc = c
|
||||||
if not cc.nonce.isSome:
|
if not cc.nonce.isSome:
|
||||||
let fromAddress = web3.privateKey.toPublicKey().tryGet().toCanonicalAddress.Address
|
let fromAddress = web3.privateKey.get().toPublicKey().toCanonicalAddress.Address
|
||||||
cc.nonce = some(int(await web3.provider.eth_getTransactionCount(fromAddress, "latest")))
|
cc.nonce = some(int(await web3.provider.eth_getTransactionCount(fromAddress, "latest")))
|
||||||
let t = "0x" & encodeTransaction(cc, web3.privateKey)
|
let t = "0x" & encodeTransaction(cc, web3.privateKey.get())
|
||||||
return await web3.provider.eth_sendRawTransaction(t)
|
return await web3.provider.eth_sendRawTransaction(t)
|
||||||
else:
|
else:
|
||||||
return await web3.provider.eth_sendTransaction(c)
|
return await web3.provider.eth_sendTransaction(c)
|
||||||
|
@ -747,7 +744,7 @@ proc send*(c: ContractCallBase, value = 0.u256, gas = 3000000'u64, gasPrice = 0)
|
||||||
cc.gas = some(Quantity(gas))
|
cc.gas = some(Quantity(gas))
|
||||||
cc.value = some(value)
|
cc.value = some(value)
|
||||||
|
|
||||||
if web3.signatureEnabled() or gasPrice != 0:
|
if web3.privateKey.isSome() or gasPrice != 0:
|
||||||
cc.gasPrice = some(gasPrice)
|
cc.gasPrice = some(gasPrice)
|
||||||
web3.send(cc)
|
web3.send(cc)
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,8 @@ import
|
||||||
proc signTransaction(tr: var Transaction, pk: PrivateKey) =
|
proc signTransaction(tr: var Transaction, pk: PrivateKey) =
|
||||||
let h = tr.txHashNoSignature
|
let h = tr.txHashNoSignature
|
||||||
let s = sign(pk, h)
|
let s = sign(pk, h)
|
||||||
if s.isErr:
|
|
||||||
raise newException(CatchableError, "Could not sign transaction: " & $s.error)
|
|
||||||
|
|
||||||
var r = toRaw(s[])
|
var r = toRaw(s)
|
||||||
let v = r[64]
|
let v = r[64]
|
||||||
|
|
||||||
tr.R = fromBytesBE(UInt256, r.toOpenArray(0, 31))
|
tr.R = fromBytesBE(UInt256, r.toOpenArray(0, 31))
|
||||||
|
|
Loading…
Reference in New Issue