github.com/uuosio/chaintester@v0.0.0-20230731100329-1f6fad7372e5/actionsender.go (about)

     1  package chaintester
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/uuosio/chaintester/interfaces"
     7  )
     8  
     9  type ActionSender struct {
    10  	tester  *ChainTester
    11  	actions []*interfaces.Action
    12  }
    13  
    14  func NewActionSender(tester *ChainTester) *ActionSender {
    15  	return &ActionSender{tester, nil}
    16  }
    17  
    18  func (sender *ActionSender) AddAction(account string, action string, args string, permissions string) {
    19  	_args := interfaces.NewActionArguments()
    20  	_args.JSONArgs_ = &args
    21  	_action := interfaces.Action{
    22  		Account:     account,
    23  		Action:      action,
    24  		Arguments:   _args,
    25  		Permissions: permissions,
    26  	}
    27  	sender.actions = append(sender.actions, &_action)
    28  }
    29  
    30  func (sender *ActionSender) AddActionEx(account string, action string, rawArgs []byte, permissions string) {
    31  	_args := interfaces.NewActionArguments()
    32  	_rawArgs := make([]byte, len(rawArgs))
    33  	copy(_rawArgs, rawArgs)
    34  	_args.RawArgs_ = _rawArgs
    35  	_action := interfaces.Action{
    36  		Account:     account,
    37  		Action:      action,
    38  		Arguments:   _args,
    39  		Permissions: permissions,
    40  	}
    41  	sender.actions = append(sender.actions, &_action)
    42  }
    43  
    44  func (sender *ActionSender) AddActionWithSigner(account string, action string, jsonArgs string, signer string) {
    45  	permissions := fmt.Sprintf(`{"%s": "active"}`, signer)
    46  	sender.AddAction(account, action, jsonArgs, permissions)
    47  }
    48  
    49  func (sender *ActionSender) AddActionWithSignerEx(account string, action string, rawArgs []byte, signer string) {
    50  	permissions := fmt.Sprintf(`{"%s": "active"}`, signer)
    51  	sender.AddActionEx(account, action, rawArgs, permissions)
    52  }
    53  
    54  func (sender *ActionSender) Send() (*JsonValue, error) {
    55  	return sender.tester.PushActions(sender.actions)
    56  }