コード例 #1
0
#
# 2. Create an alternate peg from testnet to Liquid, using asset issuance and
#    destruction.
#
# 3. Implement a round-robin blocksigner protocol, where each signer takes a turn
#    proposing blocks for the others to sign.
#

print("")
print("8. Raw transaction demo")
# RAW API

# Let's create a basic transaction using the raw api, blind it, sign, and send

# Create a transaction with a single destination output to other wallet.
rawtx = e1.createrawtransaction([], [{e2.getnewaddress(): 100}])
# Biggest difference compared to Bitcoin is that we have explicit fee outputs,
# which may be set in `createrawtransaction`. These will be added or adjusted
# 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.
コード例 #2
0
#
# 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