Comments (4)
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.
from python-bitcointx.
Thank you, I will give it a go.
from python-bitcointx.
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)
from python-bitcointx.
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
's sign()
method, you can create psbt from CTransaction
like in this test code: https://github.com/Simplexum/python-bitcointx/blob/master/bitcointx/tests/test_psbt.py#L401 and then call psbt.sign(keystore)
where keystore is an instance of KeyStore
which contains your keys
from python-bitcointx.
Related Issues (20)
- Can DeserializationValueBoundsError be triggered by a valid tx? HOT 6
- Taproot support HOT 18
- BIP32 test vector 5 should be added to tests and checked HOT 5
- How to handle libsecp256k1 ABI non-guarantees of stability HOT 5
- CPubKey class and invalid pubkeys - should the API be changed ?
- Potential problem with RIPEMD160 removal from newer OpenSSL versions by default HOT 2
- On MacOS-latest, openssl import fails (openssl is used for non-strict sig verification) HOT 1
- Consider adding scriptWitness to CTxIn
- sign-psbt.py example does not support electrum's testnet xpub encoding for p2wsh HOT 3
- libbitcoinconsensus undefined symbol HOT 4
- Use libsecp256k1 v0.2.0? HOT 11
- Incompatibility with OpenSSL 3 HOT 9
- psbt.sign not support pubkey type witness_v1_taproot HOT 1
- CScript.witness_version() returns 0x51 instead of 1 for taproot HOT 13
- Iibbitcoinconsensus is deprecated by Core
- secp256k1 library not found HOT 2
- Consider OP_1NEGATE handling in CScriptOp (as per linked issue from Core) HOT 1
- Issues with configure bitcointx to work with libsecp256k1 HOT 2
- tapInternalKey issue while creating the transaction
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-bitcointx.