當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。