Skip to content

Commit

Permalink
Add new methods #2
Browse files Browse the repository at this point in the history
  • Loading branch information
LuaxY committed Aug 21, 2020
1 parent 6e5fe18 commit 8cca235
Show file tree
Hide file tree
Showing 88 changed files with 2,312 additions and 898 deletions.
33 changes: 20 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ func main() {
})

// check wallet balance
balance, unlocked, err := client.GetBalance()
balance, err := client.GetBalance(&walletrpc.GetBalanceRequest{
AccountIndex: 0,
})

// there are two types of error that can happen:
// connection errors
Expand All @@ -65,15 +67,15 @@ func main() {
os.Exit(1)
}

fmt.Println("Balance:", walletrpc.XMRToDecimal(balance))
fmt.Println("Unlocked balance:", walletrpc.XMRToDecimal(unlocked))
fmt.Println("Balance:", walletrpc.XMRToDecimal(balance.Balance))
fmt.Println("Unlocked balance:", walletrpc.XMRToDecimal(balance.UnlockedBalance))

// Make a transfer
res, err := client.Transfer(walletrpc.TransferRequest{
res, err := client.Transfer(&walletrpc.TransferRequest{
Destinations: []walletrpc.Destination{
{
Address: "45eoXYNHC4LcL2Hh42T9FMPTmZHyDEwDbgfBEuNj3RZUek8A4og4KiCfVL6ZmvHBfCALnggWtHH7QHF8426yRayLQq7MLf5",
Amount: 10*unit.Millinero, // 0.01 XMR
Amount: 10 * unit.Millinero, // 0.01 XMR
},
},
Priority: walletrpc.PriorityUnimportant,
Expand All @@ -89,7 +91,7 @@ func main() {
fmt.Println("Error:", err.Error())
os.Exit(1)
}
fmt.Println("Transfer success! Fee:", walletrpc.XMRToDecimal(res.Fee), "Hash:", res.TxHash)
fmt.Println("Transfer success! Fee:", walletrpc.XMRToDecimal(uint64(res.Fee)), "Hash:", res.TxHash)
}
```

Expand All @@ -105,8 +107,9 @@ package main
import (
"fmt"

"github.com/gabstv/httpdigest"

"github.com/LuaxY/go-monero/walletrpc"
"github.com/LuaxY/httpdigest"
)

func main() {
Expand All @@ -119,13 +122,15 @@ func main() {
Transport: t,
})

balance, unlocked, err := client.GetBalance()
balance, err := client.GetBalance(&walletrpc.GetBalanceRequest{
AccountIndex: 0,
})

if err != nil {
panic(err)
}
fmt.Println("balance", walletrpc.XMRToDecimal(balance))
fmt.Println("unlocked balance", walletrpc.XMRToDecimal(unlocked))
fmt.Println("balance", walletrpc.XMRToDecimal(balance.Balance))
fmt.Println("unlocked balance", walletrpc.XMRToDecimal(balance.UnlockedBalance))
}
```

Expand Down Expand Up @@ -192,7 +197,9 @@ func main() {
})

// check wallet balance
balance, unlocked, err := client.GetBalance()
balance, err := client.GetBalance(&walletrpc.GetBalanceRequest{
AccountIndex: 0,
})

// there are two types of error that can happen:
// connection errors
Expand All @@ -209,8 +216,8 @@ func main() {
os.Exit(1)
}

fmt.Println("Balance:", walletrpc.XMRToDecimal(balance))
fmt.Println("Unlocked balance:", walletrpc.XMRToDecimal(unlocked))
fmt.Println("Balance:", walletrpc.XMRToDecimal(balance.Balance))
fmt.Println("Unlocked balance:", walletrpc.XMRToDecimal(balance.UnlockedBalance))
}
```

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module github.com/LuaxY/go-monero

go 1.13
go 1.15

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabstv/httpdigest v0.0.0-20180129153118-c898b29b0dc2
github.com/gorilla/rpc v1.2.1-0.20190627040322-27d3316e212c
github.com/iancoleman/strcase v0.1.0
github.com/kr/pretty v0.1.0 // indirect
github.com/stretchr/testify v1.4.0
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/gorilla/rpc v1.2.0 h1:WvvdC2lNeT1SP32zrIce5l0ECBfbAlmrmSBsuc57wfk=
github.com/gorilla/rpc v1.2.0/go.mod h1:V4h9r+4sF5HnzqbwIez0fKSpANP0zlYd3qR7p36jkTQ=
github.com/gorilla/rpc v1.2.1-0.20190627040322-27d3316e212c h1:2eBas5y4Sohp73YjGoobKPssaY9Jw6J0AerL2r835pU=
github.com/gorilla/rpc v1.2.1-0.20190627040322-27d3316e212c/go.mod h1:V4h9r+4sF5HnzqbwIez0fKSpANP0zlYd3qR7p36jkTQ=
github.com/iancoleman/strcase v0.1.0 h1:Lar8rut26AXkJUmVOb2bRsFGv//+tJBeJLxXvpZpF1Q=
github.com/iancoleman/strcase v0.1.0/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
22 changes: 22 additions & 0 deletions walletrpc/add_address_book.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package walletrpc

type AddAddressBookRequest struct {
Address string `json:"address"`
PaymentId string `json:"payment_id"`
Description string `json:"description"`
}

type AddAddressBookResponse struct {
// Index The index of the address book entry.
Index uint64 `json:"index"`
}

// AddAddressBook Add an entry to the address book.
func (c *Client) AddAddressBook(req *AddAddressBookRequest) (*AddAddressBookResponse, error) {
resp := &AddAddressBookResponse{}
err := c.do("add_address_book", &req, resp)
if err != nil {
return nil, err
}
return resp, nil
}
18 changes: 18 additions & 0 deletions walletrpc/auto_refresh.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package walletrpc

type AutoRefreshRequest struct {
// Enable (Optional) Enable or disable automatic refreshing (default = true).
Enable bool `json:"enable"`

// Period (Optional) The period of the wallet refresh cycle (i.e. time between refreshes) in seconds.
Period uint64 `json:"period"`
}

// AutoRefresh Set whether and how often to automatically refresh the current wallet.
func (c *Client) AutoRefresh(req *AutoRefreshRequest) error {
err := c.do("auto_refresh", &req, nil)
if err != nil {
return err
}
return nil
}
18 changes: 18 additions & 0 deletions walletrpc/change_wallet_password.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package walletrpc

type ChangeWalletPasswordRequest struct {
// OldPassword (Optional) Current wallet password, if defined.
OldPassword string `json:"old_password"`

// NewPassword (Optional) New wallet password, if not blank.
NewPassword string `json:"new_password"`
}

// ChangeWalletPassword Change a wallet password.
func (c *Client) ChangeWalletPassword(req *ChangeWalletPasswordRequest) error {
err := c.do("change_wallet_password", &req, nil)
if err != nil {
return err
}
return nil
}
27 changes: 27 additions & 0 deletions walletrpc/check_reserve_proof.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package walletrpc

type CheckReserveProofRequest struct {
// Address Public address of the wallet.
Address string `json:"address"`

// Message (Optional) Should be the same message used in get_reserve_proof.
Message string `json:"message"`

// Signature reserve signature to confirm.
Signature string `json:"signature"`
}

type CheckReserveProofResponse struct {
// Good States if the inputs proves the reserve.
Good bool `json:"good"`
}

// CheckReserveProof Proves a wallet has a disposable reserve using a signature.
func (c *Client) CheckReserveProof(req *CheckReserveProofRequest) (*CheckReserveProofResponse, error) {
resp := &CheckReserveProofResponse{}
err := c.do("check_reserve_proof", &req, resp)
if err != nil {
return nil, err
}
return resp, nil
}
27 changes: 27 additions & 0 deletions walletrpc/check_spend_proof.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package walletrpc

type CheckSpendProofRequest struct {
// Txid transaction id.
Txid string `json:"txid"`

// Message (Optional) Should be the same message used in get_spend_proof.
Message string `json:"message"`

// Signature spend signature to confirm.
Signature string `json:"signature"`
}

type CheckSpendProofResponse struct {
// Good States if the inputs proves the spend.
Good bool `json:"good"`
}

// CheckSpendProof Prove a spend using a signature. Unlike proving a transaction, it does not requires the destination public address.
func (c *Client) CheckSpendProof(req *CheckSpendProofRequest) (*CheckSpendProofResponse, error) {
resp := &CheckSpendProofResponse{}
err := c.do("check_spend_proof", &req, resp)
if err != nil {
return nil, err
}
return resp, nil
}
33 changes: 33 additions & 0 deletions walletrpc/check_tx_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package walletrpc

type CheckTxKeyRequest struct {
// Txid transaction id.
Txid string `json:"txid"`

// TxKey transaction secret key.
TxKey string `json:"tx_key"`

// Address destination public address of the transaction.
Address string `json:"address"`
}

type CheckTxKeyResponse struct {
// Confirmations Number of block mined after the one with the transaction.
Confirmations uint64 `json:"confirmations"`

// InPool States if the transaction is still in pool or has been added to a block.
InPool bool `json:"in_pool"`

// Received Amount of the transaction.
Received uint64 `json:"received"`
}

// CheckTxKey Check a transaction in the blockchain with its secret key.
func (c *Client) CheckTxKey(req *CheckTxKeyRequest) (*CheckTxKeyResponse, error) {
resp := &CheckTxKeyResponse{}
err := c.do("check_tx_key", &req, resp)
if err != nil {
return nil, err
}
return resp, nil
}
39 changes: 39 additions & 0 deletions walletrpc/check_tx_proof.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package walletrpc

type CheckTxProofRequest struct {
// Txid transaction id.
Txid string `json:"txid"`

// Address destination public address of the transaction.
Address string `json:"address"`

// Message (Optional) Should be the same message used in get_tx_proof.
Message string `json:"message"`

// Signature transaction signature to confirm.
Signature string `json:"signature"`
}

type CheckTxProofResponse struct {
// Confirmations Number of block mined after the one with the transaction.
Confirmations uint64 `json:"confirmations"`

// Good States if the inputs proves the transaction.
Good bool `json:"good"`

// InPool States if the transaction is still in pool or has been added to a block.
InPool bool `json:"in_pool"`

// Received Amount of the transaction.
Received uint64 `json:"received"`
}

// CheckTxProof Prove a transaction by checking its signature.
func (c *Client) CheckTxProof(req *CheckTxProofRequest) (*CheckTxProofResponse, error) {
resp := &CheckTxProofResponse{}
err := c.do("check_tx_proof", &req, resp)
if err != nil {
return nil, err
}
return resp, nil
}
Loading

0 comments on commit 8cca235

Please sign in to comment.