-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
when i use p2sh address call brc20 commit, i got raw transaction, but when i boardcast it to network, i got
mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element)
there is my code
var privateKeyHex =
"2f609a828ce21a2d8dc6a0a53190f0b059203f6557104960bb7e2a5c015e2daa";
var utxoList = [
UTXO(
txId:
"2ca801f84d9979663e85b641c359f7c7e08941a8827ec9576c5ca77578f365d4",
index: 1,
amount: "99996992")
];
var fromAddress = "2N3ETqqmibtVU8Zj1S6ohQqL46pf1hKRojw";
var toAddress = "2N3ETqqmibtVU8Zj1S6ohQqL46pf1hKRojw";
var utxos = UTXOList(data: utxoList);
var minerFee = btcClient.calculateBrc20CommitMinerFee(
fromAddress, toAddress, 1, utxos, "2");
Log.d("minerFee: ${minerFee}");
var raw = btcClient.signBrc20Commit(fromAddress, toAddress, privateKeyHex,
brc20Ticker, brc20Amount, 1, utxos, brcInscribeAmount, minerFee);
Log.d("commit raw: ${hex.encode(raw.encoded)}");
----
Bitcoin.SigningOutput signBrc20Commit(
String fromAddress,
String toAddress,
String privateKeyHex,
String brc20Ticker,
String brc20Amount,
int coinType,
UTXOList utxos,
int brcInscribeAmount,
int minerFee) {
var privateKey = PrivateKey.createWithData(privateKeyHex.toUint8List());
var publicKey = privateKey.getPublicKeySecp256k1(true);
var addressType = detectAddressType(fromAddress, coinType);
// generate input
var input = Bitcoin.SigningInput(
isItBrcOperation: true,
privateKey: [privateKeyHex.toUint8List()],
amount: $fixnum.Int64(brcInscribeAmount));
if (addressType == P2SH) {
input.scripts.addAll(
generateSigScriptForP2SH(privateKey.getPublicKeySecp256k1(true)));
}
// generate normal utxo
UTXOSummary summary = _generateUtxoPramater(fromAddress, utxos, coinType);
input.utxo.addAll(summary.unspentTransactions);
// change amount
var changeAmount = summary.totalAmount - minerFee - brcInscribeAmount;
// make inscribe
var outputInscribe = BitcoinScript.buildBRC20InscribeTransfer(
brc20Ticker, brc20Amount, publicKey.data());
var outputInscribeProto =
Bitcoin.TransactionOutput.fromBuffer(outputInscribe.data());
// generate out put
var utxoPlan0 = Bitcoin.UnspentTransaction(
amount: $fixnum.Int64(brcInscribeAmount),
script: outputInscribeProto.script,
variant: TransactionVariant.BRC20TRANSFER);
// change out put
var utxoPlan1 = Bitcoin.UnspentTransaction(
script: BitcoinScript.lockScriptForAddress(fromAddress, coinType)
.data()
.toList(),
amount: $fixnum.Int64(changeAmount));
// make transaction plan
var plan = Bitcoin.TransactionPlan(utxos: [utxoPlan0, utxoPlan1]);
input.plan = plan;
// sign transaction
var signed = AnySigner.sign(input.writeToBuffer(), coinType);
var signingOutput = Bitcoin.SigningOutput.fromBuffer(signed);
return signingOutput;
}
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working