parent
818d5988f5
commit
ec6317d643
1 changed files with 45 additions and 29 deletions
|
@ -433,8 +433,10 @@ func addNetworkFee(bc *Blockchain, tx *transaction.Transaction, sender *wallet.A
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Signer can be either bool or *wallet.Account.
|
||||||
|
// In the first case `true` means sign by committee, `false` means sign by validators.
|
||||||
func prepareContractMethodInvokeGeneric(chain *Blockchain, sysfee int64,
|
func prepareContractMethodInvokeGeneric(chain *Blockchain, sysfee int64,
|
||||||
hash util.Uint160, method string, isCommittee bool, args ...interface{}) (*transaction.Transaction, error) {
|
hash util.Uint160, method string, signer interface{}, args ...interface{}) (*transaction.Transaction, error) {
|
||||||
w := io.NewBufBinWriter()
|
w := io.NewBufBinWriter()
|
||||||
emit.AppCall(w.BinWriter, hash, method, callflag.All, args...)
|
emit.AppCall(w.BinWriter, hash, method, callflag.All, args...)
|
||||||
if w.Err != nil {
|
if w.Err != nil {
|
||||||
|
@ -444,19 +446,52 @@ func prepareContractMethodInvokeGeneric(chain *Blockchain, sysfee int64,
|
||||||
tx := transaction.New(chain.GetConfig().Magic, script, sysfee)
|
tx := transaction.New(chain.GetConfig().Magic, script, sysfee)
|
||||||
tx.ValidUntilBlock = chain.blockHeight + 1
|
tx.ValidUntilBlock = chain.blockHeight + 1
|
||||||
var err error
|
var err error
|
||||||
if isCommittee {
|
switch s := signer.(type) {
|
||||||
|
case bool:
|
||||||
|
if s {
|
||||||
addSigners(testchain.CommitteeScriptHash(), tx)
|
addSigners(testchain.CommitteeScriptHash(), tx)
|
||||||
err = testchain.SignTxCommittee(chain, tx)
|
err = testchain.SignTxCommittee(chain, tx)
|
||||||
} else {
|
} else {
|
||||||
addSigners(neoOwner, tx)
|
addSigners(neoOwner, tx)
|
||||||
err = testchain.SignTx(chain, tx)
|
err = testchain.SignTx(chain, tx)
|
||||||
}
|
}
|
||||||
|
case *wallet.Account:
|
||||||
|
signTxWithAccounts(chain, tx, s)
|
||||||
|
case []*wallet.Account:
|
||||||
|
signTxWithAccounts(chain, tx, s...)
|
||||||
|
default:
|
||||||
|
panic("invalid signer")
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return tx, nil
|
return tx, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func signTxWithAccounts(chain *Blockchain, tx *transaction.Transaction, accs ...*wallet.Account) {
|
||||||
|
scope := transaction.CalledByEntry
|
||||||
|
for _, acc := range accs {
|
||||||
|
tx.Signers = append(tx.Signers, transaction.Signer{
|
||||||
|
Account: acc.PrivateKey().GetScriptHash(),
|
||||||
|
Scopes: scope,
|
||||||
|
})
|
||||||
|
scope = transaction.Global
|
||||||
|
}
|
||||||
|
size := io.GetVarSize(tx)
|
||||||
|
for _, acc := range accs {
|
||||||
|
netFee, sizeDelta := fee.Calculate(chain.GetBaseExecFee(), acc.Contract.Script)
|
||||||
|
size += sizeDelta
|
||||||
|
tx.NetworkFee += netFee
|
||||||
|
}
|
||||||
|
tx.NetworkFee += int64(size) * chain.FeePerByte()
|
||||||
|
|
||||||
|
for _, acc := range accs {
|
||||||
|
if err := acc.SignTx(tx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func prepareContractMethodInvoke(chain *Blockchain, sysfee int64,
|
func prepareContractMethodInvoke(chain *Blockchain, sysfee int64,
|
||||||
hash util.Uint160, method string, args ...interface{}) (*transaction.Transaction, error) {
|
hash util.Uint160, method string, args ...interface{}) (*transaction.Transaction, error) {
|
||||||
return prepareContractMethodInvokeGeneric(chain, sysfee, hash,
|
return prepareContractMethodInvokeGeneric(chain, sysfee, hash,
|
||||||
|
@ -486,9 +521,9 @@ func invokeContractMethod(chain *Blockchain, sysfee int64, hash util.Uint160, me
|
||||||
}
|
}
|
||||||
|
|
||||||
func invokeContractMethodGeneric(chain *Blockchain, sysfee int64, hash util.Uint160, method string,
|
func invokeContractMethodGeneric(chain *Blockchain, sysfee int64, hash util.Uint160, method string,
|
||||||
isCommittee bool, args ...interface{}) (*state.AppExecResult, error) {
|
signer interface{}, args ...interface{}) (*state.AppExecResult, error) {
|
||||||
tx, err := prepareContractMethodInvokeGeneric(chain, sysfee, hash,
|
tx, err := prepareContractMethodInvokeGeneric(chain, sysfee, hash,
|
||||||
method, isCommittee, args...)
|
method, signer, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -509,26 +544,7 @@ func invokeContractMethodBy(t *testing.T, chain *Blockchain, signer *wallet.Acco
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, vm.HaltState, res[0].VMState)
|
require.Equal(t, vm.HaltState, res[0].VMState)
|
||||||
require.Equal(t, 0, len(res[0].Stack))
|
require.Equal(t, 0, len(res[0].Stack))
|
||||||
|
return invokeContractMethodGeneric(chain, sysfee, hash, method, signer, args...)
|
||||||
w := io.NewBufBinWriter()
|
|
||||||
emit.AppCall(w.BinWriter, hash, method, callflag.All, args...)
|
|
||||||
if w.Err != nil {
|
|
||||||
return nil, w.Err
|
|
||||||
}
|
|
||||||
script := w.Bytes()
|
|
||||||
tx := transaction.New(chain.GetConfig().Magic, script, sysfee)
|
|
||||||
tx.ValidUntilBlock = chain.blockHeight + 1
|
|
||||||
tx.Signers = []transaction.Signer{
|
|
||||||
{Account: signer.PrivateKey().PublicKey().GetScriptHash()},
|
|
||||||
}
|
|
||||||
tx.NetworkFee = netfee
|
|
||||||
err = signer.SignTx(tx)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.NoError(t, chain.AddBlock(chain.newBlock(tx)))
|
|
||||||
|
|
||||||
res, err = chain.GetAppExecResults(tx.Hash(), trigger.Application)
|
|
||||||
require.NoError(t, err)
|
|
||||||
return &res[0], nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func transferTokenFromMultisigAccount(t *testing.T, chain *Blockchain, to, tokenHash util.Uint160, amount int64, additionalArgs ...interface{}) *transaction.Transaction {
|
func transferTokenFromMultisigAccount(t *testing.T, chain *Blockchain, to, tokenHash util.Uint160, amount int64, additionalArgs ...interface{}) *transaction.Transaction {
|
||||||
|
|
Loading…
Reference in a new issue