-
Notifications
You must be signed in to change notification settings - Fork 9
Examples: Get Accounts info
Eleazar Garrido edited this page Oct 3, 2018
·
26 revisions
Returns AccountInfo for an account.
package main
import (
"encoding/json"
"fmt"
"github.com/proximax-storage/nem2-sdk-go/sdk"
"golang.org/x/net/context"
)
// Simple Account API request
func main() {
networkType := sdk.MijinTest
alicePublickey := "E17324EAF403B5FD747055ED3ED97CFD1000AF176FB9294C9424A2814D765A76"
aliceAddress, _ := sdk.NewAddressFromPublicKey(alicePublickey, networkType)
conf, err := sdk.LoadTestnetConfig("http://catapult.internal.proximax.io:3000")
if err != nil {
panic(err)
}
// Use the default http client
client := sdk.NewClient(nil, conf)
// Get AccountInfo for an account.
// Param address - A Address struct.
accountInfo, resp, err := client.Account.GetAccountInfo(context.Background(), aliceAddress)
if err != nil {
fmt.Printf("Account.GetAccountInfo returned error: %s", err)
return
}
accountInfoJson, _ := json.MarshalIndent(accountInfo, " ", "")
fmt.Printf("Response Status Code == %d\n", resp.StatusCode)
fmt.Printf("%s\n\n", string(accountInfoJson))
}
Returns AccountsInfo for different accounts.
package main
import (
"encoding/json"
"fmt"
"github.com/proximax-storage/nem2-sdk-go/sdk"
"golang.org/x/net/context"
)
// Simple Account API request
func main() {
networkType := sdk.MijinTest
alicePublicKey := "E17324EAF403B5FD747055ED3ED97CFD1000AF176FB9294C9424A2814D765A76"
carolPublicKey := "280F42F3898B79EB1E304D14F873186AC7D2401A787092D7BD1D2D34C6B182F9"
conf, err := sdk.LoadTestnetConfig("http://catapult.internal.proximax.io:3000")
if err != nil {
panic(err)
}
// Use the default http client
client := sdk.NewClient(nil, conf)
aliceAddress, _ := sdk.NewAddressFromPublicKey(alicePublicKey, networkType)
carolAddress, _ := sdk.NewAddressFromPublicKey(carolPublicKey, networkType)
var adds []*sdk.Address
// Append attachment into Address
adds = append(adds, aliceAddress)
// Append attachment into Address
adds = append(adds, carolAddress)
// Get AccountsInfo for different accounts.
// Param adds - slice of Address.
accountsInfo, resp, err := client.Account.GetAccountsInfo(context.Background(), adds)
if err != nil {
fmt.Printf("Account.GetAccountsInfo returned error: %s", err)
return
}
accountsInfoJson, _ := json.Marshal(accountsInfo)
fmt.Printf("Response Status Code == %d\n", resp.StatusCode)
fmt.Printf("%s\n\n", string(accountsInfoJson))
}
Gets an array of confirmed transaction for which an account is signer or recipient.
package main
import (
"encoding/json"
"fmt"
"github.com/proximax-storage/nem2-sdk-go/sdk"
"golang.org/x/net/context"
)
// Simple Account API request
func main() {
networkType := sdk.MijinTest
alicePrivateKey := "0F3CC33190A49ABB32E7172E348EA927F975F8829107AAA3D6349BB10797D4F6"
aliceAccount, _ := sdk.NewAccount(alicePrivateKey, networkType)
conf, err := sdk.LoadTestnetConfig("http://192.168.10.38:3000")
if err != nil {
panic(err)
}
// Use the default http client
client := sdk.NewClient(nil, conf)
opt := sdk.AccountTransactionsOption{
// The number of transactions to return. Should be between 10 and 100, otherwise 10.
PageSize: 10,
// Identifier of the transaction after which we want the transactions to be returned. Eje: "5B2B0F61415CD864572BDA46".
Id: "",
}
// Get confirmed transactions information.
// Param PublicAccount - A PublicAccount struct
// Param opt - A AccountTransactionsOption struct
transactions, resp, err := client.Account.Transactions(context.Background(), aliceAccount.PublicAccount, &opt )
if err != nil {
fmt.Printf("Account.Transactions returned error: %s", err)
return
}
transactionsJson, _ := json.Marshal(transactions)
fmt.Printf("Response Status Code == %d\n", resp.StatusCode)
fmt.Printf("%s\n\n", string(transactionsJson))
}
- Gets an array of transactions for which an account is the recipient.
A transaction is said to be incoming regarding an account if the account is the recipient of a transaction.
- Param PublicAccount - A PublicAccount struct
- Param opt - A AccountTransactionsOption struct
incomingTransactions, resp, err := client.Account.IncomingTransactions(context.Background(), aliceAccount.PublicAccount, &opt )
if err != nil {
fmt.Printf("Account.IncomingTransactions returned error: %s", err)
return
}
incomingTransactionsJson, _ := json.Marshal(incomingTransactions)
fmt.Printf("Response Status Code == %d\n", resp.StatusCode)
fmt.Printf("%s\n\n", string(incomingTransactionsJson))
- Gets an array of transactions for which an account is the sender.
A transaction is said to be outgoing egarding an account if the account is the sender of a transaction.
- Param PublicAccount - A PublicAccount struct
- Param opt - A AccountTransactionsOption struct
outgoingTransactions, resp, err := client.Account.OutgoingTransactions(context.Background(), aliceAccount.PublicAccount, &opt )
if err != nil {
fmt.Printf("Account.OutgoingTransactions returned error: %s", err)
return
}
outgoingTransactionsJson, _ := json.Marshal(outgoingTransactions)
fmt.Printf("Response Status Code == %d\n", resp.StatusCode)
fmt.Printf("%s\n\n", string(outgoingTransactionsJson))
- Gets the array of transactions for which an account is the sender or
receiver and which have not yet been included in a block.
- Param PublicAccount - A PublicAccount struct
- Param opt - A AccountTransactionsOption struct
unconfirmedTransactions, resp, err := client.Account.UnconfirmedTransactions(context.Background(), aliceAccount.PublicAccount, &opt )
if err != nil {
fmt.Printf("Account.unconfirmedTransactions returned error: %s", err)
return
}
unconfirmedTransactionsJson, _ := json.Marshal(unconfirmedTransactions)
fmt.Printf("Response Status Code == %d\n", resp.StatusCode)
fmt.Printf("%s\n\n", string(unconfirmedTransactionsJson))
- Param aliceAddress - Address struct.
getMultisigAccountInfo, resp, err := client.Account.GetMultisigAccountInfo(context.Background(), aliceAddress)
if err != nil {
fmt.Printf("Account.GetMultisigAccountInfo returned error: %s", err)
return
}
getMultisigAccountInfoJson, _ := json.Marshal(getMultisigAccountInfo)
fmt.Printf("Response Status Code == %d\n", resp.StatusCode)
fmt.Printf("%s\n\n", string(getMultisigAccountInfoJson))