# by `fundrawtransaction` to make the transaction balance. rawtx2 = e1.createrawtransaction( [], [{ e2.getnewaddress(): 100 }, { e1.getnewaddress(): 5 }, { "fee": Decimal("0.1") }], ) # Fee outputs are unblinded, with a scriptPubKey of "". On Elements, empty # scriptPubKeys are unspendable. # Next we can fund the transaction (and replaces fee with something more appropriate) fundedtx = e1.fundrawtransaction(rawtx2) # Blind blindedtx = e1.blindrawtransaction(fundedtx["hex"]) # In some cases, such as when there is one blinded output but no blinded inputs, # blinding will fail. The `ignoreblindfails` option to `blindrawtransaction` may # be set, in which case the transaction will "successfully" not be blinded. # # To unconditionally blind a transaction, ensure that it has 2 or more outputs, # which will ensure that blinding is (a) useful and (b) mathematically possible. # Sign signedtx = e1.signrawtransactionwithwallet(blindedtx) # And send
# This step is fairly complicated and will be significantly simplified by # future RPC improvements. # # First, each party generates a new address print ("2a. Exchange addresses") alice_addr = alice.getnewaddress() carol_addr = carol.getnewaddress() print (" Alice: ", alice_addr) print (" Carol: ", carol_addr) # Then they each create and fund (but don't sign!) partial transactions # which simply send the assets to each other. print ("2b. Exchange partial transaction data") raw_tx_a = alice.createrawtransaction(outputs=[{carol_addr: 2500}]) funded_a = alice.fundrawtransaction(raw_tx_a)['hex'] raw_tx_c = carol.createrawtransaction(outputs=[{alice_addr: 1000, "asset": asset_ALT}]) funded_c = carol.fundrawtransaction(raw_tx_c)['hex'] # Each party cross-checks the other's transaction print ("2c. Check partial transactions") decoded_a = carol.decoderawtransaction(funded_a) carol_spk = carol.validateaddress(carol_addr)['scriptPubKey'] found_my_output = False feerate = None for output in decoded_a["vout"]: if output["scriptPubKey"]["type"] == "fee" and output["asset"] == asset_BTC: # Feerate multiplier is 10^8 (btc->sat) / 10^3 (bytes->kb) to get a value in sat/kb feerate = 100000.0 * float(output["value"]) / decoded_a["vsize"]