Util

Tools for validating transactions, signing, and verifying signatures.

You can use mvc-cli help command to view the usage of specific commands. The JsonRpc call method is in the example.

Commands

== Util ==
clearinvalidtransactions
createmultisig nrequired ["key",...]
signmessagewithprivkey "privkey" "message"
validateaddress "address"
verifymessage "address" "signature" "message"
verifyscript <scripts> [<stopOnFirstInvalid> [<totalTimeout>]]

clearinvalidtransactions

Deletes stored invalid transactions.

clearinvalidtransactions

Deletes stored invalid transactions.
Result: number of bytes freed.

createmultisig

Creates a multi-signature address with n signature of m keys required.

Param:

  • nrequired (numeric, required)

  • keys (array, required)

createmultisig nrequired ["key",...]

Creates a multi-signature address with n signature of m keys required.
It returns a json object with the address and redeemScript.

Arguments:
1. nrequired      (numeric, required) The number of required signatures out of the n keys or addresses.
2. "keys"       (string, required) A json array of keys which are mvc addresses or hex-encoded public keys
     [
       "key"    (string) mvc address or hex-encoded public key
       ,...
     ]

Result:
{
  "address":"multisigaddress",  (string) The value of the new multisig address.
  "redeemScript":"script"       (string) The string value of the hex-encoded redemption script.
}

Examples:

Create a multisig address from 2 addresses
> mvc-cli createmultisig 2 "[\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\",\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\"]"

As a json rpc call
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "createmultisig", "params": [2, ["16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5","171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV"]] }' -H 'content-type: text/plain;' http://127.0.0.1:9882/

signmessagewithprivkey

Sign a message with the private key of an address

Param:

  • privkey (string, required)

  • message (string, required)

signmessagewithprivkey "privkey" "message"

Sign a message with the private key of an address

Arguments:
1. "privkey"         (string, required) The private key to sign the message with.
2. "message"         (string, required) The message to create a signature of.

Result:
"signature"          (string) The signature of the message encoded in base 64

Examples:

Create the signature
> mvc-cli signmessagewithprivkey "privkey" "my message"

Verify the signature
> mvc-cli verifymessage "1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX" "signature" "my message"

As json rpc
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "signmessagewithprivkey", "params": ["privkey", "my message"] }' -H 'content-type: text/plain;' http://127.0.0.1:9882/

validateaddress

Return information about the given mvc address.

Param:

  • address (string, required)

validateaddress "address"

Return information about the given mvc address.

Arguments:
1. "address"     (string, required) The mvc address to validate

Result:
{
  "isvalid" : true|false,       (boolean) If the address is valid or not. If not, this is the only property returned.
  "address" : "address", (string) The mvc address validated
  "scriptPubKey" : "hex",       (string) The hex encoded scriptPubKey generated by the address
  "ismine" : true|false,        (boolean) If the address is yours or not
  "iswatchonly" : true|false,   (boolean) If the address is watchonly
  "isscript" : true|false,      (boolean) If the key is a script
  "pubkey" : "publickeyhex",    (string) The hex value of the raw public key
  "iscompressed" : true|false,  (boolean) If the address is compressed
  "account" : "account"         (string) DEPRECATED. The account associated with the address, "" is the default account
  "timestamp" : timestamp,        (number, optional) The creation time of the key if available in seconds since epoch (Jan 1 1970 GMT)
  "hdkeypath" : "keypath"       (string, optional) The HD keypath if the key is HD and available
  "hdmasterkeyid" : "<hash160>" (string, optional) The Hash160 of the HD master pubkey
}

Examples:
> mvc-cli validateaddress "1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc"
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "validateaddress", "params": ["1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc"] }' -H 'content-type: text/plain;' http://127.0.0.1:9882/

verifymessage

Verify a signed message

Param:

  • address (string, required) 地址。

  • signature (string, required) 签名。

  • message (string, required) 消息。

verifymessage "address" "signature" "message"

Verify a signed message

Arguments:
1. "address"         (string, required) The mvc address to use for the signature.
2. "signature"       (string, required) The signature provided by the signer in base 64 encoding (see signmessage).
3. "message"         (string, required) The message that was signed.

Result:
true|false   (boolean) If the signature is verified or not.

Examples:

Unlock the wallet for 30 seconds
> mvc-cli walletpassphrase "mypassphrase" 30

Create the signature
> mvc-cli signmessage "1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX" "my message"

Verify the signature
> mvc-cli verifymessage "1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX" "signature" "my message"

As json rpc
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "verifymessage", "params": ["1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX", "signature", "my message"] }' -H 'content-type: text/plain;' http://127.0.0.1:9882/

verifyscript

Verify a script in given transactions.

Param:

  • scripts (string, required)

  • stopOnFirstInvalid (boolean, optional)

  • totalTimeout (numeric, optional)

verifyscript <scripts> [<stopOnFirstInvalid> [<totalTimeout>]]

Verify a script in given transactions.

Script to be verified is defined by unlock script in n-th input of specified transaction and lock script in spent transaction output.

Script verification in general depends on node configuration and state:
  - Node configuration defines script related limits and policies.
  - Block height is needed to obtain values of script verification flags (e.g. BIPs, genesis...).
  - UTXO database and mempool are needed to get TXO providing the lock script.

Limits and policies specified in node configuration always apply and may affect script verification (e.g. maxscriptsizepolicy, maxstdtxvalidationduration ...).
Dependency on node state can be avoided by explicitly providing required data.

Arguments:
  1. scripts (array, required)
        JSON array specifying scripts that will be verified.
        [
          {
            # (required) Hex-string of transaction containing unlock script (input) to be verified
            tx: <string>,

            # (required) Input of the transaction providing the unlock script to be verified
            n: <integer>,

            # (optional) Bit field providing script verification flags.
            # If not specified, flags are defined by prevblockhash and txo.height.
            # Script flags are defined in source file script_flags.h.
            flags: <integer>,

            # (optional) If true, actual value of flags used to verify script is included in verification result object.
            reportflags: <boolean>,

            # (optional) Hash of parent of the block containing the transaction tx (default: current tip)
            # Used to obtain script verification flags. Only allowed if flags is not present.
            prevblockhash: <string>,

            # (optional) Data for transaction output spent by the n-th input.
            # By default it is obtained from current UTXO database or mempool using n-th input of transaction.
            txo: {
              # (required) Hex-string of the lock script
              lock: <string>,

              # (required) Value of transaction output (in satoshi)
              value: <integer>,

              # Height at which this transaction output was created (-1=mempool height)
              # Used to obtain script verification flags that depend on height of TXO.
              # If flags is present, this is optional and overrides the value in flags.
              # If flags is not present, this is required.
              height: <integer>
            }
          }, ...
        ]

  2. stopOnFirstInvalid (boolean, optional default=true)
        If true and an invalid script is encountered, subsequent scripts will not be verified.
        If false, all scripts are verified.

  3. totalTimeout (integer, optional default=100)
        Execution will stop if total script verification time exceeds this value (in ms).
        Note that actual timeout may be lower if node does not allow script verification to take this long.

Result:
  JSON array containing verification results.
  It has the same number of elements as <scripts> argument with each element providing verification result of the corresponding script.
  [
    {
      result: <string>,
      description: <string>  # (optional)
      flags: <integer> # (optional)
    }, ...
  ]
  Possible values for "result":
    "ok"      : Script verification succeeded.
    "error"   : Script verification failed. Script was determined to be invalid. More info may be provided in "description".
    "timeout" : Script verification was aborted because total allowed script verification time was exceeded or because verification of this script took longer than permitted in node configuration (maxstdtxvalidationduration).
    "skipped" : Script verification was skipped. This could happen because total allowed script verification time was exceeded or because previous script verification failed and stopOnFirstInvalid was specified.

Examples:
> mvc-cli verifyscript "[{\"tx\": \"<txhex>\", \"n\": 0}]" true 100
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "verifyscript", "params": [[{"tx": "<txhex>", "n": 0}], true, 100] }' -H 'content-type: text/plain;' http://127.0.0.1:9882/