github.com/Synthesix/Sia@v1.3.3-0.20180413141344-f863baeed3ca/node/api/client/wallet.go (about)

     1  package client
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"net/url"
     7  	"strconv"
     8  
     9  	"github.com/Synthesix/Sia/node/api"
    10  	"github.com/Synthesix/Sia/types"
    11  )
    12  
    13  // WalletAddressGet requests a new address from the /wallet/address endpoint
    14  func (c *Client) WalletAddressGet() (wag api.WalletAddressGET, err error) {
    15  	err = c.get("/wallet/address", &wag)
    16  	return
    17  }
    18  
    19  // WalletInitPost uses the /wallet/init endpoint to initialize and encrypt a
    20  // wallet
    21  func (c *Client) WalletInitPost(password string, force bool) (wip api.WalletInitPOST, err error) {
    22  	values := url.Values{}
    23  	values.Set("encryptionpassword", password)
    24  	values.Set("force", strconv.FormatBool(force))
    25  	err = c.post("/wallet/init", values.Encode(), &wip)
    26  	return
    27  }
    28  
    29  // WalletGet requests the /wallet api resource
    30  func (c *Client) WalletGet() (wg api.WalletGET, err error) {
    31  	err = c.get("/wallet", &wg)
    32  	return
    33  }
    34  
    35  // WalletSiacoinsMultiPost uses the /wallet/siacoin api endpoint to send money
    36  // to multiple addresses at once
    37  func (c *Client) WalletSiacoinsMultiPost(outputs []types.SiacoinOutput) (wsp api.WalletSiacoinsPOST, err error) {
    38  	values := url.Values{}
    39  	marshaledOutputs, err := json.Marshal(outputs)
    40  	if err != nil {
    41  		return api.WalletSiacoinsPOST{}, err
    42  	}
    43  	values.Set("outputs", string(marshaledOutputs))
    44  	err = c.post("/wallet/siacoins", values.Encode(), &wsp)
    45  	return
    46  }
    47  
    48  // WalletSiacoinsPost uses the /wallet/siacoins api endpoint to send money to a
    49  // single address
    50  func (c *Client) WalletSiacoinsPost(amount types.Currency, destination types.UnlockHash) (wsp api.WalletSiacoinsPOST, err error) {
    51  	values := url.Values{}
    52  	values.Set("amount", amount.String())
    53  	values.Set("destination", destination.String())
    54  	err = c.post("/wallet/siacoins", values.Encode(), &wsp)
    55  	return
    56  }
    57  
    58  // WalletTransactionsGet requests the/wallet/transactions api resource for a
    59  // certain startheight and endheight
    60  func (c *Client) WalletTransactionsGet(startHeight types.BlockHeight, endHeight types.BlockHeight) (wtg api.WalletTransactionsGET, err error) {
    61  	err = c.get(fmt.Sprintf("/wallet/transactions?startheight=%v&endheight=%v",
    62  		startHeight, endHeight), &wtg)
    63  	return
    64  }
    65  
    66  // WalletUnlockPost uses the /wallet/unlock endpoint to unlock the wallet with
    67  // a given encryption key. Per default this key is the seed.
    68  func (c *Client) WalletUnlockPost(password string) (err error) {
    69  	values := url.Values{}
    70  	values.Set("encryptionpassword", password)
    71  	err = c.post("/wallet/unlock", values.Encode(), nil)
    72  	return
    73  }