跳到主要内容

Util 命令

Util命令提供一些校验交易,签名,以及校验签名的工具。

可以使用mvc-cli help command来查看具体命令的使用方法。JsonRpc调用方法在示例中。

命令列表

命令列表如下(从文档右侧边框选取对应的命令进行查看):

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

clearinvalidtransactions

清除无效交易。

clearinvalidtransactions

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

createmultisig

创建多重签名地址。

参数:

  • 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

使用私钥对消息进行签名。

参数:

  • 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

校验地址编码是否合法。

参数:

  • 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

校验消息签名。

参数:

  • 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

校验脚本能否正确解锁。

参数:

  • 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/