assertion failed Aborted(Assertion failed: other.hash().size() == 32, a #3903
Replies: 3 comments 1 reply
-
Some one has to correct the size as according to the scanned network and manually input the numbers and the past on the blockchain again to reflect a change it is due to the 33.3 rule in a 12 month 28 day month so the time zone was off it is now corrected but all the values must be enter for me manually Timothy P. KilgoreOn Jun 17, 2024, at 23:22, ***@***.*** wrote:I do not understand what is going wrong:I have the following utxos , that i get from a freeware api , then i use those utxos to create outputs, but i keep getting assertion errorAborted(Assertion failed: other.hash().size() == 32, at: /home/runner/work/wallet-core-releases/wallet-core-releases/src/Bitcoin/OutPoint.h,42,OutPoint)
RuntimeError: Aborted(Assertion failed: other.hash().size() == 32, at: /home/runner/work/wallet-core-releases/wallet-core-releases/src/Bitcoin/OutPoint.h,42,OutPoint)
I have already reversed as and still getting error : #3856 async createAndSignBitcoinTransaction(recipientAddress: string, amountToSend: Decimal) {
if (!this.validateAddress(recipientAddress)){
throw new Error("Invalid recipient Address");
}
const { AnySigner, BitcoinScript, PrivateKey, HexCoding, Hash, CoinType } = this.walletCore;
const privateKey = this.wallet.getKeyForCoin(CoinType.bitcoin);
const privateKeyData = privateKey.data();
const publicKey = privateKey.getPublicKeySecp256k1(true);
const pubKeyHash = Hash.ripemd(Hash.sha256(publicKey.data()));
const p2wpkh = BitcoinScript.buildPayToWitnessPubkeyHash(pubKeyHash);
// Fetch UTXOs for the wallet address
const walletAddress = this.wallet.getAddressForCoin(CoinType.bitcoin);
interface UnspentOutput {
tx_hash_big_endian: string;
tx_hash: string;
tx_output_n: number;
script: string;
value: number;
value_hex: string;
confirmations: number;
tx_index: number;
}
interface UnspentOutputsResponse {
notice: string;
unspent_outputs: UnspentOutput[];
}
const utxos = await fetch(`https://blockchain.info/unspent?active=${walletAddress}`)
.then(response => response.json() as Promise<UnspentOutputsResponse> )
.then(data => data.unspent_outputs);
if (!utxos || utxos.length === 0) {
throw new Error("No UTXOs found for the wallet address.");
}
// Calculate the total amount of UTXOs and the required miner fee
const totalUtxoAmount = new Decimal(utxos.reduce((sum, utxo) => sum + utxo.value, 0));
const minerFee = await this.calculateFee(); // Set an appropriate fee
const changeAmount = totalUtxoAmount.sub(amountToSend).sub(minerFee);
if (minerFee.isZero()){
throw new Error("Miner fee is zero, script must have stopped");
}
if (changeAmount.lessThan(0)) {
throw new Error("Insufficient funds to cover the amount and miner fee.");
}
const inputs = utxos.map(utxo => TW.Bitcoin.Proto.UnspentTransaction.create({
script: p2wpkh.data(),
amount: Long.fromNumber(utxo.value),
variant: TW.Bitcoin.Proto.TransactionVariant.P2WPKH,
outPoint: TW.Bitcoin.Proto.OutPoint.create({
hash: HexCoding.decode(utxo.tx_hash).reverse(),
index: utxo.tx_output_n,
}),
}));
const recipientScript = BitcoinScript.lockScriptForAddress(recipientAddress, CoinType.bitcoin);
const changeScript = BitcoinScript.buildPayToWitnessPubkeyHash(pubKeyHash);
const amountToSendLong = Long.fromString(amountToSend.toString());
const changeAmountLong = Long.fromString(changeAmount.toString());
const outputs = [
TW.Bitcoin.Proto.UnspentTransaction.create({
script: recipientScript.data(),
amount: amountToSendLong,
variant: TW.Bitcoin.Proto.TransactionVariant.P2WPKH,
}),
TW.Bitcoin.Proto.UnspentTransaction.create({
script: changeScript.data(),
amount: changeAmountLong,
variant: TW.Bitcoin.Proto.TransactionVariant.P2WPKH,
}),
];
const input = TW.Bitcoin.Proto.SigningInput.create({
privateKey: [privateKeyData],
utxo: inputs,
plan: TW.Bitcoin.Proto.TransactionPlan.create({
utxos: outputs,
}),
});
const encoded = TW.Bitcoin.Proto.SigningInput.encode(input).finish();
const outputData = AnySigner.sign(encoded, CoinType.bitcoin);
const output = TW.Bitcoin.Proto.SigningOutput.decode(outputData);
console.log("Signed transaction: ", HexCoding.encode(output.encoded));
console.log("Transaction ID: ", output.transactionId);
return {
signedTransaction: HexCoding.encode(output.encoded),
transactionId: output.transactionId,
};
}
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Timothy P. KilgoreOn Jun 17, 2024, at 03:56, jaspreetonesatoshi ***@***.***> wrote:
I do not understand what is going wrong:
I have the following utxos , that i get from a freeware api , then i use those utxos to create outputs, but i keep getting assertion error
Aborted(Assertion failed: other.hash().size() == 32, at: /home/runner/work/wallet-core-releases/wallet-core-releases/src/Bitcoin/OutPoint.h,42,OutPoint)
RuntimeError: Aborted(Assertion failed: other.hash().size() == 32, at: /home/runner/work/wallet-core-releases/wallet-core-releases/src/Bitcoin/OutPoint.h,42,OutPoint)
I have already reversed as and still getting error : #3856
async createAndSignBitcoinTransaction(recipientAddress: string, amountToSend: Decimal) {
if (!this.validateAddress(recipientAddress)){
throw new Error("Invalid recipient Address");
}
const { AnySigner, BitcoinScript, PrivateKey, HexCoding, Hash, CoinType } = this.walletCore;
const privateKey = this.wallet.getKeyForCoin(CoinType.bitcoin);
const privateKeyData = privateKey.data();
const publicKey = privateKey.getPublicKeySecp256k1(true);
const pubKeyHash = Hash.ripemd(Hash.sha256(publicKey.data()));
const p2wpkh = BitcoinScript.buildPayToWitnessPubkeyHash(pubKeyHash);
// Fetch UTXOs for the wallet address
const walletAddress = this.wallet.getAddressForCoin(CoinType.bitcoin);
interface UnspentOutput {
tx_hash_big_endian: string;
tx_hash: string;
tx_output_n: number;
script: string;
value: number;
value_hex: string;
confirmations: number;
tx_index: number;
}
interface UnspentOutputsResponse {
notice: string;
unspent_outputs: UnspentOutput[];
}
const utxos = await fetch(`https://blockchain.info/unspent?active=${walletAddress}`)
.then(response => response.json() as Promise<UnspentOutputsResponse> )
.then(data => data.unspent_outputs);
if (!utxos || utxos.length === 0) {
throw new Error("No UTXOs found for the wallet address.");
}
// Calculate the total amount of UTXOs and the required miner fee
const totalUtxoAmount = new Decimal(utxos.reduce((sum, utxo) => sum + utxo.value, 0));
const minerFee = await this.calculateFee(); // Set an appropriate fee
const changeAmount = totalUtxoAmount.sub(amountToSend).sub(minerFee);
if (minerFee.isZero()){
throw new Error("Miner fee is zero, script must have stopped");
}
if (changeAmount.lessThan(0)) {
throw new Error("Insufficient funds to cover the amount and miner fee.");
}
const inputs = utxos.map(utxo => TW.Bitcoin.Proto.UnspentTransaction.create({
script: p2wpkh.data(),
amount: Long.fromNumber(utxo.value),
variant: TW.Bitcoin.Proto.TransactionVariant.P2WPKH,
outPoint: TW.Bitcoin.Proto.OutPoint.create({
hash: HexCoding.decode(utxo.tx_hash).reverse(),
index: utxo.tx_output_n,
}),
}));
const recipientScript = BitcoinScript.lockScriptForAddress(recipientAddress, CoinType.bitcoin);
const changeScript = BitcoinScript.buildPayToWitnessPubkeyHash(pubKeyHash);
const amountToSendLong = Long.fromString(amountToSend.toString());
const changeAmountLong = Long.fromString(changeAmount.toString());
const outputs = [
TW.Bitcoin.Proto.UnspentTransaction.create({
script: recipientScript.data(),
amount: amountToSendLong,
variant: TW.Bitcoin.Proto.TransactionVariant.P2WPKH,
}),
TW.Bitcoin.Proto.UnspentTransaction.create({
script: changeScript.data(),
amount: changeAmountLong,
variant: TW.Bitcoin.Proto.TransactionVariant.P2WPKH,
}),
];
const input = TW.Bitcoin.Proto.SigningInput.create({
privateKey: [privateKeyData],
utxo: inputs,
plan: TW.Bitcoin.Proto.TransactionPlan.create({
utxos: outputs,
}),
});
const encoded = TW.Bitcoin.Proto.SigningInput.encode(input).finish();
const outputData = AnySigner.sign(encoded, CoinType.bitcoin);
const output = TW.Bitcoin.Proto.SigningOutput.decode(outputData);
console.log("Signed transaction: ", HexCoding.encode(output.encoded));
console.log("Transaction ID: ", output.transactionId);
return {
signedTransaction: HexCoding.encode(output.encoded),
transactionId: output.transactionId,
};
}
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hi @jaspreetonesatoshi, I think the problem is that you try to specify wallet-core/tests/chains/Bitcoin/TWBitcoinSigningTests.cpp Lines 735 to 819 in b92d1de |
Beta Was this translation helpful? Give feedback.
-
@jaspreetonesatoshi this is the code i'm using to get encoded input. import { initWasm, TW } from '@trustwallet/wallet-core';
export const getEncodedInput = async (inputs: any) => {
const { utxos, fromAddress, outputAmmount, toAddress, feeRate } = inputs
const walletCore = await initWasm()
const utxo = utxos.map(
(utxo: { txid: any; vout: any; value: any; satoshis: number }) => {
return TW.Bitcoin.Proto.UnspentTransaction.create({
outPoint: {
hash: Buffer.from(utxo.txid, 'hex').reverse(),
index: utxo.vout,
sequence: 4294967295, // default sequence
},
amount: new Long(utxo.value),
script: walletCore.BitcoinScript.lockScriptForAddress(
fromAddress,
walletCore.CoinType.bitcoin
).data(),
})
}
)
const txInput = TW.Bitcoin.Proto.SigningInput.create({
hashType: walletCore.BitcoinSigHashType.all.value,
coinType: walletCore.CoinType.bitcoin.value,
amount: new Long(outputAmmount),
toAddress: toAddress,
lockTime: 0,
changeAddress: fromAddress,
utxo: utxo
})
return TW.Bitcoin.Proto.SigningInput.encode(txInput).finish()
} I'm using external signer to sign this transaction. in your case you can sign using private key. |
Beta Was this translation helpful? Give feedback.
-
I do not understand what is going wrong:
I have the following utxos , that i get from a freeware api , then i use those utxos to create outputs, but i keep getting assertion error
I am essentially trying to send BTC to a receivingAddress and i want the changeAddress to be the same as input address,
I have already reversed as and still getting error : #3856
Beta Was this translation helpful? Give feedback.
All reactions