OSDN Git Service

add account.go
authorChengcheng Zhang <943420582@qq.com>
Tue, 27 Aug 2019 07:52:39 +0000 (15:52 +0800)
committerChengcheng Zhang <943420582@qq.com>
Tue, 27 Aug 2019 07:52:39 +0000 (15:52 +0800)
swap/account.go [new file with mode: 0644]
swap/contract.go

diff --git a/swap/account.go b/swap/account.go
new file mode 100644 (file)
index 0000000..023a5c2
--- /dev/null
@@ -0,0 +1,99 @@
+package swap
+
+import (
+       "encoding/json"
+       "fmt"
+)
+
+type Account struct {
+       AccountID    string `json:"id"`
+       AccountAlias string `json:"alias"`
+}
+
+type AccountsResponse struct {
+       Status string    `json:"status"`
+       Data   []Account `json:"data"`
+}
+
+func ListAccounts() []Account {
+       data := []byte(`{}`)
+       body := request(listAccountsURL, data)
+
+       accountsResp := new(AccountsResponse)
+       if err := json.Unmarshal(body, accountsResp); err != nil {
+               fmt.Println(err)
+       }
+       return accountsResp.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 AddressesResponse 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(AddressesResponse)
+       if err := json.Unmarshal(body, addresses); err != nil {
+               fmt.Println(err)
+       }
+       return addresses.Data
+}
+
+type Balance struct {
+       AccountID string `json:"account_id"`
+       Amount    uint64 `json:"amount"`
+}
+
+type BalancesResponse struct {
+       Status string    `json:"status"`
+       Data   []Balance `json:"data"`
+}
+
+func ListBalances(accountAlias string) []Balance {
+       data := []byte(`{"account_alias": "` + accountAlias + `"}`)
+       body := request(listBalancesURL, data)
+
+       balancesResp := new(BalancesResponse)
+       if err := json.Unmarshal(body, balancesResp); err != nil {
+               fmt.Println(err)
+       }
+       return balancesResp.Data
+}
+
+type PubkeyInfo struct {
+       Pubkey string   `json:"pubkey"`
+       Path   []string `json:"derivation_path"`
+}
+
+type KeyInfo struct {
+       XPubkey     string       `json:"root_xpub"`
+       PubkeyInfos []PubkeyInfo `json:"pubkey_infos"`
+}
+
+type PubkeysResponse struct {
+       Status string  `json:"status"`
+       Data   KeyInfo `json:"data"`
+}
+
+func ListPubkeys(accountAlias string) KeyInfo {
+       data := []byte(`{"account_alias": "` + accountAlias + `"}`)
+       body := request(listPubkeysURL, data)
+
+       pubkeysResp := new(PubkeysResponse)
+       if err := json.Unmarshal(body, pubkeysResp); err != nil {
+               fmt.Println(err)
+       }
+       return pubkeysResp.Data
+}
index 4f3028b..0cdfddb 100644 (file)
@@ -11,99 +11,6 @@ var (
        errFailedGetContractUTXOID = errors.New("Failed to get contract UTXO ID")
 )
 
-type Account struct {
-       AccountID    string `json:"id"`
-       AccountAlias string `json:"alias"`
-}
-
-type AccountsResponse struct {
-       Status string    `json:"status"`
-       Data   []Account `json:"data"`
-}
-
-func ListAccounts() []Account {
-       data := []byte(`{}`)
-       body := request(listAccountsURL, data)
-
-       accountsResp := new(AccountsResponse)
-       if err := json.Unmarshal(body, accountsResp); err != nil {
-               fmt.Println(err)
-       }
-       return accountsResp.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 AddressesResponse 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(AddressesResponse)
-       if err := json.Unmarshal(body, addresses); err != nil {
-               fmt.Println(err)
-       }
-       return addresses.Data
-}
-
-type Balance struct {
-       AccountID string `json:"account_id"`
-       Amount    uint64 `json:"amount"`
-}
-
-type BalancesResponse struct {
-       Status string    `json:"status"`
-       Data   []Balance `json:"data"`
-}
-
-func ListBalances(accountAlias string) []Balance {
-       data := []byte(`{"account_alias": "` + accountAlias + `"}`)
-       body := request(listBalancesURL, data)
-
-       balancesResp := new(BalancesResponse)
-       if err := json.Unmarshal(body, balancesResp); err != nil {
-               fmt.Println(err)
-       }
-       return balancesResp.Data
-}
-
-type PubkeyInfo struct {
-       Pubkey string   `json:"pubkey"`
-       Path   []string `json:"derivation_path"`
-}
-
-type KeyInfo struct {
-       XPubkey     string       `json:"root_xpub"`
-       PubkeyInfos []PubkeyInfo `json:"pubkey_infos"`
-}
-
-type PubkeysResponse struct {
-       Status string  `json:"status"`
-       Data   KeyInfo `json:"data"`
-}
-
-func ListPubkeys(accountAlias string) KeyInfo {
-       data := []byte(`{"account_alias": "` + accountAlias + `"}`)
-       body := request(listPubkeysURL, data)
-
-       pubkeysResp := new(PubkeysResponse)
-       if err := json.Unmarshal(body, pubkeysResp); err != nil {
-               fmt.Println(err)
-       }
-       return pubkeysResp.Data
-}
-
 type ContractInfo struct {
        Program string `json:"program"`
 }