Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add getbalance #23

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]:18891/wallet/foowallet", []string{})
if err != nil {
log.Fatal(err)
}
fmt.Println(res)
}
```
Output:
```
map[bitcoin:0]
```

### Reissue Asset

```golang
package main

import (
Expand Down Expand Up @@ -36,7 +60,7 @@ Output:
### Send To Address


```
```golang
package main

import (
Expand Down Expand Up @@ -74,7 +98,7 @@ Output:
```

### Wallet management
```
```golang
package main

import (
Expand Down Expand Up @@ -113,7 +137,7 @@ Output:

### Complex Example

```
```golang
package main

import (
Expand Down
1 change: 1 addition & 0 deletions types/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ var (
MethodWalletpassphrase = "walletpassphrase"
MethodListWallets = "listwallets"
MethodListReceivedByAddress = "listreceivedbyaddress"
MethodGetBalance = "getbalance"
)
2 changes: 2 additions & 0 deletions types/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ type ListReceivedByAddressResult struct {

type WalletpassphraseResult struct {
}

type GetBalanceResult map[string]float64
12 changes: 12 additions & 0 deletions wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}