You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some minimal help would be appreciated, all I'm trying to do is transfer from bc1xx to bc1xx.
No idea what to do with these, big example mentions 3 alice,bob and contract keys.
spend_key=None # from privkeyBytes parameter ?
btc_contract='?'
I guess branch_condition true is to not to use lock times.
Do we know the numof vBytes in advance to calculate the fee?
This is what I have:
from bitcointx.wallet import CCoinAddress
from bitcointx.core import CMutableTransaction,CTxIn, CTxOut,COutPoint,lx,CTxInWitness
from bitcointx.core.script import SIGHASH_ALL,SIGVERSION_WITNESS_V0, DATA,CScriptWitness,CBitcoinScript
def sweep_bech32_tx(utxos, toAddrStr, privkeyB, feeSat=200):
spend_key=None # from privkeyB parameter ?
btc_contract='?'
in_amount = sum([amntSat for txid,vout_n,amntSat in utxos])
out_amount = in_amount - feeSat
# Create the unsigned transaction.
tx = CMutableTransaction(
vin=[CTxIn(prevout=COutPoint(hash=lx(txid), n=vout_n)) for txid,vout_n,amntSat in utxos],
vout=[CTxOut(nValue=out_amount, scriptPubKey=CCoinAddress(toAddrStr).to_scriptPubKey())]
)
cond = b'\x01' # branch_condition true
# We used P2WSHCoinAddress to create the address that we sent bitcoin to, so we know that we need to use SIGVERSION_WITNESS_V0
sighash = btc_contract.sighash(tx, 0, SIGHASH_ALL, amount=in_amount, sigversion=SIGVERSION_WITNESS_V0)
spend_sig = spend_key.sign(sighash) + bytes([SIGHASH_ALL])
# This is script witness, not script. The condition for OP_IF
# in our script is directly encoded as data in the witness.
# We cannot use OP_TRUE/OP_FALSE here. We use DATA guard is to ensure that.
witness = CScriptWitness([spend_sig, DATA(cond), btc_contract])
# empty scriptSig, because segwit
tx.vin[0].scriptSig = CBitcoinScript([])
# all data to check the spend conditions is in the witness
tx.wit.vtxinwit[0] = CTxInWitness(witness)
# VerifyScript not working
return tx
# inputs: (txid, vout_n, amntSat)
utxos = [
('097fed228b1c4afb9dc8df2ae137e4be5e1c1376541c2db3b1c74a6166e7842b', 0, 178876),
]
tx = sweep_bech32_tx(utxos, toAddrStr='bc1..', privkeyB=bytes.fromhex('11'*32))
print(tx)
Hmm, I guess linking to python-elementstx example was not helpful, because that example uses custom bitcoin scripts and that is not the same as signing simple keypath spending.
Activity
dgpv commentedon Aug 31, 2022
You can look into python-elementstx examples for the code that spends p2wsh address: https://github.com/Simplexum/python-elementstx/blob/4858587d27c9cdc16eb4d1556f95be33e7406abe/examples/confidential-cross-chain-atomic-swap.py#L602-L646
or look into implementation of PartiallySignedTransaction.sign() - it has code that signs various types of inputs.
more example code is of course welcome if you or anyone are willing to create that.
mrx23dot commentedon Aug 31, 2022
Thank you, I will give it a go.
mrx23dot commentedon Sep 3, 2022
Some minimal help would be appreciated, all I'm trying to do is transfer from bc1xx to bc1xx.
No idea what to do with these, big example mentions 3 alice,bob and contract keys.
I guess branch_condition true is to not to use lock times.
Do we know the numof vBytes in advance to calculate the fee?
This is what I have:
dgpv commentedon Sep 5, 2022
Hmm, I guess linking to python-elementstx example was not helpful, because that example uses custom bitcoin scripts and that is not the same as signing simple keypath spending.
You probably better use
PartiallySignedTransaction'ssign()method, you can create psbt fromCTransactionlike in this test code: https://github.com/Simplexum/python-bitcointx/blob/master/bitcointx/tests/test_psbt.py#L401 and then callpsbt.sign(keystore)where keystore is an instance ofKeyStorewhich contains your keys