github.com/MetalBlockchain/metalgo@v1.11.9/vms/example/xsvm/cmd/issue/importtx/flags.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package importtx 5 6 import ( 7 "github.com/spf13/pflag" 8 9 "github.com/MetalBlockchain/metalgo/genesis" 10 "github.com/MetalBlockchain/metalgo/ids" 11 "github.com/MetalBlockchain/metalgo/utils/crypto/secp256k1" 12 "github.com/MetalBlockchain/metalgo/wallet/subnet/primary" 13 ) 14 15 const ( 16 URIKey = "uri" 17 SourceURIsKey = "source-uris" 18 SourceChainIDKey = "source-chain-id" 19 DestinationChainIDKey = "destination-chain-id" 20 TxIDKey = "tx-id" 21 MaxFeeKey = "max-fee" 22 PrivateKeyKey = "private-key" 23 ) 24 25 func AddFlags(flags *pflag.FlagSet) { 26 flags.String(URIKey, primary.LocalAPIURI, "API URI to use during issuance") 27 flags.StringSlice(SourceURIsKey, []string{primary.LocalAPIURI}, "API URIs to use during the fetching of signatures") 28 flags.String(SourceChainIDKey, "", "Chain the export transaction was issued on") 29 flags.String(DestinationChainIDKey, "", "Chain to send the asset to") 30 flags.String(TxIDKey, "", "ID of the export transaction") 31 flags.Uint64(MaxFeeKey, 0, "Maximum fee to spend") 32 flags.String(PrivateKeyKey, genesis.EWOQKeyFormattedStr, "Private key to sign the transaction") 33 } 34 35 type Config struct { 36 URI string 37 SourceURIs []string 38 SourceChainID string 39 DestinationChainID string 40 TxID ids.ID 41 MaxFee uint64 42 PrivateKey *secp256k1.PrivateKey 43 } 44 45 func ParseFlags(flags *pflag.FlagSet, args []string) (*Config, error) { 46 if err := flags.Parse(args); err != nil { 47 return nil, err 48 } 49 50 uri, err := flags.GetString(URIKey) 51 if err != nil { 52 return nil, err 53 } 54 55 sourceURIs, err := flags.GetStringSlice(SourceURIsKey) 56 if err != nil { 57 return nil, err 58 } 59 60 sourceChainID, err := flags.GetString(SourceChainIDKey) 61 if err != nil { 62 return nil, err 63 } 64 65 destinationChainID, err := flags.GetString(DestinationChainIDKey) 66 if err != nil { 67 return nil, err 68 } 69 70 txIDStr, err := flags.GetString(TxIDKey) 71 if err != nil { 72 return nil, err 73 } 74 75 txID, err := ids.FromString(txIDStr) 76 if err != nil { 77 return nil, err 78 } 79 80 maxFee, err := flags.GetUint64(MaxFeeKey) 81 if err != nil { 82 return nil, err 83 } 84 85 skStr, err := flags.GetString(PrivateKeyKey) 86 if err != nil { 87 return nil, err 88 } 89 90 var sk secp256k1.PrivateKey 91 err = sk.UnmarshalText([]byte(`"` + skStr + `"`)) 92 if err != nil { 93 return nil, err 94 } 95 96 return &Config{ 97 URI: uri, 98 SourceURIs: sourceURIs, 99 SourceChainID: sourceChainID, 100 DestinationChainID: destinationChainID, 101 TxID: txID, 102 MaxFee: maxFee, 103 PrivateKey: &sk, 104 }, nil 105 }