Skip to content

Commit 3ba146d

Browse files
committed
update assets tutorial to support new peg-in format
1 parent 6e8e6b2 commit 3ba146d

File tree

2 files changed

+12
-35
lines changed

2 files changed

+12
-35
lines changed

contrib/assets_tutorial/assets_tutorial.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def sync_all(e1, e2):
4646
time.sleep(1)
4747
return
4848

49-
5049
## Preparations
5150

5251
# Make data directories for each daemon
@@ -91,20 +90,19 @@ def sync_all(e1, e2):
9190
# Alternatively, you can set validatepegin=0 in their configs and not
9291
# run the bitcoin node, but it is necessary for fully validating the two way peg.
9392

94-
# At beginning "immature balance" holds all funds until genesis is mature
95-
# Regtest chain starts with 21M elements coins as OP_TRUE which the wallet
96-
# understands. This is useful for testing basic functionality.
97-
# In Elements there is no block subsidy. All 21M output value in a mainnet
98-
# pegged sidechain are locked for pegging.
93+
# Regtest chain starts with 21M bitcoins as OP_TRUE which the wallet
94+
# understands. This is useful for testing basic functionality and for
95+
# blockchains that have no pegging functionality. "Policy" coins are required
96+
# for anti-DoS purposes as well as asset issuance, which consumes inputs for entropy.
97+
# In Elements there is no block subsidy. In a production sidechain it can
98+
# be configured to start with no outputs, necessitating peg-in functionality
99+
# for asset issuance.
99100
e1.getwalletinfo()
100101

101102
# In regtest mining "target" is OP_TRUE since we have not set `-signblockscript` argument
102103
# Generate simply works.
103104
e1.generate(101)
104105
sync_all(e1, e2)
105-
# Now we have 21M OP_TRUE value in each Elements wallet.
106-
e1.getwalletinfo()
107-
e2.getwalletinfo()
108106

109107
######## WALLET ###########
110108

@@ -419,12 +417,6 @@ def sync_all(e1, e2):
419417
bitcoin.generate(101)
420418
sync_all(e1, e2)
421419

422-
# We have to lock up some of the funds first. Regtest(what we're running) has all funds as OP_TRUE
423-
# but this is not the case in testnet/production. Doesn't matter where we send it
424-
# inside Bitcoin, this is just a hack to lock some funds up.
425-
# We can immediately grab this output from the mempool on subsequent steps
426-
e1.sendtomainchain(bitcoin.getnewaddress(), 50)
427-
428420
# Now we can actually start pegging in. Examine the pegin address fields
429421
e1.getpeginaddress()
430422
# Changes each time as it's a new sidechain address as well as new "tweak" for the watchmen keys
@@ -448,7 +440,7 @@ def sync_all(e1, e2):
448440
raw = bitcoin.getrawtransaction(txid)
449441

450442
# Attempt claim!
451-
claimtxid = e1.claimpegin(raw, proof, addrs["sidechain_address"])
443+
claimtxid = e1.claimpegin(raw, proof, addrs["witness_program"])
452444
sync_all(e1, e2)
453445

454446
# Other node should accept to mempool and mine

contrib/assets_tutorial/assets_tutorial.sh

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,11 @@ e2-dae
3939
# run the bitcoin node, but it is necessary for the two way peg parts of
4040
# this tutorial.
4141

42-
# Prime the chain, see "immature balance" holds all funds until genesis is mature
43-
e1-cli getwalletinfo
44-
45-
# Mining for now is OP_TRUE
46-
e1-cli generate 101
47-
48-
# Now we have 21M OP_TRUE value
42+
# We have 21M OP_TRUE value in each wallet
43+
# This is useful for testing and non-sidechain applications of Elements
4944
e1-cli getwalletinfo
5045
e2-cli getwalletinfo
5146

52-
# Primed and ready
53-
5447
######## WALLET ###########
5548

5649

@@ -311,19 +304,11 @@ e2-dae $FEDPEGARG
311304
e1-cli generate 101
312305
b-cli generate 101
313306

314-
# We have to lock up some of the funds first. Regtest(what we're running) has all funds as OP_TRUE
315-
# but this is not the case in testnet/production. Doesn't matter where we send it
316-
# inside Bitcoin, this is just a hack to lock some funds up.
317-
e1-cli sendtomainchain $(b-cli getnewaddress) 50
318-
319-
# Mature the pegout
320-
e1-cli generate 101
321-
322307
# Now we can actually start pegging in. Examine the pegin address fields
323308
e1-cli getpeginaddress
324309
# Changes each time as it's a new sidechain address as well as new "tweak" for the watchmen keys
325310
# mainchain_address : where you send your bitcoin from Bitcoin network
326-
# sidechain_address : where the bitcoin will end up on the sidechain after pegging in
311+
# witness_program: what script will have to be satisfied to spent the peg-in input
327312

328313
# Each call of this takes the pubkeys defined in the config file, adds a random number to them
329314
# that is essetially the hash of the sidechain_address and other information,
@@ -335,7 +320,7 @@ e1-cli getpeginaddress
335320
ADDRS=$(e1-cli getpeginaddress)
336321

337322
MAINCHAIN=$(echo $ADDRS | python3 -c "import sys, json; print(json.load(sys.stdin)['mainchain_address'])")
338-
SIDECHAIN=$(echo $ADDRS | python3 -c "import sys, json; print(json.load(sys.stdin)['sidechain_address'])")
323+
SIDECHAIN=$(echo $ADDRS | python3 -c "import sys, json; print(json.load(sys.stdin)['witness_program'])")
339324

340325
#Send funds to unique watchmen P2SH address
341326
TXID=$(b-cli sendtoaddress $MAINCHAIN 1)

0 commit comments

Comments
 (0)