types

package
v0.0.0-...-00a565c Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 19 Imported by: 2

Documentation

Index

Constants

View Source
const (
	FIELD_GEN   int    = 3
	FIELD_PRIME string = "3618502788666131213697322783095070105623107215331596699973092056135872020481"
)
View Source
const HashLength = 32

HashLength is the expected length of the hash

Variables

View Source
var (
	MaxFelt = StrToFelt(FIELD_PRIME)
)

Functions

func BigToHex

func BigToHex(in *big.Int) string

convert big int to hexidecimal string

func BytesToBig

func BytesToBig(bytes []byte) *big.Int

func ComputeFact

func ComputeFact(programHash *big.Int, programOutputs []*big.Int) *big.Int

compute the keccack fact given the program hash and outputs

func FmtKecBytes

func FmtKecBytes(in *big.Int, rolen int) (buf []byte)

format the bytes in Keccak hash

func GetSelectorFromName

func GetSelectorFromName(funcName string) *big.Int

func HexToBN

func HexToBN(hexString string) *big.Int

trim "0x" prefix(if exists) and converts hexidecimal string to big int

func HexToBytes

func HexToBytes(hexString string) ([]byte, error)

trim "0x" prefix(if exists) and converts hexidecimal string to byte slice

func HexToShortStr

func HexToShortStr(hexStr string) string

convert hex string to StarkNet 'short string'

func Keccak256

func Keccak256(data ...[]byte) []byte

Keccak256 calculates and returns the Keccak256 hash of the input data. (ref: https://github.com/ethereum/go-ethereum/blob/master/crypto/crypto.go)

func MaskBits

func MaskBits(mask, wordSize int, slice []byte) (ret []byte)

mask excess bits

func SNValToBN

func SNValToBN(str string) *big.Int

used in string conversions when interfacing with the APIs

func SplitFactStr

func SplitFactStr(fact string) (fact_low, fact_high string)

split a fact into two felts

func StrToBig

func StrToBig(str string) *big.Int

convert decimal string to big int

func UTF8StrToBig

func UTF8StrToBig(str string) *big.Int

convert utf8 string to big int

Types

type ABI

type ABI []ABIEntry

type ABIEntry

type ABIEntry interface {
	IsType() ABIType
}

type ABIType

type ABIType string
const (
	ABITypeConstructor ABIType = "constructor"
	ABITypeFunction    ABIType = "function"
	ABITypeL1Handler   ABIType = "l1_handler"
	ABITypeEvent       ABIType = "event"
	ABITypeStruct      ABIType = "struct"
)

type AddDeclareResponse

type AddDeclareResponse struct {
	Code            string `json:"code"`
	TransactionHash string `json:"transaction_hash"`
	ClassHash       string `json:"class_hash"`
}

type AddDeployResponse

type AddDeployResponse struct {
	Code            string `json:"code"`
	TransactionHash string `json:"transaction_hash"`
	ContractAddress string `json:"address"`
}

type AddInvokeTransactionOutput

type AddInvokeTransactionOutput struct {
	TransactionHash string `json:"transaction_hash"`
}

type ContractClass

type ContractClass struct {
	// Program A base64 representation of the compressed program code
	Program string `json:"program"`

	EntryPointsByType EntryPointsByType `json:"entry_points_by_type"`

	ABI *ABI `json:"abi,omitempty"`
}

func (*ContractClass) UnmarshalJSON

func (c *ContractClass) UnmarshalJSON(content []byte) error

type DeployAccountRequest

type DeployAccountRequest struct {
	MaxFee *big.Int `json:"max_fee"`
	// Version of the transaction scheme, should be set to 0 or 1
	Version *big.Int `json:"version"`
	// Signature
	Signature Signature `json:"signature"`
	// Nonce should only be set with Transaction V1
	Nonce *big.Int `json:"nonce,omitempty"`

	Type                string   `json:"type"`
	ContractAddressSalt string   `json:"contract_address_salt"`
	ConstructorCalldata []string `json:"constructor_calldata"`
	ClassHash           string   `json:"class_hash"`
}

type DeployRequest

type DeployRequest struct {
	Type                string        `json:"type"`
	ContractAddressSalt string        `json:"contract_address_salt"`
	ConstructorCalldata []string      `json:"constructor_calldata"`
	ContractDefinition  ContractClass `json:"contract_definition"`
}

type EntryPoint

type EntryPoint struct {
	// The offset of the entry point in the program
	Offset NumAsHex `json:"offset"`
	// A unique identifier of the entry point (function) in the program
	Selector string `json:"selector"`
}

type EntryPointsByType

type EntryPointsByType struct {
	Constructor []EntryPoint `json:"CONSTRUCTOR"`
	External    []EntryPoint `json:"EXTERNAL"`
	L1Handler   []EntryPoint `json:"L1_HANDLER"`
}

type EventABIEntry

type EventABIEntry struct {
	// The event type
	Type ABIType `json:"type"`

	// The event name
	Name string `json:"name"`

	Keys []TypedParameter `json:"keys"`

	Data []TypedParameter `json:"data"`
}

func (*EventABIEntry) IsType

func (e *EventABIEntry) IsType() ABIType

type ExecuteDetails

type ExecuteDetails struct {
	MaxFee *big.Int
	Nonce  *big.Int
}

ExecuteDetails provides some details about the execution.

type FeeEstimate

type FeeEstimate struct {
	// GasConsumed the Ethereum gas cost of the transaction (see https://docs.starknet.io/docs/Fees/fee-mechanism for more info)
	GasConsumed NumAsHex `json:"gas_consumed"`

	// GasPrice the gas price (in gwei) that was used in the cost estimation
	GasPrice NumAsHex `json:"gas_price"`

	// OverallFee the estimated fee for the transaction (in gwei), product of gas_consumed and gas_price
	OverallFee NumAsHex `json:"overall_fee"`
}

type Felt

type Felt struct {
	*big.Int
}

Felt represents Field Element or Felt from cairo.

func BigToFelt

func BigToFelt(b *big.Int) *Felt

BigToFelt converts a big.Int to its Felt representation.

func BytesToFelt

func BytesToFelt(b []byte) *Felt

BytesToFelt converts a []byte to its Felt representation.

func StrToFelt

func StrToFelt(str string) *Felt

StrToFelt converts a string containing a decimal, hexadecimal or UTF8 charset into a Felt.

func (*Felt) Big

func (f *Felt) Big() *big.Int

Big converts a Felt to its big.Int representation.

func (Felt) MarshalGQL

func (f Felt) MarshalGQL(w io.Writer)

MarshalGQL implements the gqlgen Marshaller interface to marshal Felt into an io.Writer.

func (Felt) MarshalJSON

func (f Felt) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaller interface for Felt to marshal types to []byte.

func (*Felt) Scan

func (f *Felt) Scan(src interface{}) error

Scan implements the database/sql Scanner interface to read Felt from a databases.

func (*Felt) ShortString

func (f *Felt) ShortString() string

String converts a Felt into its 'short string' representation.

func (*Felt) String

func (f *Felt) String() string

String converts a Felt into its hexadecimal string representation and implement fmt.Stringer.

func (*Felt) UnmarshalGQL

func (b *Felt) UnmarshalGQL(v interface{}) error

UnmarshalGQL implements the gqlgen Unmarshaller interface to unmarshal an interface into a Felt.

func (*Felt) UnmarshalJSON

func (f *Felt) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the json Unmarshaller interface to unmarshal []byte into types.

func (Felt) Value

func (f Felt) Value() (driver.Value, error)

Value is used by database/sql drivers to store data in databases

type FunctionABIEntry

type FunctionABIEntry struct {
	// The function type
	Type ABIType `json:"type"`

	// The function name
	Name string `json:"name"`

	StateMutability *string `json:"stateMutability,omitempty"`

	Inputs []TypedParameter `json:"inputs"`

	Outputs []TypedParameter `json:"outputs"`
}

func (*FunctionABIEntry) IsType

func (f *FunctionABIEntry) IsType() ABIType

type FunctionCall

type FunctionCall struct {
	ContractAddress    Hash   `json:"contract_address"`
	EntryPointSelector string `json:"entry_point_selector,omitempty"`

	// Calldata The parameters passed to the function
	Calldata []string `json:"calldata"`
}

FunctionCall function call information

type FunctionInvoke

type FunctionInvoke struct {
	MaxFee *big.Int `json:"max_fee"`
	// Version of the transaction scheme, should be set to 0 or 1
	Version *big.Int `json:"version"`
	// Signature
	Signature Signature `json:"signature"`
	// Nonce should only be set with Transaction V1
	Nonce *big.Int `json:"nonce,omitempty"`
	// Defines the transaction type to invoke
	Type string `json:"type,omitempty"`

	FunctionCall
}

type Hash

type Hash [HashLength]byte

func BigToHash

func BigToHash(b *big.Int) Hash

BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.

func BytesToHash

func BytesToHash(b []byte) Hash

BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.

func HexToHash

func HexToHash(s string) Hash

HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func (Hash) Big

func (h Hash) Big() *big.Int

Big converts a hash to a big integer.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (Hash) Format

func (h Hash) Format(s fmt.State, c rune)

Format implements fmt.Formatter. Hash supports the %v, %s, %q, %x, %X and %d format verbs.

func (Hash) Generate

func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value

Generate implements testing/quick.Generator.

func (Hash) Hex

func (h Hash) Hex() string

Hex converts a hash to a hex string.

func (Hash) ImplementsGraphQLType

func (Hash) ImplementsGraphQLType(name string) bool

ImplementsGraphQLType returns true if Hash implements the specified GraphQL type.

func (Hash) MarshalJSON

func (h Hash) MarshalJSON() ([]byte, error)

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText returns the hex representation of h.

func (*Hash) Scan

func (h *Hash) Scan(src interface{}) error

Scan implements Scanner for database/sql.

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

func (Hash) String

func (h Hash) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash) TerminalString

func (h Hash) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (*Hash) UnmarshalGraphQL

func (h *Hash) UnmarshalGraphQL(input interface{}) error

UnmarshalGraphQL unmarshals the provided GraphQL query data.

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

func (Hash) Value

func (h Hash) Value() (driver.Value, error)

Value implements valuer for database/sql.

type KeccakState

type KeccakState interface {
	hash.Hash
	Read([]byte) (int, error)
}

KeccakState wraps sha3.state. In addition to the usual hash methods, it also supports Read to get a variable amount of data from the hash state. Read is faster than Sum because it doesn't copy the internal state, but also modifies the internal state.

func NewKeccakState

func NewKeccakState() KeccakState

NewKeccakState creates a new KeccakState (ref: https://github.com/ethereum/go-ethereum/blob/master/crypto/crypto.go)

type Member

type Member struct {
	TypedParameter
	Offset uint64 `json:"offset"`
}

type NumAsHex

type NumAsHex string

type Signature

type Signature []*big.Int

func (Signature) MarshalJSON

func (s Signature) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaller interface for a Signature array to marshal types to []byte.

type StructABIEntry

type StructABIEntry struct {
	// The event type
	Type ABIType `json:"type"`

	// The event name
	Name string `json:"name"`

	Size uint64 `json:"size"`

	Members []Member `json:"members"`
}

func (*StructABIEntry) IsType

func (s *StructABIEntry) IsType() ABIType

type TransactionState

type TransactionState string
const (
	TransactionAcceptedOnL1 TransactionState = "ACCEPTED_ON_L1"
	TransactionAcceptedOnL2 TransactionState = "ACCEPTED_ON_L2"
	TransactionNotReceived  TransactionState = "NOT_RECEIVED"
	TransactionPending      TransactionState = "PENDING"
	TransactionReceived     TransactionState = "RECEIVED"
	TransactionRejected     TransactionState = "REJECTED"
)

func (TransactionState) IsTransactionFinal

func (s TransactionState) IsTransactionFinal() bool

func (TransactionState) MarshalJSON

func (ts TransactionState) MarshalJSON() ([]byte, error)

func (TransactionState) String

func (s TransactionState) String() string

func (*TransactionState) UnmarshalJSON

func (ts *TransactionState) UnmarshalJSON(data []byte) error

type TypedParameter

type TypedParameter struct {
	// The parameter's name
	Name string `json:"name"`

	// The parameter's type
	Type string `json:"type"`
}

type Uint256

type Uint256 struct {
	Low  *Felt
	High *Felt
}

func NewUint256

func NewUint256(low, high *Felt) (*Uint256, error)

func Uint256FromBig

func Uint256FromBig(b *big.Int) (*Uint256, error)

func (*Uint256) Big

func (u *Uint256) Big() *big.Int

func (*Uint256) String

func (u *Uint256) String() string

Jump to

Keyboard shortcuts

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