From c0b4602f460296b998b77c605187fa9a5e519042 Mon Sep 17 00:00:00 2001 From: "nathan.eth" <39421782+natclark@users.noreply.github.com> Date: Sun, 9 Jan 2022 18:51:35 -0800 Subject: [PATCH] make getBalance return bal @ last block by default --- Sources/SafariWalletCore/Provider/ProviderAPI.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/SafariWalletCore/Provider/ProviderAPI.swift b/Sources/SafariWalletCore/Provider/ProviderAPI.swift index 4b19148..0e26939 100644 --- a/Sources/SafariWalletCore/Provider/ProviderAPI.swift +++ b/Sources/SafariWalletCore/Provider/ProviderAPI.swift @@ -113,10 +113,14 @@ public struct ProviderAPI { case "eth_getBalance": // https://eth.wiki/json-rpc/API#eth_getbalance - guard let params = params as? [String], params.count == 2 else { + guard let params = params as? [String], params.count > 0, params.count < 3 else { throw WalletCoreError.invalidParams } - let result = try await client.ethGetBalance(address: params[0], blockNumber: Block(rawValue: params[1])) + if params.count == 2 { + let result = try await client.ethGetBalance(address: params[0], blockNumber: Block(rawValue: params[1])) + } else { + let result = try await client.ethGetBalance(address: params[0], blockNumber: Block(rawValue: "latest")) + } return result.hexString case "eth_sendTransaction": @@ -126,7 +130,7 @@ public struct ProviderAPI { case "eth_sign": // https://eth.wiki/json-rpc/API#eth_sign - guard let params = params as? [String], params.count >= 2 else { + guard let params = params as? [String], params.count == 2 else { throw WalletCoreError.invalidParams } let address = params[0]