var metadata = WalletMeta(source: .newIdentity)
metadata.network = Network.testnet
metadata.segWit = .p2wpkh // .p2wpkh means that the derived btc wallet is a SegWit wallet
metadata.name = "MyFirstIdentity"
let (mnemonic, identity) = try Identity.createIdentity(password: TestData.password, metadata: metadata)
let ethereumWallet = identity.wallets[0]
let bitcoinWalelt = identity.wallets[1]
do {
let prvKey = BTCKey(privateKey: (singleUTXOfixture["privateKey"] as! String).tk_dataFromHexString())!
prvKey.isPublicKeyCompressed = true
let utxos: [UTXO] = (singleUTXOfixture["utxos"] as! [[String: Any]]).map { UTXO(raw: $0)! }
let signer = try BTCTransactionSigner(
utxos: utxos,
keys: [prvKey],
amount: singleUTXOfixture["amount"] as! Int64,
fee: singleUTXOfixture["fee"] as! Int64,
toAddress: BTCAddress(string: singleUTXOfixture["to"] as? String)!,
changeAddress: prvKey.addressTestnet!
)
let result = try signer.sign()
print(result.signedTx)
报如下错误:
./bitcoin-cli -testnet sendrawtransaction 0200000000010154cd4795cd351bea42d6844f91b1e362af206225c41d44891bcbaa3f172c92ab0000000017160014e24274f3e210e3fa0a2434eddcb978d5f2a4fad0ffffffff0280969800000000001976a914a096160b67a035f2006590ad003959a94a5743ea88ace5f858000000000017a91471d4f1b975d8f098624fc0350194101d5b890fe6870247304402204e8ab698ba96713377ef0077c4dec56e0929772dab61a8b8754b802d78e654eb022050bbb458744037983d65c6bd7bbc15f11339d09b42d404c7c0a92de185d591c10121031213bee798bfd0be537dbbd65d09f486a062f405978f1cdeed0ee71489f7ed9600000000
error code: -26
error message:
mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element) (code 16)
如下是我创建钱包和发送交易的方式;
var metadata = WalletMeta(source: .newIdentity) metadata.network = Network.testnet metadata.segWit = .p2wpkh // .p2wpkh means that the derived btc wallet is a SegWit wallet metadata.name = "MyFirstIdentity" let (mnemonic, identity) = try Identity.createIdentity(password: TestData.password, metadata: metadata) let ethereumWallet = identity.wallets[0] let bitcoinWalelt = identity.wallets[1]
let singleUTXOfixture: [String: Any] = [ "sign": "0200000000010154cd4795cd351bea42d6844f91b1e362af206225c41d44891bcbaa3f172c92ab0000000017160014e24274f3e210e3fa0a2434eddcb978d5f2a4fad0ffffffff0280969800000000001976a914a096160b67a035f2006590ad003959a94a5743ea88ace5f858000000000017a91471d4f1b975d8f098624fc0350194101d5b890fe6870247304402204e8ab698ba96713377ef0077c4dec56e0929772dab61a8b8754b802d78e654eb022050bbb458744037983d65c6bd7bbc15f11339d09b42d404c7c0a92de185d591c10121031213bee798bfd0be537dbbd65d09f486a062f405978f1cdeed0ee71489f7ed9600000000", "privateKey": "eb6d0ab5d766187ea30e21dd796105d67e632d7339cc2633a24eb07e3e4019ab", "amount": Int64(10000000), "fee": Int64(1691000), "to": "2N7Hp25quccEnEcSVLcNFwWqeFgWEKzLgM3", "changeIdx": 0, "utxos": [ [ "txHash": "ab922c173faacb1b89441dc4256220af62e3b1914f84d642ea1b35cd9547cd54", "vout": 0, "amount": "16000000", "address": "2N6k2rid1c6S7migaoPLMJ7YbywwWBNGtDP", "scriptPubKey": "a914940c6827ce2849f54359e4921164fb8bba475aa587" ], ] ]
报如下错误:
./bitcoin-cli -testnet sendrawtransaction 0200000000010154cd4795cd351bea42d6844f91b1e362af206225c41d44891bcbaa3f172c92ab0000000017160014e24274f3e210e3fa0a2434eddcb978d5f2a4fad0ffffffff0280969800000000001976a914a096160b67a035f2006590ad003959a94a5743ea88ace5f858000000000017a91471d4f1b975d8f098624fc0350194101d5b890fe6870247304402204e8ab698ba96713377ef0077c4dec56e0929772dab61a8b8754b802d78e654eb022050bbb458744037983d65c6bd7bbc15f11339d09b42d404c7c0a92de185d591c10121031213bee798bfd0be537dbbd65d09f486a062f405978f1cdeed0ee71489f7ed9600000000 error code: -26 error message: mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element) (code 16)