github.com/ZuluSpl0it/Sia@v1.3.7/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/NebulousLabs/Sia/node/api" 10 "github.com/NebulousLabs/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 // WalletAddressesGet requests the wallets known addresses from the 20 // /wallet/addresses endpoint. 21 func (c *Client) WalletAddressesGet() (wag api.WalletAddressesGET, err error) { 22 err = c.get("/wallet/addresses", &wag) 23 return 24 } 25 26 // WalletChangePasswordPost uses the /wallet/changepassword endpoint to change 27 // the wallet's password. 28 func (c *Client) WalletChangePasswordPost(currentPassword, newPassword string) (err error) { 29 values := url.Values{} 30 values.Set("newpassword", newPassword) 31 values.Set("encryptionpassword", currentPassword) 32 err = c.post("/wallet/changepassword", values.Encode(), nil) 33 return 34 } 35 36 // WalletInitPost uses the /wallet/init endpoint to initialize and encrypt a 37 // wallet 38 func (c *Client) WalletInitPost(password string, force bool) (wip api.WalletInitPOST, err error) { 39 values := url.Values{} 40 values.Set("encryptionpassword", password) 41 values.Set("force", strconv.FormatBool(force)) 42 err = c.post("/wallet/init", values.Encode(), &wip) 43 return 44 } 45 46 // WalletInitSeedPost uses the /wallet/init/seed endpoint to initialize and 47 // encrypt a wallet using a given seed. 48 func (c *Client) WalletInitSeedPost(seed, password string, force bool) (err error) { 49 values := url.Values{} 50 values.Set("seed", seed) 51 values.Set("encryptionpassword", password) 52 values.Set("force", strconv.FormatBool(force)) 53 err = c.post("/wallet/init/seed", values.Encode(), nil) 54 return 55 } 56 57 // WalletGet requests the /wallet api resource 58 func (c *Client) WalletGet() (wg api.WalletGET, err error) { 59 err = c.get("/wallet", &wg) 60 return 61 } 62 63 // WalletLockPost uses the /wallet/lock endpoint to lock the wallet. 64 func (c *Client) WalletLockPost() (err error) { 65 err = c.post("/wallet/lock", "", nil) 66 return 67 } 68 69 // WalletSeedPost uses the /wallet/seed endpoint to add a seed to the wallet's list 70 // of seeds. 71 func (c *Client) WalletSeedPost(seed, password string) (err error) { 72 values := url.Values{} 73 values.Set("seed", seed) 74 values.Set("encryptionpassword", password) 75 err = c.post("/wallet/seed", values.Encode(), nil) 76 return 77 } 78 79 // WalletSeedsGet uses the /wallet/seeds endpoint to return the wallet's 80 // current seeds. 81 func (c *Client) WalletSeedsGet() (wsg api.WalletSeedsGET, err error) { 82 err = c.get("/wallet/seeds", &wsg) 83 return 84 } 85 86 // WalletSiacoinsMultiPost uses the /wallet/siacoin api endpoint to send money 87 // to multiple addresses at once 88 func (c *Client) WalletSiacoinsMultiPost(outputs []types.SiacoinOutput) (wsp api.WalletSiacoinsPOST, err error) { 89 values := url.Values{} 90 marshaledOutputs, err := json.Marshal(outputs) 91 if err != nil { 92 return api.WalletSiacoinsPOST{}, err 93 } 94 values.Set("outputs", string(marshaledOutputs)) 95 err = c.post("/wallet/siacoins", values.Encode(), &wsp) 96 return 97 } 98 99 // WalletSiacoinsPost uses the /wallet/siacoins api endpoint to send money to a 100 // single address 101 func (c *Client) WalletSiacoinsPost(amount types.Currency, destination types.UnlockHash) (wsp api.WalletSiacoinsPOST, err error) { 102 values := url.Values{} 103 values.Set("amount", amount.String()) 104 values.Set("destination", destination.String()) 105 err = c.post("/wallet/siacoins", values.Encode(), &wsp) 106 return 107 } 108 109 // WalletSiafundsPost uses the /wallet/siafunds api endpoint to send siafunds 110 // to a single address. 111 func (c *Client) WalletSiafundsPost(amount types.Currency, destination types.UnlockHash) (wsp api.WalletSiafundsPOST, err error) { 112 values := url.Values{} 113 values.Set("amount", amount.String()) 114 values.Set("destination", destination.String()) 115 err = c.post("/wallet/siafunds", values.Encode(), &wsp) 116 return 117 } 118 119 // WalletSiagKeyPost uses the /wallet/siagkey endpoint to load a siag key into 120 // the wallet. 121 func (c *Client) WalletSiagKeyPost(keyfiles, password string) (err error) { 122 values := url.Values{} 123 values.Set("keyfiles", keyfiles) 124 values.Set("encryptionpassword", password) 125 err = c.post("/wallet/siagkey", values.Encode(), nil) 126 return 127 } 128 129 // WalletSweepPost uses the /wallet/sweep/seed endpoint to sweep a seed into 130 // the current wallet. 131 func (c *Client) WalletSweepPost(seed string) (wsp api.WalletSweepPOST, err error) { 132 values := url.Values{} 133 values.Set("seed", seed) 134 err = c.post("/wallet/sweep/seed", values.Encode(), &wsp) 135 return 136 } 137 138 // WalletTransactionsGet requests the/wallet/transactions api resource for a 139 // certain startheight and endheight 140 func (c *Client) WalletTransactionsGet(startHeight types.BlockHeight, endHeight types.BlockHeight) (wtg api.WalletTransactionsGET, err error) { 141 err = c.get(fmt.Sprintf("/wallet/transactions?startheight=%v&endheight=%v", 142 startHeight, endHeight), &wtg) 143 return 144 } 145 146 // WalletTransactionGet requests the /wallet/transaction/:id api resource for a 147 // certain TransactionID. 148 func (c *Client) WalletTransactionGet(id types.TransactionID) (wtg api.WalletTransactionGETid, err error) { 149 err = c.get("/wallet/transaction/"+id.String(), wtg) 150 return 151 } 152 153 // WalletUnlockPost uses the /wallet/unlock endpoint to unlock the wallet with 154 // a given encryption key. Per default this key is the seed. 155 func (c *Client) WalletUnlockPost(password string) (err error) { 156 values := url.Values{} 157 values.Set("encryptionpassword", password) 158 err = c.post("/wallet/unlock", values.Encode(), nil) 159 return 160 } 161 162 // Wallet033xPost uses the /wallet/033x endpoint to load a v0.3.3.x wallet into 163 // the current wallet. 164 func (c *Client) Wallet033xPost(path, password string) (err error) { 165 values := url.Values{} 166 values.Set("source", path) 167 values.Set("encryptionpassword", password) 168 err = c.post("/wallet/033x", values.Encode(), nil) 169 return 170 }