safe

package
v0.0.0-...-011bec4 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package safe contains types for working with Safe smart contract wallets. These are used to build batch transactions for the tx-builder app. The types are based on https://github.com/safe-global/safe-react-apps/blob/development/apps/tx-builder/src/typings/models.ts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batch

type Batch struct {
	SkipCalldata bool               `json:"-"`
	Version      string             `json:"version"`
	ChainID      *big.Int           `json:"chainId"`
	CreatedAt    uint64             `json:"createdAt"`
	Meta         BatchMeta          `json:"meta"`
	Transactions []BatchTransaction `json:"transactions"`
}

Batch represents a Safe tx-builder transaction. SkipCalldata will skip adding the calldata to the BatchTransaction. This is useful for when using the Safe UI because it prefers using the raw calldata when both the calldata and ABIs with arguments are present.

func (*Batch) AddCall

func (b *Batch) AddCall(to common.Address, value *big.Int, sig string, args []any, iface *abi.ABI) error

AddCall will add a call to the batch. After a series of calls are added to the batch, it can be serialized to JSON.

func (*Batch) Check

func (b *Batch) Check() error

Check will check the batch for errors

func (*Batch) MarshalJSON

func (b *Batch) MarshalJSON() ([]byte, error)

MarshalJSON will marshal a Batch to JSON.

func (*Batch) UnmarshalJSON

func (b *Batch) UnmarshalJSON(data []byte) error

UnmarshalJSON will unmarshal a Batch from JSON.

type BatchMeta

type BatchMeta struct {
	TxBuilderVersion        string `json:"txBuilderVersion,omitempty"`
	Checksum                string `json:"checksum,omitempty"`
	CreatedFromSafeAddress  string `json:"createdFromSafeAddress"`
	CreatedFromOwnerAddress string `json:"createdFromOwnerAddress"`
	Name                    string `json:"name"`
	Description             string `json:"description"`
}

BatchMeta contains metadata about a Batch. Not all of the fields are required.

type BatchTransaction

type BatchTransaction struct {
	To          common.Address    `json:"to"`
	Value       *big.Int          `json:"value"`
	Data        []byte            `json:"data"`
	Method      ContractMethod    `json:"contractMethod"`
	InputValues map[string]string `json:"contractInputsValues"`
}

BatchTransaction represents a single call in a tx-builder transaction.

func (*BatchTransaction) Arguments

func (bt *BatchTransaction) Arguments() abi.Arguments

func (*BatchTransaction) Check

func (bt *BatchTransaction) Check() error

Check will check the batch transaction for errors. An error is defined by: - incorrectly encoded calldata - mismatch in number of arguments It does not currently work on structs, will return no error if a "tuple" is used as an argument. Need to find a generic way to work with structs.

func (*BatchTransaction) MarshalJSON

func (b *BatchTransaction) MarshalJSON() ([]byte, error)

MarshalJSON will marshal a BatchTransaction to JSON.

func (*BatchTransaction) Signature

func (bt *BatchTransaction) Signature() string

Signature returns the function signature of the batch transaction.

func (*BatchTransaction) UnmarshalJSON

func (b *BatchTransaction) UnmarshalJSON(data []byte) error

UnmarshalJSON will unmarshal a BatchTransaction from JSON.

type ContractInput

type ContractInput struct {
	InternalType string          `json:"internalType"`
	Name         string          `json:"name"`
	Type         string          `json:"type"`
	Components   []ContractInput `json:"components,omitempty"`
}

ContractInput represents an input to a contract method.

type ContractMethod

type ContractMethod struct {
	Inputs  []ContractInput `json:"inputs"`
	Name    string          `json:"name"`
	Payable bool            `json:"payable"`
}

ContractMethod represents a method call in a tx-builder transaction.

Jump to

Keyboard shortcuts

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