簡體   English   中英

用於簽署交易的 Litecore-lib 函數無法正常工作

[英]Litecore-lib function to sign transactions does not work propertly

我正在嘗試使用 litecore-lib 包在萊特幣測試網上創建交易。 我附上代碼片段。 我打印每一行來分析交易是如何構建的。 調用“sign”方法時沒有變化。

const litecore = require('litecore-lib');

var wif = 'cRkP6k8dDab1PDg2SvS8mbKMSxCSJfDFg6hibkKGmrfaU4xaCi9R';
var privateKey = new litecore.PrivateKey(wif, 'testnet');
var address = privateKey.toAddress('testnet');

console.log("Private key:", privateKey.toString());
console.log("WIF Private key:", privateKey.toWIF());
console.log("Address: ", address.toString()); //mmQQ2Mz1UGWtos6fGmM6sTg69itJmvxW9h



var utxo = {
  "txId" : "d095e2e921ac6f0ed5f7f886529c14d662b82feb35e1afa0051a8328855ecdf8",
  "outputIndex" : 0,
  "address" : address.toString(),
  "script" : "76a91447862fe165e6121af80d5dde1ecb478ed170565b88ac",
  "satoshis" : 100000,
  "network":'testnet'
};

var transaction = new litecore.Transaction()
console.log("\nTx Created:");
console.log(transaction.toString());

console.log("\nAdd input:");
transaction = transaction.from(utxo)
console.log(transaction.toString());

console.log("\nAdd output:");
transaction = transaction.to('mi1gqn4z9r1sm4XDjrTS8hegEaAMxYGWkW', 98000)
console.log(transaction.toString());

console.log("\nChange:");
transaction = transaction.change(address.toString())
console.log(transaction.toString());

console.log("\nFee:");
transaction = transaction.fee(1100)
console.log(transaction.toString());

console.log("Is fully signed:", transaction.isFullySigned());

console.log("\nSign:");
transaction = transaction.sign(privateKey)
console.log(transaction.toString());

console.log("Is fully signed:", transaction.isFullySigned());

下面我附上輸出。 請比較簽名前后的tx字符串:它們是一樣的!

Private key: 7c54567e49114ffce7c54831f019e07eaf12ab666e2e075afde4699dc3947e96
WIF Private key: cRkP6k8dDab1PDg2SvS8mbKMSxCSJfDFg6hibkKGmrfaU4xaCi9R
Address:  mmQQ2Mz1UGWtos6fGmM6sTg69itJmvxW9h

Tx Created:
01000000000000000000

Add input:
0100000001f8cd5e8528831a05a0afe135eb2fb862d6149c5286f8f7d50e6fac21e9e295d00000000000ffffffff0000000000

Add output:
0100000001f8cd5e8528831a05a0afe135eb2fb862d6149c5286f8f7d50e6fac21e9e295d00000000000ffffffff01d07e0100000000001976a9141b5f6a37c731c1f2e84448c4298352144dadd18088ac00000000

Change:
0100000001f8cd5e8528831a05a0afe135eb2fb862d6149c5286f8f7d50e6fac21e9e295d00000000000ffffffff01d07e0100000000001976a9141b5f6a37c731c1f2e84448c4298352144dadd18088ac00000000

Fee:
0100000001f8cd5e8528831a05a0afe135eb2fb862d6149c5286f8f7d50e6fac21e9e295d00000000000ffffffff02d07e0100000000001976a9141b5f6a37c731c1f2e84448c4298352144dadd18088ac84030000000000001976a9144093522294655efcbfc2bdfdb448682bf3bef69a88ac00000000
Is fully signed: false

Sign:
0100000001f8cd5e8528831a05a0afe135eb2fb862d6149c5286f8f7d50e6fac21e9e295d00000000000ffffffff02d07e0100000000001976a9141b5f6a37c731c1f2e84448c4298352144dadd18088ac84030000000000001976a9144093522294655efcbfc2bdfdb448682bf3bef69a88ac00000000
Is fully signed: false

確保為 utxo 設置了正確的腳本。

var utxo = {
  "txId" : "d095e2e921ac6f0ed5f7f886529c14d662b82feb35e1afa0051a8328855ecdf8",
  "outputIndex" : 0,
  "address" : address.toString(),
  "script" : "76a9144093522294655efcbfc2bdfdb448682bf3bef69a88ac",
  // "script" : "76a91447862fe165e6121af80d5dde1ecb478ed170565b88ac",
  "satoshis" : 100000,
  "network":'testnet'
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM