Browse Source

Simplify by passing private keys into getAccountInfo

xno
codesoap 10 months ago
parent
commit
26e595913d
  1. 7
      account.go
  2. 6
      balance.go
  3. 6
      change.go
  4. 6
      send.go

7
account.go

@ -3,6 +3,7 @@ package main @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"math/big"
)
var errAccountNotFound = fmt.Errorf("account has not yet been opened")
@ -19,7 +20,11 @@ type blockInfo struct { @@ -19,7 +20,11 @@ type blockInfo struct {
Contents block `json:"contents"`
}
func getAccountInfo(address string) (info accountInfo, err error) {
func getAccountInfo(privateKey *big.Int) (info accountInfo, err error) {
address, err := getAddress(privateKey)
if err != nil {
return
}
requestBody := fmt.Sprintf(`{`+
`"action": "account_info",`+
`"account": "%s",`+

6
balance.go

@ -39,12 +39,8 @@ func printBalance() error { @@ -39,12 +39,8 @@ func printBalance() error {
return err
}
privateKey := getPrivateKey(seed, uint32(accountIndexFlag))
address, err := getAddress(privateKey)
if err != nil {
return err
}
info, err := getAccountInfo(address)
info, err := getAccountInfo(privateKey)
if err == errAccountNotFound {
// This info is needed to create the first block:
info.Frontier = "0000000000000000000000000000000000000000000000000000000000000000"

6
change.go

@ -13,11 +13,7 @@ func changeRepresentative() error { @@ -13,11 +13,7 @@ func changeRepresentative() error {
return err
}
privateKey := getPrivateKey(seed, uint32(accountIndexFlag))
address, err := getAddress(privateKey)
if err != nil {
return err
}
info, err := getAccountInfo(address)
info, err := getAccountInfo(privateKey)
if err != nil {
return err
}

6
send.go

@ -18,11 +18,7 @@ func sendFunds() error { @@ -18,11 +18,7 @@ func sendFunds() error {
return err
}
privateKey := getPrivateKey(seed, uint32(accountIndexFlag))
address, err := getAddress(privateKey)
if err != nil {
return err
}
info, err := getAccountInfo(address)
info, err := getAccountInfo(privateKey)
if err != nil {
return err
}

Loading…
Cancel
Save