github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/rpcclient/notary/accounts.go (about)

     1  package notary
     2  
     3  import (
     4  	"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
     5  	"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
     6  	"github.com/nspcc-dev/neo-go/pkg/encoding/address"
     7  	"github.com/nspcc-dev/neo-go/pkg/smartcontract"
     8  	"github.com/nspcc-dev/neo-go/pkg/util"
     9  	"github.com/nspcc-dev/neo-go/pkg/wallet"
    10  )
    11  
    12  // FakeSimpleAccount creates a fake account belonging to the given public key.
    13  // It uses a simple signature contract and this account has SignTx that
    14  // returns no error, but at the same time adds no signature (it obviously can't
    15  // do that, so CanSign() returns false for it). Use this account for Actor when
    16  // simple signatures are needed to be collected.
    17  func FakeSimpleAccount(k *keys.PublicKey) *wallet.Account {
    18  	return &wallet.Account{
    19  		Address: k.Address(),
    20  		Contract: &wallet.Contract{
    21  			Script: k.GetVerificationScript(),
    22  		},
    23  	}
    24  }
    25  
    26  // FakeMultisigAccount creates a fake account belonging to the given "m out of
    27  // len(pkeys)" account for the given set of keys. The account returned has SignTx
    28  // that returns no error, but at the same time adds no signatures (it can't
    29  // do that, so CanSign() returns false for it). Use this account for Actor when
    30  // multisignature account needs to be added into a notary transaction, but you
    31  // have no keys at all for it (if you have at least one (which usually is the
    32  // case) ordinary multisig account works fine already).
    33  func FakeMultisigAccount(m int, pkeys keys.PublicKeys) (*wallet.Account, error) {
    34  	script, err := smartcontract.CreateMultiSigRedeemScript(m, pkeys)
    35  	if err != nil {
    36  		return nil, err
    37  	}
    38  	return &wallet.Account{
    39  		Address: address.Uint160ToString(hash.Hash160(script)),
    40  		Contract: &wallet.Contract{
    41  			Script: script,
    42  		},
    43  	}, nil
    44  }
    45  
    46  // FakeContractAccount creates a fake account belonging to some deployed contract.
    47  // SignTx can be called on this account with no error, but at the same time it
    48  // adds no signature or other data into the invocation script (it obviously can't
    49  // do that, so CanSign() returns false for it). Use this account for Actor when
    50  // one of the signers is a contract and it doesn't need a signature or you can
    51  // provide it externally.
    52  func FakeContractAccount(hash util.Uint160) *wallet.Account {
    53  	return &wallet.Account{
    54  		Address: address.Uint160ToString(hash),
    55  		Contract: &wallet.Contract{
    56  			Deployed: true,
    57  		},
    58  	}
    59  }