-
Notifications
You must be signed in to change notification settings - Fork 9
Examples: Get Accounts info
Eleazar Garrido edited this page Oct 2, 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
alicePrivateKey := "814DA2775296E71D461CACA6CB8BF3D0485C522AAAD99C1681A9AE12C402188E"
aliceAddress, _ := sdk.NewAddressFromPublicKey(alicePrivateKey, 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.Marshal(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
alicePrivateKey := "814DA2775296E71D461CACA6CB8BF3D0485C522AAAD99C1681A9AE12C402188E"
carolPrivateKey := "04dd376196603c44a19fd500492e5de12de9ed353de070a788cb21f210645613"
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(alicePrivateKey, networkType)
carolAddress, _ := sdk.NewAddressFromPublicKey(carolPrivateKey, 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.IncomingTransactions 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))