Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor packages #79

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions account.go

This file was deleted.

5 changes: 3 additions & 2 deletions api/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package api

import (
"encoding/json"
"github.com/aptos-labs/aptos-go-sdk/internal/types"
"github.com/stretchr/testify/assert"
"testing"

"github.com/aptos-labs/aptos-go-sdk/types"
"github.com/stretchr/testify/assert"
)

func TestEvent_V1(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion api/module.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package api

import (
"github.com/aptos-labs/aptos-go-sdk/internal/types"
"github.com/aptos-labs/aptos-go-sdk/types"
)

// MoveBytecode describes a module, or script, and it's associated ABI as a [MoveModule]
Expand Down
2 changes: 1 addition & 1 deletion api/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/aptos-labs/aptos-go-sdk/internal/util"
"github.com/aptos-labs/aptos-go-sdk/util"
"github.com/stretchr/testify/assert"
)

Expand Down
3 changes: 2 additions & 1 deletion api/payloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package api

import (
"encoding/json"
"github.com/aptos-labs/aptos-go-sdk/internal/types"

"github.com/aptos-labs/aptos-go-sdk/types"
)

// TransactionPayloadVariant is the type of payload represented in JSON
Expand Down
3 changes: 2 additions & 1 deletion api/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package api

import (
"encoding/json"

"github.com/aptos-labs/aptos-go-sdk/crypto"
"github.com/aptos-labs/aptos-go-sdk/internal/types"
"github.com/aptos-labs/aptos-go-sdk/types"
)

// SignatureVariant is the JSON representation of the signature types
Expand Down
5 changes: 3 additions & 2 deletions api/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package api
import (
"encoding/json"
"fmt"
"github.com/aptos-labs/aptos-go-sdk/internal/types"
"github.com/aptos-labs/aptos-go-sdk/internal/util"

"github.com/aptos-labs/aptos-go-sdk/types"
"github.com/aptos-labs/aptos-go-sdk/util"
)

// TransactionVariant is the type of transaction, all transactions submitted by this SDK are [TransactionVariantUser]
Expand Down
5 changes: 3 additions & 2 deletions api/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package api

import (
"encoding/json"
"github.com/aptos-labs/aptos-go-sdk/internal/types"
"github.com/stretchr/testify/assert"
"testing"

"github.com/aptos-labs/aptos-go-sdk/types"
"github.com/stretchr/testify/assert"
)

func TestTransaction_GenesisTransaction(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions api/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package api

import (
"encoding/json"
"github.com/aptos-labs/aptos-go-sdk/internal/types"
"github.com/aptos-labs/aptos-go-sdk/internal/util"

"github.com/aptos-labs/aptos-go-sdk/types"
"github.com/aptos-labs/aptos-go-sdk/util"
)

// GUID describes a GUID associated with things like V1 events
Expand Down
3 changes: 2 additions & 1 deletion api/writeSet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package api

import (
"encoding/json"
"github.com/aptos-labs/aptos-go-sdk/internal/types"

"github.com/aptos-labs/aptos-go-sdk/types"
)

// WriteSetVariant is the type of [WriteSet]
Expand Down
5 changes: 3 additions & 2 deletions api/writeSet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package api

import (
"encoding/json"
"github.com/aptos-labs/aptos-go-sdk/internal/types"
"github.com/stretchr/testify/assert"
"testing"

"github.com/aptos-labs/aptos-go-sdk/types"
"github.com/stretchr/testify/assert"
)

func TestWriteSet_WriteModule(t *testing.T) {
Expand Down
87 changes: 44 additions & 43 deletions client.go → client/client.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package aptos
package client

import (
"time"

"github.com/aptos-labs/aptos-go-sdk/api"
"github.com/aptos-labs/aptos-go-sdk/types"
"github.com/hasura/go-graphql-client"
)

Expand Down Expand Up @@ -148,39 +149,39 @@ func (client *Client) Info() (info NodeInfo, err error) {
}

// Account Retrieves information about the account such as [SequenceNumber] and [crypto.AuthenticationKey]
func (client *Client) Account(address AccountAddress, ledgerVersion ...uint64) (info AccountInfo, err error) {
func (client *Client) Account(address types.AccountAddress, ledgerVersion ...uint64) (info types.AccountInfo, err error) {
return client.nodeClient.Account(address, ledgerVersion...)
}

// AccountResource Retrieves a single resource given its struct name.
//
// address := AccountOne
// address := types.AccountOne
// dataMap, _ := client.AccountResource(address, "0x1::coin::CoinStore")
//
// Can also fetch at a specific ledger version
//
// address := AccountOne
// address := types.AccountOne
// dataMap, _ := client.AccountResource(address, "0x1::coin::CoinStore", 1)
func (client *Client) AccountResource(address AccountAddress, resourceType string, ledgerVersion ...uint64) (data map[string]any, err error) {
func (client *Client) AccountResource(address types.AccountAddress, resourceType string, ledgerVersion ...uint64) (data map[string]any, err error) {
return client.nodeClient.AccountResource(address, resourceType, ledgerVersion...)
}

// AccountResources fetches resources for an account into a JSON-like map[string]any in AccountResourceInfo.Data
// AccountResources fetches resources for an account into a JSON-like map[string]any in types.AccountResourceInfo.Data
// For fetching raw Move structs as BCS, See #AccountResourcesBCS
//
// address := AccountOne
// address := types.AccountOne
// dataMap, _ := client.AccountResources(address)
//
// Can also fetch at a specific ledger version
//
// address := AccountOne
// address := types.AccountOne
// dataMap, _ := client.AccountResource(address, 1)
func (client *Client) AccountResources(address AccountAddress, ledgerVersion ...uint64) (resources []AccountResourceInfo, err error) {
func (client *Client) AccountResources(address types.AccountAddress, ledgerVersion ...uint64) (resources []types.AccountResourceInfo, err error) {
return client.nodeClient.AccountResources(address, ledgerVersion...)
}

// AccountResourcesBCS fetches account resources as raw Move struct BCS blobs in AccountResourceRecord.Data []byte
func (client *Client) AccountResourcesBCS(address AccountAddress, ledgerVersion ...uint64) (resources []AccountResourceRecord, err error) {
// AccountResourcesBCS fetches account resources as raw Move struct BCS blobs in types.AccountResourceRecord.Data []byte
func (client *Client) AccountResourcesBCS(address types.AccountAddress, ledgerVersion ...uint64) (resources []types.AccountResourceRecord, err error) {
return client.nodeClient.AccountResourcesBCS(address, ledgerVersion...)
}

Expand Down Expand Up @@ -270,20 +271,20 @@ func (client *Client) Transactions(start *uint64, limit *uint64) (data []*api.Co
}

// SubmitTransaction Submits an already signed transaction to the blockchain
func (client *Client) SubmitTransaction(signedTransaction *SignedTransaction) (data *api.SubmitTransactionResponse, err error) {
func (client *Client) SubmitTransaction(signedTransaction *types.SignedTransaction) (data *api.SubmitTransactionResponse, err error) {
return client.nodeClient.SubmitTransaction(signedTransaction)
}

// BatchSubmitTransaction submits a collection of signed transactions to the network in a single request
//
// It will return the responses in the same order as the input transactions that failed. If the response is empty, then
// all transactions succeeded.
func (client *Client) BatchSubmitTransaction(signedTxns []*SignedTransaction) (response *api.BatchSubmitTransactionResponse, err error) {
func (client *Client) BatchSubmitTransaction(signedTxns []*types.SignedTransaction) (response *api.BatchSubmitTransactionResponse, err error) {
return client.nodeClient.BatchSubmitTransaction(signedTxns)
}

// SimulateTransaction Simulates a raw transaction without sending it to the blockchain
func (client *Client) SimulateTransaction(rawTxn *RawTransaction, sender TransactionSigner, options ...any) (data []*api.UserTransaction, err error) {
func (client *Client) SimulateTransaction(rawTxn *types.RawTransaction, sender types.TransactionSigner, options ...any) (data []*api.UserTransaction, err error) {
return client.nodeClient.SimulateTransaction(rawTxn, sender, options...)
}

Expand All @@ -294,87 +295,87 @@ func (client *Client) GetChainId() (chainId uint8, err error) {
}

// Fund Uses the faucet to fund an address, only applies to non-production networks
func (client *Client) Fund(address AccountAddress, amount uint64) error {
func (client *Client) Fund(address types.AccountAddress, amount uint64) error {
return client.faucetClient.Fund(address, amount)
}

// BuildTransaction Builds a raw transaction from the payload and fetches any necessary information from on-chain
//
// sender := NewEd25519Account()
// txnPayload := TransactionPayload{
// Payload: &EntryFunction{
// Module: ModuleId{
// Address: AccountOne,
// sender := types.NewEd25519Account()
// txnPayload := types.TransactionPayload{
// Payload: &types.EntryFunction{
// Module: types.ModuleId{
// Address: types.AccountOne,
// Name: "aptos_account",
// },
// Function: "transfer",
// ArgTypes: []TypeTag{},
// ArgTypes: []types.TypeTag{},
// Args: [][]byte{
// dest[:],
// amountBytes,
// },
// }
// }
// rawTxn, err := client.BuildTransaction(sender.AccountAddress(), txnPayload)
func (client *Client) BuildTransaction(sender AccountAddress, payload TransactionPayload, options ...any) (rawTxn *RawTransaction, err error) {
func (client *Client) BuildTransaction(sender types.AccountAddress, payload types.TransactionPayload, options ...any) (rawTxn *types.RawTransaction, err error) {
return client.nodeClient.BuildTransaction(sender, payload, options...)
}

// BuildTransactionMultiAgent Builds a raw transaction for MultiAgent or FeePayer from the payload and fetches any necessary information from on-chain
//
// sender := NewEd25519Account()
// txnPayload := TransactionPayload{
// Payload: &EntryFunction{
// Module: ModuleId{
// Address: AccountOne,
// sender := types.NewEd25519Account()
// txnPayload := types.TransactionPayload{
// Payload: &types.EntryFunction{
// Module: types.ModuleId{
// Address: types.AccountOne,
// Name: "aptos_account",
// },
// Function: "transfer",
// ArgTypes: []TypeTag{},
// ArgTypes: []types.TypeTag{},
// Args: [][]byte{
// dest[:],
// amountBytes,
// },
// }
// }
// rawTxn, err := client.BuildTransactionMultiAgent(sender.AccountAddress(), txnPayload, FeePayer(AccountZero))
func (client *Client) BuildTransactionMultiAgent(sender AccountAddress, payload TransactionPayload, options ...any) (rawTxn *RawTransactionWithData, err error) {
func (client *Client) BuildTransactionMultiAgent(sender types.AccountAddress, payload types.TransactionPayload, options ...any) (rawTxn *types.RawTransactionWithData, err error) {
return client.nodeClient.BuildTransactionMultiAgent(sender, payload, options...)
}

// BuildSignAndSubmitTransaction Convenience function to do all three in one
// for more configuration, please use them separately
//
// sender := NewEd25519Account()
// txnPayload := TransactionPayload{
// Payload: &EntryFunction{
// Module: ModuleId{
// Address: AccountOne,
// sender := types.NewEd25519Account()
// txnPayload := types.TransactionPayload{
// Payload: &types.EntryFunction{
// Module: types.ModuleId{
// Address: types.AccountOne,
// Name: "aptos_account",
// },
// Function: "transfer",
// ArgTypes: []TypeTag{},
// ArgTypes: []types.TypeTag{},
// Args: [][]byte{
// dest[:],
// amountBytes,
// },
// }
// }
// submitResponse, err := client.BuildSignAndSubmitTransaction(sender, txnPayload)
func (client *Client) BuildSignAndSubmitTransaction(sender *Account, payload TransactionPayload, options ...any) (data *api.SubmitTransactionResponse, err error) {
func (client *Client) BuildSignAndSubmitTransaction(sender *types.Account, payload types.TransactionPayload, options ...any) (data *api.SubmitTransactionResponse, err error) {
return client.nodeClient.BuildSignAndSubmitTransaction(sender, payload, options...)
}

// View Runs a view function on chain returning a list of return values.
//
// address := AccountOne
// address := types.AccountOne
// payload := &ViewPayload{
// Module: ModuleId{
// Address: AccountOne,
// Module: types.ModuleId{
// Address: types.AccountOne,
// Name: "coin",
// },
// Function: "balance",
// ArgTypes: []TypeTag{AptosCoinTypeTag},
// ArgTypes: []types.TypeTag{types.AptosCoinTypeTag},
// Args: [][]byte{address[:]},
// }
// vals, err := client.aptosClient.View(payload)
Expand All @@ -384,12 +385,12 @@ func (client *Client) View(payload *ViewPayload, ledgerVersion ...uint64) (vals
}

// EstimateGasPrice Retrieves the gas estimate from the network.
func (client *Client) EstimateGasPrice() (info EstimateGasInfo, err error) {
func (client *Client) EstimateGasPrice() (info types.EstimateGasInfo, err error) {
return client.nodeClient.EstimateGasPrice()
}

// AccountAPTBalance retrieves the APT balance in the account
func (client *Client) AccountAPTBalance(address AccountAddress) (uint64, error) {
func (client *Client) AccountAPTBalance(address types.AccountAddress) (uint64, error) {
return client.nodeClient.AccountAPTBalance(address)
}

Expand Down Expand Up @@ -429,7 +430,7 @@ func (client *Client) GetProcessorStatus(processorName string) (uint64, error) {
}

// GetCoinBalances gets the balances of all coins associated with a given address
func (client *Client) GetCoinBalances(address AccountAddress) ([]CoinBalance, error) {
func (client *Client) GetCoinBalances(address types.AccountAddress) ([]CoinBalance, error) {
return client.indexerClient.GetCoinBalances(address)
}

Expand Down
Loading