types

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: MIT Imports: 19 Imported by: 0

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 added in v0.4.0

func BigToHex(in *big.Int) string

convert big int to hexidecimal string

func BytesToBig added in v0.4.0

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

func ComputeFact added in v0.4.0

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

compute the keccack fact given the program hash and outputs

func FmtKecBytes added in v0.4.0

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

format the bytes in Keccak hash

func GetSelectorFromName added in v0.4.0

func GetSelectorFromName(funcName string) *big.Int

func HexToBN added in v0.4.0

func HexToBN(hexString string) *big.Int

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

func HexToBytes added in v0.4.0

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

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

func HexToShortStr added in v0.4.0

func HexToShortStr(hexStr string) string

convert hex string to StarkNet 'short string'

func Keccak256 added in v0.4.0

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 added in v0.4.0

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

mask excess bits

func SNValToBN added in v0.4.0

func SNValToBN(str string) *big.Int

used in string conversions when interfacing with the APIs

func SplitFactStr added in v0.4.0

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

split a fact into two felts

func StrToBig added in v0.4.0

func StrToBig(str string) *big.Int

convert decimal string to big int

func UTF8StrToBig added in v0.4.0

func UTF8StrToBig(str string) *big.Int

convert utf8 string to big int

Types

type ABI

type ABI []ABIEntry

type ABIEntry added in v0.4.0

type ABIEntry interface {
	IsType() ABIType
}

type ABIType added in v0.4.0

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

type AddDeclareResponse added in v0.4.0

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

type AddDeployResponse added in v0.4.0

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

type AddInvokeTransactionOutput added in v0.4.0

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 added in v0.4.0

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

type DeployAccountRequest added in v0.4.0

type DeployAccountRequest struct {
	MaxFee *big.Int `json:"max_fee"`
	// Version of the transaction scheme, should be set to 0 or 1
	Version uint64 `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 added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

func (e *EventABIEntry) IsType() ABIType

type ExecuteDetails added in v0.4.0

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

ExecuteDetails provides some details about the execution.

type FeeEstimate

type FeeEstimate struct {
	GasConsumed NumAsHex `json:"gas_consumed"`
	GasPrice    NumAsHex `json:"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 added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

type Hash [HashLength]byte

func BigToHash added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

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

Big converts a hash to a big integer.

func (Hash) Bytes added in v0.4.0

func (h Hash) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (Hash) Format added in v0.4.0

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 added in v0.4.0

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

Generate implements testing/quick.Generator.

func (Hash) Hex added in v0.4.0

func (h Hash) Hex() string

Hex converts a hash to a hex string.

func (Hash) ImplementsGraphQLType added in v0.4.0

func (Hash) ImplementsGraphQLType(name string) bool

ImplementsGraphQLType returns true if Hash implements the specified GraphQL type.

func (Hash) MarshalJSON added in v0.4.0

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

func (Hash) MarshalText added in v0.4.0

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

MarshalText returns the hex representation of h.

func (*Hash) Scan added in v0.4.0

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

Scan implements Scanner for database/sql.

func (*Hash) SetBytes added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

func (h Hash) TerminalString() string

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

func (*Hash) UnmarshalGraphQL added in v0.4.0

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

UnmarshalGraphQL unmarshals the provided GraphQL query data.

func (*Hash) UnmarshalJSON added in v0.4.0

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

UnmarshalJSON parses a hash in hex syntax.

func (*Hash) UnmarshalText added in v0.4.0

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

UnmarshalText parses a hash in hex syntax.

func (Hash) Value added in v0.4.0

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

Value implements valuer for database/sql.

type KeccakState added in v0.4.0

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 added in v0.4.0

func NewKeccakState() KeccakState

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

type Member added in v0.4.0

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

type NumAsHex added in v0.4.0

type NumAsHex string

type Signature added in v0.4.0

type Signature []*big.Int

func (Signature) MarshalJSON added in v0.4.0

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

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

type StructABIEntry added in v0.4.0

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 added in v0.4.0

func (s *StructABIEntry) IsType() ABIType

type TransactionState added in v0.4.0

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 added in v0.4.0

func (s TransactionState) IsTransactionFinal() bool

func (TransactionState) MarshalJSON added in v0.4.0

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

func (TransactionState) String added in v0.4.0

func (s TransactionState) String() string

func (*TransactionState) UnmarshalJSON added in v0.4.0

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

type TypedParameter added in v0.4.0

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

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

type Uint256 added in v0.4.0

type Uint256 struct {
	Low  *Felt
	High *Felt
}

func NewUint256 added in v0.4.0

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

func Uint256FromBig added in v0.4.0

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

func (*Uint256) Big added in v0.4.0

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

func (*Uint256) String added in v0.4.0

func (u *Uint256) String() string

Jump to

Keyboard shortcuts

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