account

package
v0.0.0-...-4fa4744 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotAllParametersSet   = errors.New("Not all neccessary parameters have been set")
	ErrTxnTypeUnSupported    = errors.New("Unsupported transction type")
	ErrTxnVersionUnSupported = errors.New("Unsupported transction version")
	ErrFeltToBigInt          = errors.New("Felt to BigInt error")
)
View Source
var (
	PREFIX_TRANSACTION      = new(felt.Felt).SetBytes([]byte("invoke"))
	PREFIX_DECLARE          = new(felt.Felt).SetBytes([]byte("declare"))
	PREFIX_CONTRACT_ADDRESS = new(felt.Felt).SetBytes([]byte("STARKNET_CONTRACT_ADDRESS"))
	PREFIX_DEPLOY_ACCOUNT   = new(felt.Felt).SetBytes([]byte("deploy_account"))
)
View Source
var ErrSenderNoExist = errors.New("sender does not exist")

Functions

func FmtCallDataCairo0

func FmtCallDataCairo0(callArray []rpc.FunctionCall) []*felt.Felt

FmtCallDataCairo0 generates a slice of *felt.Felt that represents the calldata for the given function calls in Cairo 0 format.

Parameters: - fnCalls: a slice of rpc.FunctionCall containing the function calls.

Returns: - a slice of *felt.Felt representing the generated calldata. https://github.com/project3fusion/StarkSharp/blob/main/StarkSharp/StarkSharp.Rpc/Modules/Transactions/Hash/TransactionHash.cs#L27

func FmtCallDataCairo2

func FmtCallDataCairo2(callArray []rpc.FunctionCall) []*felt.Felt

FmtCallDataCairo2 generates the calldata for the given function calls for Cairo 2 contracs.

Parameters: - fnCalls: a slice of rpc.FunctionCall containing the function calls. Returns: - a slice of *felt.Felt representing the generated calldata. https://github.com/project3fusion/StarkSharp/blob/main/StarkSharp/StarkSharp.Rpc/Modules/Transactions/Hash/TransactionHash.cs#L22

Types

type Account

type Account struct {
	ChainId        *felt.Felt
	AccountAddress *felt.Felt

	CairoVersion int
	// contains filtered or unexported fields
}

func NewAccount

func NewAccount(provider rpc.RpcProvider, accountAddress *felt.Felt, publicKey string, keystore Keystore, cairoVersion int) (*Account, error)

NewAccount creates a new Account instance.

Parameters: - provider: is the provider of type rpc.RpcProvider - accountAddress: is the account address of type *felt.Felt - publicKey: is the public key of type string - keystore: is the keystore of type Keystore It returns: - *Account: a pointer to newly created Account - error: an error if any

func NewAccountWithoutProvider

func NewAccountWithoutProvider(chainID string, accountAddress *felt.Felt, publicKey string, keystore Keystore,
	cairoVersion int) (*Account, error)

NewAccountWithoutProvider creates a new Account instance.

func (*Account) AddDeclareTransaction

func (account *Account) AddDeclareTransaction(ctx context.Context, declareTransaction rpc.BroadcastDeclareTxnType) (*rpc.AddDeclareTransactionResponse, error)

AddDeclareTransaction adds a declare transaction to the account.

Parameters: - ctx: The context.Context for the request. - declareTransaction: The input for adding a declare transaction. Returns: - *rpc.AddDeclareTransactionResponse: The response for adding a declare transaction - error: an error, if any

func (*Account) AddDeployAccountTransaction

func (account *Account) AddDeployAccountTransaction(ctx context.Context, deployAccountTransaction rpc.BroadcastAddDeployTxnType) (*rpc.AddDeployAccountTransactionResponse, error)

AddDeployAccountTransaction adds a deploy account transaction to the account.

Parameters: - ctx: The context.Context object for the function. - deployAccountTransaction: The rpc.DeployAccountTxn object representing the deploy account transaction. Returns: - *rpc.AddDeployAccountTransactionResponse: a pointer to rpc.AddDeployAccountTransactionResponse - error: an error if any

func (*Account) AddInvokeTransaction

func (account *Account) AddInvokeTransaction(ctx context.Context, invokeTx rpc.BroadcastInvokeTxnType) (*rpc.AddInvokeTransactionResponse, error)

AddInvokeTransaction generates an invoke transaction and adds it to the account's provider.

Parameters: - ctx: the context.Context object for the transaction. - invokeTx: the invoke transaction to be added. Returns: - *rpc.AddInvokeTransactionResponse: The response for the AddInvokeTransactionResponse - error: an error if any.

func (*Account) BlockHashAndNumber

func (account *Account) BlockHashAndNumber(ctx context.Context) (*rpc.BlockHashAndNumberOutput, error)

BlockHashAndNumber returns the block hash and number for the account.

Parameters: - ctx: The context in which the function is called. Returns: - rpc.BlockHashAndNumberOutput: the block hash and number as an rpc.BlockHashAndNumberOutput object. - error: an error if there was an issue retrieving the block hash and number.

func (*Account) BlockNumber

func (account *Account) BlockNumber(ctx context.Context) (uint64, error)

BlockNumber returns the block number of the account.

Parameters: - ctx: The context in which the function is called. Returns: - uint64: the block number as a uint64 - error: an error encountered

func (*Account) BlockTransactionCount

func (account *Account) BlockTransactionCount(ctx context.Context, blockID rpc.BlockID) (uint64, error)

BlockTransactionCount returns the number of transactions in a block.

Parameters: - ctx: The context.Context object for the function. - blockID: The rpc.BlockID object representing the block. Returns: - uint64: the number of transactions in the block

  • error: an error, if any

func (*Account) BlockWithReceipts

func (account *Account) BlockWithReceipts(ctx context.Context, blockID rpc.BlockID) (interface{}, error)

func (*Account) BlockWithTxHashes

func (account *Account) BlockWithTxHashes(ctx context.Context, blockID rpc.BlockID) (interface{}, error)

BlockWithTxHashes retrieves a block with transaction hashes.

Parameters: - ctx: the context.Context object for the request. - blockID: the rpc.BlockID object specifying the block to retrieve. Returns: - interface{}: an interface{} representing the retrieved block - error: an error if there was any issue retrieving the block

func (*Account) BlockWithTxs

func (account *Account) BlockWithTxs(ctx context.Context, blockID rpc.BlockID) (interface{}, error)

BlockWithTxs retrieves the specified block along with its transactions.

Parameters: - ctx: The context.Context object for the function. - blockID: The rpc.BlockID parameter for the function. Returns: - interface{}: An interface{} - error: An error

func (*Account) Call

func (account *Account) Call(ctx context.Context, call rpc.FunctionCall, blockId rpc.BlockID) ([]*felt.Felt, error)

Call is a function that performs a function call on an Account.

Parameters: - ctx: The context.Context object for the function. - call: The rpc.FunctionCall object representing the function call. - blockID: The rpc.BlockID object representing the block ID. Returns: - []*felt.Felt: a slice of *felt.Felt - error: an error object.

func (*Account) ChainID

func (account *Account) ChainID(ctx context.Context) (string, error)

ChainID returns the chain ID associated with the account.

Parameters: - ctx: the context.Context object for the function. Returns:

  • string: the chain ID.
  • error: any error encountered while retrieving the chain ID.

func (*Account) Class

func (account *Account) Class(ctx context.Context, blockID rpc.BlockID, classHash *felt.Felt) (rpc.ClassOutput, error)

Class is a method that calls the `Class` method of the `provider` field of the `account` struct.

Parameters: - ctx: The context.Context - blockID: The rpc.BlockID - classHash: The `*felt.Felt` Returns:

  • *rpc.ClassOutput: The rpc.ClassOutput (the class output could be a DeprecatedContractClass or just a Contract class depending on the contract version)
  • error: An error if any occurred.

func (*Account) ClassAt

func (account *Account) ClassAt(ctx context.Context, blockID rpc.BlockID, contractAddress *felt.Felt) (rpc.ClassOutput, error)

ClassAt retrieves the class at the specified block ID and contract address. Parameters: - ctx: The context.Context object for the function. - blockID: The rpc.BlockID object representing the block ID. - contractAddress: The felt.Felt object representing the contract address. Returns:

  • *rpc.ClassOutput: The rpc.ClassOutput object (the class output could be a DeprecatedContractClass or just a Contract class depending on the contract version)
  • error: An error if any occurred.

func (*Account) ClassHashAt

func (account *Account) ClassHashAt(ctx context.Context, blockID rpc.BlockID, contractAddress *felt.Felt) (*felt.Felt, error)

ClassHashAt returns the class hash at the given block ID for the specified contract address.

Parameters: - ctx: The context to use for the function call. - blockID: The ID of the block. contractAddress - The address of the contract to get the class hash for. Returns: - *felt.Felt: the class hash as a *felt.Felt - error: an error if any occurred.

func (*Account) EstimateFee

func (account *Account) EstimateFee(ctx context.Context, requests []rpc.BroadcastTxn, simulationFlags []rpc.SimulationFlag, blockID rpc.BlockID) ([]rpc.FeeEstimate, error)

EstimateFee estimates the fee for a set of requests in the given block ID.

Parameters: - ctx: The context.Context object for the function. - requests: An array of rpc.BroadcastTxn objects representing the requests to estimate the fee for. - blockID: The rpc.BlockID object representing the block ID for which to estimate the fee. Returns: - []rpc.FeeEstimate: An array of rpc.FeeEstimate objects representing the estimated fees. - error: An error object if any error occurred during the estimation process.

func (*Account) EstimateMessageFee

func (account *Account) EstimateMessageFee(ctx context.Context, msg rpc.MsgFromL1, blockID rpc.BlockID) (*rpc.FeeEstimate, error)

EstimateMessageFee estimates the fee for a given message in the context of an account.

Parameters: - ctx: The context.Context object for the function. - msg: The rpc.MsgFromL1 object representing the message. - blockID: The rpc.BlockID object representing the block ID. Returns: - *rpc.FeeEstimate: a pointer to rpc.FeeEstimate - error: an error if any.

func (*Account) Events

func (account *Account) Events(ctx context.Context, input rpc.EventsInput) (*rpc.EventChunk, error)

Events retrieves events for the account.

Parameters: - ctx: the context.Context to use for the request. - input: the input parameters for retrieving events. Returns: - *rpc.EventChunk: the chunk of events retrieved. - error: an error if the retrieval fails.

func (*Account) FmtCalldata

func (account *Account) FmtCalldata(fnCalls []rpc.FunctionCall) ([]*felt.Felt, error)

FmtCalldata generates the formatted calldata for the given function calls and Cairo version.

Parameters: - fnCalls: a slice of rpc.FunctionCall representing the function calls. - cairoVersion: an integer representing the Cairo version. Returns: - a slice of *felt.Felt representing the formatted calldata. - an error if Cairo version is not supported.

func (*Account) GetTransactionStatus

func (account *Account) GetTransactionStatus(ctx context.Context, Txnhash *felt.Felt) (*rpc.TxnStatusResp, error)

GetTransactionStatus returns the transaction status.

Parameters: - ctx: The context.Context - Txnhash: The *felt.Felt Txn hash. Returns: - *rpc.TxnStatusResp: the transaction status - error: anerror if any

func (*Account) Nonce

func (account *Account) Nonce(ctx context.Context, blockID rpc.BlockID, contractAddress *felt.Felt) (*felt.Felt, error)

Nonce retrieves the nonce for a given block ID and contract address.

Parameters: - ctx: is the context.Context for the function call - blockID: is the ID of the block - contractAddress: is the address of the contract Returns: - *felt.Felt: the contract's nonce at the requested state - error: an error if any

func (*Account) PrecomputeAddress

func (account *Account) PrecomputeAddress(deployerAddress *felt.Felt, salt *felt.Felt, classHash *felt.Felt, constructorCalldata []*felt.Felt) (*felt.Felt, error)

PrecomputeAddress calculates the precomputed address for an account. ref: https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/core/os/contract_address/contract_address.py

Parameters: - deployerAddress: the deployer address - salt: the salt - classHash: the class hash - constructorCalldata: the constructor calldata Returns: - *felt.Felt: the precomputed address as a *felt.Felt - error: an error if any

func (*Account) Sign

func (account *Account) Sign(ctx context.Context, msg *felt.Felt) ([]*felt.Felt, error)

Sign signs the given felt message using the account's private key.

Parameters: - ctx: is the context used for the signing operation - msg: is the felt message to be signed Returns: - []*felt.Felt: an array of signed felt messages - error: an error, if any

func (*Account) SignDeclareTransaction

func (account *Account) SignDeclareTransaction(ctx context.Context, tx *rpc.DeclareTxnV2) error

SignDeclareTransaction signs a DeclareTxnV2 transaction using the provided Account.

Parameters: - ctx: the context.Context - tx: the *rpc.DeclareTxnV2 Returns: - error: an error if any

func (*Account) SignDeployAccountTransaction

func (account *Account) SignDeployAccountTransaction(ctx context.Context, tx *rpc.DeployAccountTxn, precomputeAddress *felt.Felt) error

SignDeployAccountTransaction signs a deploy account transaction.

Parameters: - ctx: the context.Context for the function execution - tx: the *rpc.DeployAccountTxn struct representing the transaction to be signed - precomputeAddress: the precomputed address for the transaction Returns: - error: an error if any

func (*Account) SignInvokeTransaction

func (account *Account) SignInvokeTransaction(ctx context.Context, invokeTx *rpc.InvokeTxnV1) error

SignInvokeTransaction signs and invokes a transaction.

Parameters: - ctx: the context.Context for the function execution. - invokeTx: the InvokeTxnV1 struct representing the transaction to be invoked. Returns: - error: an error if there was an error in the signing or invoking process

func (*Account) SimulateTransactions

func (account *Account) SimulateTransactions(ctx context.Context, blockID rpc.BlockID, txns []rpc.Transaction, simulationFlags []rpc.SimulationFlag) ([]rpc.SimulatedTransaction, error)

SimulateTransactions simulates transactions using the provided context Parameters: - ctx: The context.Context object - blockID: The rpc.BlockID object for the block referencing the state or call the transactions are on - txns: The slice of rpc.Transaction objects representing the transactions to simulate - simulationFlags: The slice of rpc.simulationFlags Returns: - []rpc.SimulatedTransaction: a list of simulated transactions - error: an error, if any.

func (*Account) SpecVersion

func (account *Account) SpecVersion(ctx context.Context) (string, error)

SpecVersion returns the spec version of the account. It takes a context as a parameter and returns a string and an error

Parameters: - context.Context: The context.Context object Returns: - string: The spec version - error: An error if any

func (*Account) StateUpdate

func (account *Account) StateUpdate(ctx context.Context, blockID rpc.BlockID) (*rpc.StateUpdateOutput, error)

StateUpdate updates the state of the Account.

Parameters: - context.Context: The context.Context object. - blockID: The rpc.BlockID object representing the block to update the state of. Returns: - *rpc.StateUpdateOutput: a *rpc.StateUpdateOutput - error: an error

func (*Account) StorageAt

func (account *Account) StorageAt(ctx context.Context, contractAddress *felt.Felt, key string, blockID rpc.BlockID) (string, error)

StorageAt is a function that retrieves the storage value at the given key for a contract address.

Parameters: - ctx: The context.Context object for the function - contractAddress: The contract address for which to retrieve the storage value - key: The key of the storage value to retrieve - blockID: The block ID at which to retrieve the storage value Returns: - string: The storage value at the given key. - error: An error if the retrieval fails.

func (*Account) Syncing

func (account *Account) Syncing(ctx context.Context) (*rpc.SyncStatus, error)

Syncing returns the sync status of the account.

Parameters: - ctx: The context.Context object Returns: - *rpc.SyncStatus: *rpc.SyncStatus - error: an error.

func (*Account) TraceBlockTransactions

func (account *Account) TraceBlockTransactions(ctx context.Context, blockID rpc.BlockID) ([]rpc.Trace, error)

TraceBlockTransactions retrieves a list of trace transactions for a given block hash.

Parameters: - ctx: The context.Context object. - blockID: The hash of the block to retrieve trace transactions for. Returns - []rpc.Trace: The list of trace transactions for the given block. - error: An error if there was a problem retrieving the trace transactions.

func (*Account) TraceTransaction

func (account *Account) TraceTransaction(ctx context.Context, transactionHash *felt.Felt) (rpc.TxnTrace, error)

TransactionTrace returns the transaction trace for a given transaction hash.

Parameters: - ctx: The context.Context object for the request. - transactionHash: The transaction hash for which the transaction trace is to be retrieved. Returns: - rpc.TxnTrace: The rpc.TxnTrace object representing the transaction trace, and an error if any.

func (*Account) TransactionByBlockIdAndIndex

func (account *Account) TransactionByBlockIdAndIndex(ctx context.Context, blockID rpc.BlockID, index uint64) (rpc.Transaction, error)

TransactionByBlockIdAndIndex returns a transaction by block ID and index.

Parameters: - ctx: The context for the function. - blockID: The ID of the block. - index: The index of the transaction in the block. Returns: - rpc.Transaction: The transaction and an error, if any.

func (*Account) TransactionByHash

func (account *Account) TransactionByHash(ctx context.Context, hash *felt.Felt) (rpc.Transaction, error)

TransactionByHash returns the transaction with the given hash.

Parameters: - ctx: The context.Context - hash: The *felt.Felt hash as parameters. Returns: - rpc.Transaction - error

func (*Account) TransactionHashDeclare

func (account *Account) TransactionHashDeclare(tx rpc.DeclareTxnType) (*felt.Felt, error)

TransactionHashDeclare calculates the transaction hash for declaring a transaction type.

Parameters: - tx: The `tx` parameter of type `rpc.DeclareTxnType` Can be one of the following types:

  • `rpc.DeclareTxnV0`
  • `rpc.DeclareTxnV1`
  • `rpc.DeclareTxnV2`

Returns: - *felt.Felt: the calculated transaction hash as `*felt.Felt` value - error: an error, if any

If the `tx` parameter is not one of the supported types, the function returns an error `ErrTxnTypeUnSupported`.

func (*Account) TransactionHashDeployAccount

func (account *Account) TransactionHashDeployAccount(tx rpc.DeployAccountType, contractAddress *felt.Felt) (*felt.Felt, error)

TransactionHashDeployAccount calculates the transaction hash for a deploy account transaction.

Parameters: - tx: The deploy account transaction to calculate the hash for - contractAddress: The contract address as parameters as a *felt.Felt Returns: - *felt.Felt: the calculated transaction hash - error: an error if any

func (*Account) TransactionHashInvoke

func (account *Account) TransactionHashInvoke(tx rpc.InvokeTxnType) (*felt.Felt, error)

If the transaction type is unsupported, the function returns an error.

func (*Account) TransactionReceipt

func (account *Account) TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (*rpc.TransactionReceiptWithBlockInfo, error)

TransactionReceipt retrieves the transaction receipt for the given transaction hash.

Parameters: - ctx: The context to use for the request. - transactionHash: The hash of the transaction. Returns: - rpc.Transactiontype: rpc.TransactionReceipt, error.

func (*Account) WaitForTransactionReceipt

func (account *Account) WaitForTransactionReceipt(ctx context.Context, transactionHash *felt.Felt, pollInterval time.Duration) (*rpc.TransactionReceiptWithBlockInfo, error)

WaitForTransactionReceipt waits for the transaction receipt of the given transaction hash to succeed or fail.

Parameters: - ctx: The context - transactionHash: The hash - pollInterval: The poll interval as parameters It returns: - *rpc.TransactionReceipt: the transaction receipt - error: an error

type AccountInterface

type AccountInterface interface {
	Sign(ctx context.Context, msg *felt.Felt) ([]*felt.Felt, error)
	TransactionHashInvoke(invokeTxn rpc.InvokeTxnType) (*felt.Felt, error)
	TransactionHashDeployAccount(tx rpc.DeployAccountType, contractAddress *felt.Felt) (*felt.Felt, error)
	TransactionHashDeclare(tx rpc.DeclareTxnType) (*felt.Felt, error)
	SignInvokeTransaction(ctx context.Context, tx *rpc.InvokeTxnV1) error
	SignDeployAccountTransaction(ctx context.Context, tx *rpc.DeployAccountTxn, precomputeAddress *felt.Felt) error
	SignDeclareTransaction(ctx context.Context, tx *rpc.DeclareTxnV2) error
	PrecomputeAddress(deployerAddress *felt.Felt, salt *felt.Felt, classHash *felt.Felt, constructorCalldata []*felt.Felt) (*felt.Felt, error)
	WaitForTransactionReceipt(ctx context.Context, transactionHash *felt.Felt, pollInterval time.Duration) (*rpc.TransactionReceiptWithBlockInfo, error)
}

type Keystore

type Keystore interface {
	Sign(ctx context.Context, id string, msgHash *big.Int) (x *big.Int, y *big.Int, err error)
}

type MemKeystore

type MemKeystore struct {
	// contains filtered or unexported fields
}

MemKeystore implements the Keystore interface and is intended for example and test code.

func GetRandomKeys

func GetRandomKeys() (*MemKeystore, *felt.Felt, *felt.Felt)

GetRandomKeys gets a random set of pub-priv keys. Note: This should be used for testing purposes only, do NOT send real funds to these addresses. Parameters:

none

Returns: - *MemKeystore: a pointer to a MemKeystore instance - *felt.Felt: a pointer to a public key as a felt.Felt - *felt.Felt: a pointer to a private key as a felt.Felt

func NewMemKeystore

func NewMemKeystore() *MemKeystore

NewMemKeystore initializes and returns a new instance of MemKeystore.

Parameters:

none

Returns: - *MemKeystore: a pointer to MemKeystore.

func SetNewMemKeystore

func SetNewMemKeystore(pub string, priv *big.Int) *MemKeystore

SetNewMemKeystore returns a new instance of MemKeystore and sets the given public key and private key in it.

Parameters: - pub: a string representing the public key - priv: a pointer to a big.Int representing the private key Returns: - *MemKeystore: a pointer to the newly created MemKeystore instance

func (*MemKeystore) Get

func (ks *MemKeystore) Get(senderAddress string) (*big.Int, error)

Get retrieves the value associated with the senderAddress from the MemKeystore.

Parameter: - senderAddress: The address of the sender Returns: - *big.Int: The value associated with the senderAddress - error: An error if the senderAddress does not exist in the keystore

func (*MemKeystore) Put

func (ks *MemKeystore) Put(senderAddress string, k *big.Int)

Put stores the given key in the keystore for the specified sender address.

Parameters: - senderAddress: the address of the sender - k: the key to be stored

func (*MemKeystore) Sign

func (ks *MemKeystore) Sign(ctx context.Context, id string, msgHash *big.Int) (*big.Int, *big.Int, error)

Sign signs a message hash using the given key in the MemKeystore.

Parameters: - ctx: the context of the operation. - id: is the identifier of the key. - msgHash: is the message hash to be signed. Returns: - *big.Int: the R component of the signature as *big.Int - *big.Int: the S component of the signature as *big.Int - error: an error if any

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL