简体   繁体   English

用于签署交易的 Litecore-lib 函数无法正常工作

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

I'm trying to create a transaction on litecoin testnet using litecore-lib package.我正在尝试使用 litecore-lib 包在莱特币测试网上创建交易。 I attach the snippet of the code.我附上代码片段。 I print every line to analyze how the transaction is being built.我打印每一行来分析交易是如何构建的。 No changes when calling the 'sign' method.调用“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());

And below I attach the output.下面我附上输出。 Please compare the tx string before and after signing: they are the same!请比较签名前后的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

Make sure you set the correct script for your utxo.确保为 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