当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Bitcoin importmulti用法及代码示例


比特币(Bitcoin) RPC Wallet API中importmulti的用法及代码示例。

用法:

importmulti "requests" ( "options" )

导入地址/脚本(使用私钥或公钥,赎回脚本(P2SH)),可以选择从导入脚本的最早创建时间开始重新扫描区块链。需要新的钱包备份。

如果导入的地址/脚本没有从该地址花费的所有私钥,那么它将是仅监视的。在这种情况下,必须将‘watchonly’选项设置为true,否则将返回警告。

相反,如果提供了所有私钥并且地址/脚本可用,则watchonly选项必须设置为false,否则将返回警告。

注意:如果重新扫描为true,则此调用可能需要一个多小时才能完成,在此期间,其他rpc调用可能会报告已导入的 key ,地址或脚本存在,但相关事务仍然丢失。

参数1 - requests

类型:json数组,必需

要导入的数据

[
  {                                                            (json object)
    "desc": "str",                                             (string) Descriptor to import. If using descriptor, do not also provide address/scriptPubKey, scripts, or pubkeys
    "scriptPubKey": "<script>" | { "address":"<address>" },    (string / json, required) Type of scriptPubKey (string for script, json for address). Should not be provided if using a descriptor
    "timestamp": timestamp | "now",                            (integer / string, required) Creation time of the key in seconds since epoch (Jan 1 1970 GMT),
                                                               or the string "now" to substitute the current synced blockchain time. The timestamp of the oldest
                                                               key will determine how far back blockchain rescans need to begin for missing wallet transactions.
                                                               "now" can be specified to bypass scanning, for keys which are known to never have been used, and
                                                               0 can be specified to scan the entire blockchain. Blocks up to 2 hours before the earliest key
                                                               creation time of all keys being imported by the importmulti call will be scanned.
    "redeemscript": "str",                                     (string) Allowed only if the scriptPubKey is a P2SH or P2SH-P2WSH address/scriptPubKey
    "witnessscript": "str",                                    (string) Allowed only if the scriptPubKey is a P2SH-P2WSH or P2WSH address/scriptPubKey
    "pubkeys": [                                               (json array, optional, default=empty array) Array of strings giving pubkeys to import. They must occur in P2PKH or P2WPKH scripts. They are not required when the private key is also provided (see the "keys" argument).
      "pubKey",                                                (string)
      ...
    ],
    "keys": [                                                  (json array, optional, default=empty array) Array of strings giving private keys to import. The corresponding public keys must occur in the output or redeemscript.
      "key",                                                   (string)
      ...
    ],
    "range": n or [n,n],                                       (numeric or array) If a ranged descriptor is used, this specifies the end or the range (in the form [begin,end]) to import
    "internal": bool,                                          (boolean, optional, default=false) Stating whether matching outputs should be treated as not incoming payments (also known as change)
    "watchonly": bool,                                         (boolean, optional, default=false) Stating whether matching outputs should be considered watchonly.
    "label": "str",                                            (string, optional, default='') Label to assign to the address, only allowed with internal=false
    "keypool": bool,                                           (boolean, optional, default=false) Stating whether imported public keys should be added to the keypool for when users request new addresses. Only allowed when wallet private keys are disabled
  }
]

参数2 - options

类型:json对象,可选

{
  "rescan": bool,                                              (boolean, optional, default=true) Stating if should rescan the blockchain after all imports
}

返回结果

Response is an array with the same size as the input that has the execution result :

示例

bitcoin-cli importmulti '[{ "scriptPubKey": { "address": "<my address>" }, "timestamp":1455191478 }, { "scriptPubKey": { "address": "<my 2nd address>" }, "label": "example 2", "timestamp": 1455191480 }]'
bitcoin-cli importmulti '[{ "scriptPubKey": { "address": "<my address>" }, "timestamp":1455191478 }]' '{ "rescan": false}'

相关用法


注:本文由纯净天空筛选整理自bitcoin.org大神的英文原创作品 Bitcoin importmulti。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。