/**
* Add a smart contract method call to this atomic group.
*
* An error will be thrown if the composer's status is not BUILDING, if adding this transaction
* causes the current group to exceed MAX_GROUP_SIZE, or if the provided arguments are invalid
* for the given method.
 */
Add a smart contract method call to this atomic group.

An error will be thrown if the composer's status is not BUILDING, if adding this transaction
causes the current group to exceed MAX_GROUP_SIZE, or if the provided arguments are invalid
for the given method.
/ ** * Add a smart contract method call to this atomic group . * * An error will be thrown if the composer ' s status is not BUILDING if adding this transaction * causes the current group to exceed MAX_GROUP_SIZE or if the provided arguments are invalid * for the given method . * /
func (atc *AtomicTransactionComposer) AddMethodCall(params AddMethodCallParams) error {
	if atc.status != BUILDING {
		return errors.New("status must be BUILDING in order to add transactions")
	}
	if len(params.MethodArgs) != len(params.Method.Args) {
		return fmt.Errorf("the incorrect number of arguments were provided: %d != %d", len(params.MethodArgs), len(params.Method.Args))
	}
	if atc.Count()+params.Method.GetTxCountFromMethod() > MAX_GROUP_SIZE {
		return fmt.Errorf("reached max group size: %d", MAX_GROUP_SIZE)
	}
	selectorValue := params.Method.GetSelector()
	encodedAbiArgs := [][]byte{selectorValue}
	var txsToAdd []TransactionWithSigner
	var abiArgs []interface{}
	var abiTypes []abi.Type
	for i, arg := range params.Method.Args {
		if _, ok := abi.TransactionArgTypes[arg.AbiType]; ok {
			txnAndSigner, ok := params.MethodArgs[i].(TransactionWithSigner)
			if !ok {
				return fmt.Errorf("invalid arg type, expected transaction")
			}
			err := atc.validateTransaction(txnAndSigner.Txn)
			if err != nil {
				return err
			}
			txsToAdd = append(txsToAdd, txnAndSigner)
		} else {
			abiType, err := abi.TypeOf(arg.AbiType)
			if err != nil {
				return err
			}
			abiArgs = append(abiArgs, params.MethodArgs[i])
			abiTypes = append(abiTypes, abiType)
		}
	}
	if len(abiArgs) > 14 {
		tupleTypes := abiTypes[14:]
		tupleValues := abiArgs[14:]
		tupleType, err := abi.MakeTupleType(tupleTypes)
		if err != nil {
			return err
		}
		abiArgs = abiArgs[:14]
		abiArgs = append(abiArgs, tupleValues)
		abiTypes = abiTypes[:14]
		abiTypes = append(abiTypes, tupleType)
	}
	for i, abiArg := range abiArgs {
		encodedArg, err := abiTypes[i].Encode(abiArg)
		if err != nil {
			return err
		}
		encodedAbiArgs = append(encodedAbiArgs, encodedArg)
	}
	tx, err := MakeApplicationCallTx(
		params.AppID,
		encodedAbiArgs,
		nil,
		nil,
		nil,
		params.OnComplete,
		nil,
		nil,
		types.StateSchema{},
		types.StateSchema{},
		params.SuggestedParams,
		params.Sender,
		params.Note,
		types.Digest{},
		params.Lease,
		params.RekeyTo)
	if err != nil {
		return err
	}
	txAndSigner := TransactionWithSigner{
		Txn:    tx,
		Signer: params.Signer,
	}
	for _, txAndSigner := range txsToAdd {
		txContext := transactionContext{
			txn:    txAndSigner.Txn,
			signer: txAndSigner.Signer,
		}
		atc.txContexts = append(atc.txContexts, txContext)
	}
	methodCallTxContext := transactionContext{
		txn:    txAndSigner.Txn,
		signer: txAndSigner.Signer,
		method: &params.Method,
	}
	atc.txContexts = append(atc.txContexts, methodCallTxContext)
	return nil
}
func ( atc * AtomicTransactionComposer ) AddMethodCall ( params AddMethodCallParams ) error { if atc . status != BUILDING { return errors . New ( " " ) } if len ( params . MethodArgs ) != len ( params . Method . Args ) { return fmt . Errorf ( " " , len ( params . MethodArgs ) , len ( params . Method . Args ) ) } if atc . Count ( ) + params . Method . GetTxCountFromMethod ( ) > MAX_GROUP_SIZE { return fmt . Errorf ( " " , MAX_GROUP_SIZE ) } selectorValue := params . Method . GetSelector ( ) encodedAbiArgs := [ ] [ ] byte { selectorValue } var txsToAdd [ ] TransactionWithSigner var abiArgs [ ] interface { } var abiTypes [ ] abi . Type for i , arg := range params . Method . Args { if _ , ok := abi . TransactionArgTypes [ arg . AbiType ] ; ok { txnAndSigner , ok := params . MethodArgs [ i ] . ( TransactionWithSigner ) if ! ok { return fmt . Errorf ( " " ) } err := atc . validateTransaction ( txnAndSigner . Txn ) if err != nil { return err } txsToAdd = append ( txsToAdd , txnAndSigner ) } else { abiType , err := abi . TypeOf ( arg . AbiType ) if err != nil { return err } abiArgs = append ( abiArgs , params . MethodArgs [ i ] ) abiTypes = append ( abiTypes , abiType ) } } if len ( abiArgs ) > 14 { tupleTypes := abiTypes [ 14 : ] tupleValues := abiArgs [ 14 : ] tupleType , err := abi . MakeTupleType ( tupleTypes ) if err != nil { return err } abiArgs = abiArgs [ : 14 ] abiArgs = append ( abiArgs , tupleValues ) abiTypes = abiTypes [ : 14 ] abiTypes = append ( abiTypes , tupleType ) } for i , abiArg := range abiArgs { encodedArg , err := abiTypes [ i ] . Encode ( abiArg ) if err != nil { return err } encodedAbiArgs = append ( encodedAbiArgs , encodedArg ) } tx , err := MakeApplicationCallTx ( params . AppID , encodedAbiArgs , nil , nil , nil , params . OnComplete , nil , nil , types . StateSchema { } , types . StateSchema { } , params . SuggestedParams , params . Sender , params . Note , types . Digest { } , params . Lease , params . RekeyTo ) if err != nil { return err } txAndSigner := TransactionWithSigner { Txn : tx , Signer : params . Signer , } for _ , txAndSigner := range txsToAdd { txContext := transactionContext { txn : txAndSigner . Txn , signer : txAndSigner . Signer , } atc . txContexts = append ( atc . txContexts , txContext ) } methodCallTxContext := transactionContext { txn : txAndSigner . Txn , signer : txAndSigner . Signer , method : & params . Method , } atc . txContexts = append ( atc . txContexts , methodCallTxContext ) return nil }
Add a smart contract method call to this atomic group.
Add a smart contract method call to this atomic group .
// Up to 16 args can be passed to app call. First is reserved for method selector and last is // reserved for remaining args packaged into one tuple.