evm

package
v0.3.11-update-id-2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: LGPL-3.0 Imports: 56 Imported by: 32

Documentation

Index

Constants

View Source
const (
	GenesisTestAddr = "0x751a0b96e1042bee789452ecb20253fba40dbe85"
	GenesisTestKey  = "0xabd71b35d559563fea757f0f5edbde286fb8c043105b15abb7cd57189306d7d1"
)

test constants

Variables

View Source
var Codec codec.Codec

Codec does serialization and deserialization

View Source
var (
	ID = ids.ID([32]byte{'e', 'v', 'm'})
)

ID this VM should be referenced by

Functions

func FormatEthAddress added in v0.3.5

func FormatEthAddress(addr common.Address) string

FormatEthAddress formats [addr] into a string

func GetEthAddress added in v0.2.12

func GetEthAddress(privKey *crypto.PrivateKeySECP256K1R) common.Address

GetEthAddress returns the ethereum address derived from [privKey]

func IsSortedAndUniqueEVMInputs added in v0.3.5

func IsSortedAndUniqueEVMInputs(inputs []EVMInput) bool

IsSortedAndUniqueEVMInputs returns true if the EVM Inputs are sorted and unique based on the account addresses

func IsSortedAndUniqueEVMOutputs added in v0.3.5

func IsSortedAndUniqueEVMOutputs(outputs []EVMOutput) bool

IsSortedAndUniqueEVMOutputs returns true if the EVMOutputs are sorted and unique based on the account addresses and assetIDs

func ParseEthAddress added in v0.3.5

func ParseEthAddress(addrStr string) (common.Address, error)

ParseEthAddress parses [addrStr] and returns an Ethereum address

func PublicKeyToEthAddress added in v0.2.12

func PublicKeyToEthAddress(pubKey crypto.PublicKey) common.Address

PublicKeyToEthAddress returns the ethereum address derived from [pubKey]

func SortEVMInputsAndSigners added in v0.3.5

func SortEVMInputsAndSigners(inputs []EVMInput, signers [][]*crypto.PrivateKeySECP256K1R)

SortEVMInputsAndSigners sorts the list of EVMInputs based on the addresses and assetIDs

func SortEVMOutputs added in v0.3.5

func SortEVMOutputs(outputs []EVMOutput)

SortEVMOutputs sorts the list of EVMOutputs based on the addresses and assetIDs of the outputs

Types

type AvaxAPI added in v0.2.15

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

AvaxAPI offers Avalanche network related API methods

func (*AvaxAPI) ClientVersion added in v0.3.8

func (service *AvaxAPI) ClientVersion() string

ClientVersion returns the version of the vm running

func (*AvaxAPI) Export added in v0.3.1

func (service *AvaxAPI) Export(_ *http.Request, args *ExportArgs, response *api.JSONTxID) error

Export exports an asset from the C-Chain to the X-Chain It must be imported on the X-Chain to complete the transfer

func (*AvaxAPI) ExportAVAX added in v0.2.15

func (service *AvaxAPI) ExportAVAX(_ *http.Request, args *ExportAVAXArgs, response *api.JSONTxID) error

ExportAVAX exports AVAX from the C-Chain to the X-Chain It must be imported on the X-Chain to complete the transfer

func (*AvaxAPI) ExportKey added in v0.2.15

func (service *AvaxAPI) ExportKey(r *http.Request, args *ExportKeyArgs, reply *ExportKeyReply) error

ExportKey returns a private key from the provided user

func (*AvaxAPI) Import added in v0.3.1

func (service *AvaxAPI) Import(_ *http.Request, args *ImportArgs, response *api.JSONTxID) error

Import issues a transaction to import AVAX from the X-chain. The AVAX must have already been exported from the X-Chain.

func (*AvaxAPI) ImportAVAX added in v0.2.15

func (service *AvaxAPI) ImportAVAX(_ *http.Request, args *ImportArgs, response *api.JSONTxID) error

ImportAVAX is a deprecated name for Import.

func (*AvaxAPI) ImportKey added in v0.2.15

func (service *AvaxAPI) ImportKey(r *http.Request, args *ImportKeyArgs, reply *api.JSONAddress) error

ImportKey adds a private key to the provided user

type Batch

type Batch struct{ database.Batch }

Batch implements ethdb.Batch

func (Batch) Replay

func (batch Batch) Replay(w ethdb.KeyValueWriter) error

Replay implements ethdb.Batch

type Block

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

Block implements the snowman.Block interface

func (*Block) Accept

func (b *Block) Accept() error

Accept implements the snowman.Block interface

func (*Block) Bytes

func (b *Block) Bytes() []byte

Bytes implements the snowman.Block interface

func (*Block) ID

func (b *Block) ID() ids.ID

ID implements the snowman.Block interface

func (*Block) Parent

func (b *Block) Parent() snowman.Block

Parent implements the snowman.Block interface

func (*Block) Reject

func (b *Block) Reject() error

Reject implements the snowman.Block interface

func (*Block) Status

func (b *Block) Status() choices.Status

Status implements the snowman.Block interface

func (*Block) String

func (b *Block) String() string

func (*Block) Verify

func (b *Block) Verify() error

Verify implements the snowman.Block interface

type CommandLineConfig added in v0.3.7

type CommandLineConfig struct {
	// Coreth APIs
	SnowmanAPIEnabled     bool `json:"snowman-api-enabled"`
	CorethAdminAPIEnabled bool `json:"coreth-admin-api-enabled"`

	// Coreth API Gas/Price Caps
	RPCGasCap   uint64  `json:"rpc-gas-cap"`
	RPCTxFeeCap float64 `json:"rpc-tx-fee-cap"`

	// Eth APIs
	EthAPIEnabled      bool `json:"eth-api-enabled"`
	PersonalAPIEnabled bool `json:"personal-api-enabled"`
	TxPoolAPIEnabled   bool `json:"tx-pool-api-enabled"`
	DebugAPIEnabled    bool `json:"debug-api-enabled"`

	ParsingError error
}

CommandLineConfig ...

func (CommandLineConfig) EthAPIs added in v0.3.7

func (c CommandLineConfig) EthAPIs() []string

EthAPIs returns an array of strings representing the Eth APIs that should be enabled

type Database

type Database struct{ database.Database }

Database implements ethdb.Database

func (Database) Ancient

func (db Database) Ancient(kind string, number uint64) ([]byte, error)

Ancient returns an error as we don't have a backing chain freezer.

func (Database) AncientSize

func (db Database) AncientSize(kind string) (uint64, error)

AncientSize returns an error as we don't have a backing chain freezer.

func (Database) Ancients

func (db Database) Ancients() (uint64, error)

Ancients returns an error as we don't have a backing chain freezer.

func (Database) AppendAncient

func (db Database) AppendAncient(number uint64, hash, header, body, receipts, td []byte) error

AppendAncient returns an error as we don't have a backing chain freezer.

func (Database) HasAncient

func (db Database) HasAncient(kind string, number uint64) (bool, error)

HasAncient returns an error as we don't have a backing chain freezer.

func (Database) NewBatch

func (db Database) NewBatch() ethdb.Batch

NewBatch implements ethdb.Database

func (Database) NewIterator

func (db Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator

NewIterator implements ethdb.Database

func (Database) NewIteratorWithStart

func (db Database) NewIteratorWithStart(start []byte) ethdb.Iterator

NewIteratorWithStart implements ethdb.Database

func (Database) Sync

func (db Database) Sync() error

Sync returns an error as we don't have a backing chain freezer.

func (Database) TruncateAncients

func (db Database) TruncateAncients(items uint64) error

TruncateAncients returns an error as we don't have a backing chain freezer.

type EVMInput added in v0.2.12

type EVMInput struct {
	Address common.Address `serialize:"true" json:"address"`
	Amount  uint64         `serialize:"true" json:"amount"`
	AssetID ids.ID         `serialize:"true" json:"assetID"`
	Nonce   uint64         `serialize:"true" json:"nonce"`
}

EVMInput defines an input for the EVM State to be used in import transactions

func (*EVMInput) Verify added in v0.2.12

func (in *EVMInput) Verify() error

Verify ...

type EVMOutput added in v0.2.12

type EVMOutput struct {
	Address common.Address `serialize:"true" json:"address"`
	Amount  uint64         `serialize:"true" json:"amount"`
	AssetID ids.ID         `serialize:"true" json:"assetID"`
}

EVMOutput defines an output from EVM State created from export transactions

func (*EVMOutput) Verify added in v0.2.12

func (out *EVMOutput) Verify() error

Verify ...

type ExportAVAXArgs added in v0.2.12

type ExportAVAXArgs struct {
	api.UserPass

	// AssetID of the tokens
	AssetID ids.ID `json:"assetID"`
	// Amount of asset to send
	Amount json.Uint64 `json:"amount"`

	// ID of the address that will receive the AVAX. This address includes the
	// chainID, which is used to determine what the destination chain is.
	To string `json:"to"`
}

ExportAVAXArgs are the arguments to ExportAVAX

type ExportArgs added in v0.3.1

type ExportArgs struct {
	ExportAVAXArgs
	// AssetID of the tokens
	AssetID ids.ID `json:"assetID"`
}

ExportArgs are the arguments to Export

type ExportKeyArgs added in v0.2.12

type ExportKeyArgs struct {
	api.UserPass
	Address string `json:"address"`
}

ExportKeyArgs are arguments for ExportKey

type ExportKeyReply added in v0.2.12

type ExportKeyReply struct {
	// The decrypted PrivateKey for the Address provided in the arguments
	PrivateKey    string `json:"privateKey"`
	PrivateKeyHex string `json:"privateKeyHex"`
}

ExportKeyReply is the response for ExportKey

type Factory

type Factory struct {
	Fee uint64
}

Factory ...

func (*Factory) New

func (f *Factory) New() interface{}

New ...

type GetAcceptedFrontReply

type GetAcceptedFrontReply struct {
	Hash   common.Hash `json:"hash"`
	Number *big.Int    `json:"number"`
}

GetAcceptedFrontReply defines the reply that will be sent from the GetAcceptedFront API call

type ImportArgs added in v0.3.1

type ImportArgs struct {
	api.UserPass

	// Chain the funds are coming from
	SourceChain string `json:"sourceChain"`

	// The address that will receive the imported funds
	To string `json:"to"`
}

ImportArgs are arguments for passing into Import requests

type ImportKeyArgs added in v0.2.12

type ImportKeyArgs struct {
	api.UserPass
	PrivateKey string `json:"privateKey"`
}

ImportKeyArgs are arguments for ImportKey

type SnowmanAPI

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

SnowmanAPI introduces snowman specific functionality to the evm

func (*SnowmanAPI) GetAcceptedFront

func (api *SnowmanAPI) GetAcceptedFront(ctx context.Context) (*GetAcceptedFrontReply, error)

GetAcceptedFront returns the last accepted block's hash and height

func (*SnowmanAPI) IssueBlock added in v0.3.7

func (api *SnowmanAPI) IssueBlock(ctx context.Context) error

IssueBlock to the chain

type StaticService

type StaticService struct{}

StaticService defines the static API services exposed by the evm

func (*StaticService) BuildGenesis

func (*StaticService) BuildGenesis(_ context.Context, args *core.Genesis) (formatting.CB58, error)

BuildGenesis returns the UTXOs such that at least one address in [args.Addresses] is referenced in the UTXO.

type Tx added in v0.2.12

type Tx struct {
	// The body of this transaction
	UnsignedTx `serialize:"true" json:"unsignedTx"`

	// The credentials of this transaction
	Creds []verify.Verifiable `serialize:"true" json:"credentials"`
}

Tx is a signed transaction

func (*Tx) Sign added in v0.2.12

func (tx *Tx) Sign(c codec.Codec, signers [][]*crypto.PrivateKeySECP256K1R) error

Sign this transaction with the provided signers

type TxError added in v0.2.12

type TxError interface {
	error
	Temporary() bool
}

TxError provides the ability for errors to be distinguished as permenant or temporary

type UnsignedAtomicTx added in v0.2.12

type UnsignedAtomicTx interface {
	UnsignedTx

	// UTXOs this tx consumes
	InputUTXOs() ids.Set
	// Attempts to verify this transaction with the provided state.
	SemanticVerify(vm *VM, stx *Tx) TxError

	// Accept this transaction with the additionally provided state transitions.
	Accept(ctx *snow.Context, batch database.Batch) error

	EVMStateTransfer(vm *VM, state *state.StateDB) error
}

UnsignedAtomicTx is an unsigned operation that can be atomically accepted

type UnsignedExportTx added in v0.2.12

type UnsignedExportTx struct {
	avax.Metadata

	// ID of the network on which this tx was issued
	NetworkID uint32 `serialize:"true" json:"networkID"`
	// ID of this blockchain.
	BlockchainID ids.ID `serialize:"true" json:"blockchainID"`
	// Which chain to send the funds to
	DestinationChain ids.ID `serialize:"true" json:"destinationChain"`
	// Inputs
	Ins []EVMInput `serialize:"true" json:"inputs"`
	// Outputs that are exported to the chain
	ExportedOutputs []*avax.TransferableOutput `serialize:"true" json:"exportedOutputs"`
	// contains filtered or unexported fields
}

UnsignedExportTx is an unsigned ExportTx

func (*UnsignedExportTx) Accept added in v0.2.12

func (tx *UnsignedExportTx) Accept(ctx *snow.Context, _ database.Batch) error

Accept this transaction.

func (*UnsignedExportTx) EVMStateTransfer added in v0.2.12

func (tx *UnsignedExportTx) EVMStateTransfer(vm *VM, state *state.StateDB) error

EVMStateTransfer executes the state update from the atomic export transaction

func (*UnsignedExportTx) InputUTXOs added in v0.2.12

func (tx *UnsignedExportTx) InputUTXOs() ids.Set

InputUTXOs returns an empty set

func (*UnsignedExportTx) SemanticVerify added in v0.2.12

func (tx *UnsignedExportTx) SemanticVerify(
	vm *VM,
	stx *Tx,
) TxError

SemanticVerify this transaction is valid.

func (*UnsignedExportTx) Verify added in v0.2.12

func (tx *UnsignedExportTx) Verify(
	avmID ids.ID,
	ctx *snow.Context,
	feeAmount uint64,
	feeAssetID ids.ID,
) error

Verify this transaction is well-formed

type UnsignedImportTx added in v0.2.12

type UnsignedImportTx struct {
	avax.Metadata

	// ID of the network on which this tx was issued
	NetworkID uint32 `serialize:"true" json:"networkID"`
	// ID of this blockchain.
	BlockchainID ids.ID `serialize:"true" json:"blockchainID"`
	// Which chain to consume the funds from
	SourceChain ids.ID `serialize:"true" json:"sourceChain"`
	// Inputs that consume UTXOs produced on the chain
	ImportedInputs []*avax.TransferableInput `serialize:"true" json:"importedInputs"`
	// Outputs
	Outs []EVMOutput `serialize:"true" json:"outputs"`
	// contains filtered or unexported fields
}

UnsignedImportTx is an unsigned ImportTx

func (*UnsignedImportTx) Accept added in v0.2.12

func (tx *UnsignedImportTx) Accept(ctx *snow.Context, _ database.Batch) error

Accept this transaction and spend imported inputs We spend imported UTXOs here rather than in semanticVerify because we don't want to remove an imported UTXO in semanticVerify only to have the transaction not be Accepted. This would be inconsistent. Recall that imported UTXOs are not kept in a versionDB.

func (*UnsignedImportTx) EVMStateTransfer added in v0.2.12

func (tx *UnsignedImportTx) EVMStateTransfer(vm *VM, state *state.StateDB) error

EVMStateTransfer performs the state transfer to increase the balances of accounts accordingly with the imported EVMOutputs

func (*UnsignedImportTx) InputUTXOs added in v0.2.12

func (tx *UnsignedImportTx) InputUTXOs() ids.Set

InputUTXOs returns the UTXOIDs of the imported funds

func (*UnsignedImportTx) SemanticVerify added in v0.2.12

func (tx *UnsignedImportTx) SemanticVerify(
	vm *VM,
	stx *Tx,
) TxError

SemanticVerify this transaction is valid.

func (*UnsignedImportTx) Verify added in v0.2.12

func (tx *UnsignedImportTx) Verify(
	avmID ids.ID,
	ctx *snow.Context,
	feeAmount uint64,
	feeAssetID ids.ID,
) error

Verify this transaction is well-formed

type UnsignedTx added in v0.2.12

type UnsignedTx interface {
	Initialize(unsignedBytes, signedBytes []byte)
	ID() ids.ID
	UnsignedBytes() []byte
	Bytes() []byte
}

UnsignedTx is an unsigned transaction

type VM

type VM struct {
	CLIConfig CommandLineConfig
	// contains filtered or unexported fields
}

VM implements the snowman.ChainVM interface

func (*VM) Bootstrapped added in v0.2.4

func (vm *VM) Bootstrapped() error

Bootstrapped notifies this VM that the consensus engine has finished bootstrapping

func (*VM) Bootstrapping added in v0.2.4

func (vm *VM) Bootstrapping() error

Bootstrapping notifies this VM that the consensus engine is performing bootstrapping

func (*VM) BuildBlock

func (vm *VM) BuildBlock() (snowman.Block, error)

BuildBlock implements the snowman.ChainVM interface

func (*VM) Clock added in v0.2.12

func (vm *VM) Clock() *timer.Clock

Clock implements the secp256k1fx interface

func (*VM) Codec added in v0.2.12

func (vm *VM) Codec() codec.Codec

Codec implements the secp256k1fx interface

func (*VM) CreateHandlers

func (vm *VM) CreateHandlers() map[string]*commonEng.HTTPHandler

CreateHandlers makes new http handlers that can handle API calls

func (*VM) CreateStaticHandlers

func (vm *VM) CreateStaticHandlers() map[string]*commonEng.HTTPHandler

CreateStaticHandlers makes new http handlers that can handle API calls

func (*VM) GetAcceptedNonce added in v0.2.12

func (vm *VM) GetAcceptedNonce(address common.Address) (uint64, error)

GetAcceptedNonce returns the nonce associated with the address at the last accepted block

func (*VM) GetAtomicUTXOs added in v0.2.12

func (vm *VM) GetAtomicUTXOs(
	chainID ids.ID,
	addrs ids.ShortSet,
	startAddr ids.ShortID,
	startUTXOID ids.ID,
	limit int,
) ([]*avax.UTXO, ids.ShortID, ids.ID, error)

GetAtomicUTXOs returns the utxos that at least one of the provided addresses is referenced in.

func (*VM) GetBlock

func (vm *VM) GetBlock(id ids.ID) (snowman.Block, error)

GetBlock implements the snowman.ChainVM interface

func (*VM) GetSpendableFunds added in v0.3.5

func (vm *VM) GetSpendableFunds(keys []*crypto.PrivateKeySECP256K1R, assetID ids.ID, amount uint64) ([]EVMInput, [][]*crypto.PrivateKeySECP256K1R, error)

GetSpendableFunds returns a list of EVMInputs and keys (in corresponding order) to total [amount] of [assetID] owned by [keys] TODO switch to returning a list of private keys since there are no multisig inputs in Ethereum

func (*VM) Health added in v0.3.1

func (vm *VM) Health() (interface{}, error)

Health returns nil if this chain is healthy. Also returns details, which should be one of: string, []byte, map[string]string

func (*VM) Initialize

func (vm *VM) Initialize(
	ctx *snow.Context,
	db database.Database,
	b []byte,
	toEngine chan<- commonEng.Message,
	fxs []*commonEng.Fx,
) error

Initialize implements the snowman.ChainVM interface

func (*VM) LastAccepted

func (vm *VM) LastAccepted() ids.ID

LastAccepted returns the ID of the block that was last accepted

func (*VM) Logger added in v0.2.12

func (vm *VM) Logger() logging.Logger

Logger implements the secp256k1fx interface

func (*VM) ParseAddress added in v0.2.12

func (vm *VM) ParseAddress(addrStr string) (ids.ID, ids.ShortID, error)

ParseAddress takes in an address and produces the ID of the chain it's for the ID of the address

func (*VM) ParseBlock

func (vm *VM) ParseBlock(b []byte) (snowman.Block, error)

ParseBlock implements the snowman.ChainVM interface

func (*VM) SetPreference

func (vm *VM) SetPreference(blkID ids.ID)

SetPreference sets what the current tail of the chain is

func (*VM) Shutdown

func (vm *VM) Shutdown() error

Shutdown implements the snowman.ChainVM interface

Jump to

Keyboard shortcuts

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