From 1af3ab1a0aa76258c4729c32232ae39a638ce218 Mon Sep 17 00:00:00 2001 From: Jackie Date: Thu, 21 Jul 2022 02:04:05 +0200 Subject: [PATCH] Make wallet use Provider not JsonRpcProvider --- ethers/provider.nim | 3 +++ ethers/wallet.nim | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ethers/provider.nim b/ethers/provider.nim index e659f9b..15508b6 100644 --- a/ethers/provider.nim +++ b/ethers/provider.nim @@ -82,6 +82,9 @@ method estimateGas*(provider: Provider, method getChainId*(provider: Provider): Future[UInt256] {.base.} = doAssert false, "not implemented" +method sendRawTransaction*(provider: Provider, rawTransaction: seq[byte]): Future[TransactionResponse] {.base, async.} = + doAssert false, "not implemented" + method subscribe*(provider: Provider, filter: Filter, callback: LogHandler): diff --git a/ethers/wallet.nim b/ethers/wallet.nim index f8b48fd..f861955 100644 --- a/ethers/wallet.nim +++ b/ethers/wallet.nim @@ -3,7 +3,7 @@ import eth/rlp import eth/common import eth/common/transaction as ct import stew/byteutils -import ./providers/jsonrpc +import ./provider import ./transaction import ./signer @@ -23,9 +23,9 @@ type Wallet* = ref object of Signer privateKey*: PrivateKey publicKey*: PublicKey address*: Address - provider*: ?JsonRpcProvider + provider*: ?Provider -proc new*(_: type Wallet, pk: string, provider: JsonRpcProvider): Wallet = +proc new*(_: type Wallet, pk: string, provider: Provider): Wallet = result = Wallet() result.privateKey = PrivateKey.fromHex(pk).value result.publicKey = result.privateKey.toPublicKey() @@ -36,14 +36,14 @@ proc new*(_: type Wallet, pk: string): Wallet = result.privateKey = PrivateKey.fromHex(pk).value result.publicKey = result.privateKey.toPublicKey() result.address = Address.init(result.publicKey.toCanonicalAddress()) -proc connect*(wallet: Wallet, provider: JsonRpcProvider) = +proc connect*(wallet: Wallet, provider: Provider) = wallet.provider = some provider proc createRandom*(_: type Wallet): Wallet = result = Wallet() result.privateKey = PrivateKey.random(getRng()[]) result.publicKey = result.privateKey.toPublicKey() result.address = Address.init(result.publicKey.toCanonicalAddress()) -proc createRandom*(_: type Wallet, provider: JsonRpcProvider): Wallet = +proc createRandom*(_: type Wallet, provider: Provider): Wallet = result = Wallet() result.privateKey = PrivateKey.random(getRng()[]) result.publicKey = result.privateKey.toPublicKey()