diff options
author | StephenButtolph <[email protected]> | 2020-08-20 09:42:06 -0400 |
---|---|---|
committer | StephenButtolph <[email protected]> | 2020-08-20 09:42:06 -0400 |
commit | 52c6ccd2f063a6cccc35f5b4380b22fb9dd0f102 (patch) | |
tree | 465d0b4981d28835483f56e19129b27e986494d6 /plugin/evm/export_tx.go | |
parent | 6febda1bc51f6658ab8f5cf705454e3f9c24a1f4 (diff) |
implemented exportTx accept
Diffstat (limited to 'plugin/evm/export_tx.go')
-rw-r--r-- | plugin/evm/export_tx.go | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/plugin/evm/export_tx.go b/plugin/evm/export_tx.go index 8b3c4f8..31b4681 100644 --- a/plugin/evm/export_tx.go +++ b/plugin/evm/export_tx.go @@ -10,6 +10,7 @@ import ( "github.com/ava-labs/coreth/core/state" "github.com/ava-labs/go-ethereum/log" + "github.com/ava-labs/gecko/chains/atomic" "github.com/ava-labs/gecko/database" "github.com/ava-labs/gecko/ids" "github.com/ava-labs/gecko/snow" @@ -126,9 +127,37 @@ func (tx *UnsignedExportTx) SemanticVerify( } // Accept this transaction. -func (tx *UnsignedExportTx) Accept(ctx *snow.Context, batch database.Batch) error { - // TODO: finish this function via gRPC - return nil +func (tx *UnsignedExportTx) Accept(ctx *snow.Context, _ database.Batch) error { + txID := tx.ID() + + elems := make([]*atomic.Element, len(tx.ExportedOutputs)) + for i, out := range tx.ExportedOutputs { + utxo := &avax.UTXO{ + UTXOID: avax.UTXOID{ + TxID: txID, + OutputIndex: uint32(i), + }, + Asset: avax.Asset{ID: out.AssetID()}, + Out: out.Out, + } + + utxoBytes, err := Codec.Marshal(utxo) + if err != nil { + return err + } + + elem := &atomic.Element{ + Key: utxo.InputID().Bytes(), + Value: utxoBytes, + } + if out, ok := utxo.Out.(avax.Addressable); ok { + elem.Traits = out.Addresses() + } + + elems[i] = elem + } + + return ctx.SharedMemory.Put(tx.DestinationChain, elems) } // Create a new transaction |