OSDN Git Service

add listAddresses
authorChengcheng Zhang <943420582@qq.com>
Thu, 22 Aug 2019 11:29:08 +0000 (19:29 +0800)
committerChengcheng Zhang <943420582@qq.com>
Thu, 22 Aug 2019 11:29:08 +0000 (19:29 +0800)
main.go

diff --git a/main.go b/main.go
index 96fb4a7..4f7227c 100644 (file)
--- a/main.go
+++ b/main.go
@@ -9,13 +9,18 @@ import (
 )
 
 var (
-       localURL        = "http://127.0.0.1:9888/"
-       listAccountsURL = localURL + "list-accounts"
-       listBalancesURL = localURL + "list-balances"
+       localURL         = "http://127.0.0.1:9888/"
+       compileURL       = localURL + "compile"
+       listAccountsURL  = localURL + "list-accounts"
+       listAddressesURL = localURL + "list-addresses"
+       listBalancesURL  = localURL + "list-balances"
 )
 
 func main() {
        listBalances()
+       listAccounts()
+       addresses := listAddresses("a1")
+       fmt.Println(addresses)
 }
 
 func request(URL string, data []byte) []byte {
@@ -29,13 +34,58 @@ func request(URL string, data []byte) []byte {
        }
        defer resp.Body.Close()
 
-       body, _ := ioutil.ReadAll(resp.Body)
+       body, err := ioutil.ReadAll(resp.Body)
+       if err != nil {
+               fmt.Println(err)
+       }
        fmt.Println("response Body:", string(body))
        return body
 }
 
-func listAccounts() {
+type Account struct {
+       AccountID    string `json:"id"`
+       AccountAlias string `json:"alias"`
+}
+
+type Accounts struct {
+       Status string    `json:"status"`
+       Data   []Account `json:"data"`
+}
+
+func listAccounts() []Account {
+       data := []byte(`{}`)
+       body := request(listAccountsURL, data)
+
+       accounts := new(Accounts)
+       if err := json.Unmarshal(body, accounts); err != nil {
+               fmt.Println(err)
+       }
+       return accounts.Data
+}
+
+type Address struct {
+       AccountAlias   string `json:"account_alias"`
+       AccountID      string `json:"account_id"`
+       Address        string `json:"address"`
+       ControlProgram string `json:"control_program"`
+       Change         bool   `json:"change"`
+       KeyIndex       uint64 `json:"key_index"`
+}
+
+type Addresses struct {
+       Status string    `json:"status"`
+       Data   []Address `json:"data"`
+}
 
+func listAddresses(accountAlias string) []Address {
+       data := []byte(`{"account_alias": "` + accountAlias + `"}`)
+       body := request(listAddressesURL, data)
+
+       addresses := new(Addresses)
+       if err := json.Unmarshal(body, addresses); err != nil {
+               fmt.Println(err)
+       }
+       return addresses.Data
 }
 
 type Balance struct {
@@ -49,7 +99,7 @@ type Balances struct {
 }
 
 func listBalances() {
-       var data = []byte(`{
+       data := []byte(`{
                "account_alias": "a1"
                }`)
        body := request(listBalancesURL, data)
@@ -58,7 +108,33 @@ func listBalances() {
        if err := json.Unmarshal(body, balances); err != nil {
                fmt.Println(err)
        }
-       fmt.Println("balances:", balances)
-       fmt.Println("status: ", balances.Status)
-       fmt.Println("amount: ", balances.Data[0].Amount)
+       // fmt.Println("balances:", balances)
+       // fmt.Println("status: ", balances.Status)
+       // fmt.Println("amount: ", balances.Data[0].Amount)
+}
+
+func compile() {
+       // data := []byte(`{
+       //      "contract":"contract TradeOffer(assetRequested: Asset, amountRequested: Amount, seller: Program, cancelKey: PublicKey) locks valueAmount of valueAsset { clause trade() { lock amountRequested of assetRequested with seller unlock valueAmount of valueAsset } clause cancel(sellerSig: Signature) { verify checkTxSig(cancelKey, sellerSig) unlock valueAmount of valueAsset}}",
+       //      "args":[
+       //              {
+       //                      "string":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
+       //              },
+       //              {
+       //                      "integer":1000000000
+       //              },
+       //              {
+       //                      "string":"00145dd7b82556226d563b6e7d573fe61d23bd461c1f"
+       //              },
+       //              {
+       //                      "string":"3e5d7d52d334964eef173021ef6a04dc0807ac8c41700fe718f5a80c2109f79e"
+       //              }
+       //      ]
+       // }`)
+       // body := request(compileURL, data)
+
+}
+
+func builTransaction() {
+
 }