diff --git a/README.md b/README.md index f69253b..148a001 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,33 @@ ## Example usage -### Reissue Asset +### GetBalance +```golang +package main +import ( + "fmt" + "log" + + elementsrpc "github.com/rddl-network/elements-rpc" +) + +func main() { + res, err := elementsrpc.GetBalance("http://user:password@127.0.0.1:18891/wallet/foowallet", []string{}) + if err != nil { + log.Fatal(err) + } + fmt.Println(res) +} ``` +Output: +``` +map[bitcoin:0] +``` + +### Reissue Asset + +```golang package main import ( @@ -36,7 +60,7 @@ Output: ### Send To Address -``` +```golang package main import ( @@ -74,7 +98,7 @@ Output: ``` ### Wallet management -``` +```golang package main import ( @@ -113,7 +137,7 @@ Output: ### Complex Example -``` +```golang package main import ( diff --git a/types/const.go b/types/const.go index 2d6a463..a0a89af 100644 --- a/types/const.go +++ b/types/const.go @@ -27,4 +27,5 @@ var ( MethodWalletpassphrase = "walletpassphrase" MethodListWallets = "listwallets" MethodListReceivedByAddress = "listreceivedbyaddress" + MethodGetBalance = "getbalance" ) diff --git a/types/wallet.go b/types/wallet.go index fd21798..b46d86c 100644 --- a/types/wallet.go +++ b/types/wallet.go @@ -89,3 +89,5 @@ type ListReceivedByAddressResult struct { type WalletpassphraseResult struct { } + +type GetBalanceResult map[string]float64 diff --git a/wallet.go b/wallet.go index 33ec07b..b6c56ca 100644 --- a/wallet.go +++ b/wallet.go @@ -162,3 +162,15 @@ func ListReceivedByAddress(url string, params []string) (listReceivedByAddressRe } return } + +func GetBalance(url string, params []string) (getBalanceResult types.GetBalanceResult, err error) { + result, err := SendRequest(url, types.MethodGetBalance, params) + if err != nil { + return + } + err = json.Unmarshal(result, &getBalanceResult) + if err != nil { + return + } + return +}