Skip to content

Commit

Permalink
feat: add getbalance
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenz Herzberger <[email protected]>
  • Loading branch information
LaurentMontBlanc committed Apr 3, 2024
1 parent c068faf commit c830e26
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
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
}

0 comments on commit c830e26

Please sign in to comment.