github.com/MetalBlockchain/metalgo@v1.11.9/vms/avm/fxs/fx.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package fxs 5 6 import ( 7 "github.com/MetalBlockchain/metalgo/ids" 8 "github.com/MetalBlockchain/metalgo/snow" 9 "github.com/MetalBlockchain/metalgo/vms/components/avax" 10 "github.com/MetalBlockchain/metalgo/vms/components/verify" 11 "github.com/MetalBlockchain/metalgo/vms/nftfx" 12 "github.com/MetalBlockchain/metalgo/vms/propertyfx" 13 "github.com/MetalBlockchain/metalgo/vms/secp256k1fx" 14 ) 15 16 var ( 17 _ Fx = (*secp256k1fx.Fx)(nil) 18 _ Fx = (*nftfx.Fx)(nil) 19 _ Fx = (*propertyfx.Fx)(nil) 20 _ verify.Verifiable = (*FxCredential)(nil) 21 ) 22 23 type ParsedFx struct { 24 ID ids.ID 25 Fx Fx 26 } 27 28 // Fx is the interface a feature extension must implement to support the AVM. 29 type Fx interface { 30 // Initialize this feature extension to be running under this VM. Should 31 // return an error if the VM is incompatible. 32 Initialize(vm interface{}) error 33 34 // Notify this Fx that the VM is in bootstrapping 35 Bootstrapping() error 36 37 // Notify this Fx that the VM is bootstrapped 38 Bootstrapped() error 39 40 // VerifyTransfer verifies that the specified transaction can spend the 41 // provided utxo with no restrictions on the destination. If the transaction 42 // can't spend the output based on the input and credential, a non-nil error 43 // should be returned. 44 VerifyTransfer(tx, in, cred, utxo interface{}) error 45 46 // VerifyOperation verifies that the specified transaction can spend the 47 // provided utxos conditioned on the result being restricted to the provided 48 // outputs. If the transaction can't spend the output based on the input and 49 // credential, a non-nil error should be returned. 50 VerifyOperation(tx, op, cred interface{}, utxos []interface{}) error 51 } 52 53 type FxOperation interface { 54 verify.Verifiable 55 snow.ContextInitializable 56 avax.Coster 57 58 Outs() []verify.State 59 } 60 61 type FxCredential struct { 62 FxID ids.ID `serialize:"false" json:"fxID"` 63 Credential verify.Verifiable `serialize:"true" json:"credential"` 64 } 65 66 func (f *FxCredential) Verify() error { 67 return f.Credential.Verify() 68 }