Skip to content

Commit

Permalink
update assets tutorial to support new peg-in format
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Nov 6, 2017
1 parent 6e8e6b2 commit 3ba146d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 35 deletions.
24 changes: 8 additions & 16 deletions contrib/assets_tutorial/assets_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def sync_all(e1, e2):
time.sleep(1)
return


## Preparations

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

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

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

######## WALLET ###########

Expand Down Expand Up @@ -419,12 +417,6 @@ def sync_all(e1, e2):
bitcoin.generate(101)
sync_all(e1, e2)

# We have to lock up some of the funds first. Regtest(what we're running) has all funds as OP_TRUE
# but this is not the case in testnet/production. Doesn't matter where we send it
# inside Bitcoin, this is just a hack to lock some funds up.
# We can immediately grab this output from the mempool on subsequent steps
e1.sendtomainchain(bitcoin.getnewaddress(), 50)

# Now we can actually start pegging in. Examine the pegin address fields
e1.getpeginaddress()
# Changes each time as it's a new sidechain address as well as new "tweak" for the watchmen keys
Expand All @@ -448,7 +440,7 @@ def sync_all(e1, e2):
raw = bitcoin.getrawtransaction(txid)

# Attempt claim!
claimtxid = e1.claimpegin(raw, proof, addrs["sidechain_address"])
claimtxid = e1.claimpegin(raw, proof, addrs["witness_program"])
sync_all(e1, e2)

# Other node should accept to mempool and mine
Expand Down
23 changes: 4 additions & 19 deletions contrib/assets_tutorial/assets_tutorial.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,11 @@ e2-dae
# run the bitcoin node, but it is necessary for the two way peg parts of
# this tutorial.

# Prime the chain, see "immature balance" holds all funds until genesis is mature
e1-cli getwalletinfo

# Mining for now is OP_TRUE
e1-cli generate 101

# Now we have 21M OP_TRUE value
# We have 21M OP_TRUE value in each wallet
# This is useful for testing and non-sidechain applications of Elements
e1-cli getwalletinfo
e2-cli getwalletinfo

# Primed and ready

######## WALLET ###########


Expand Down Expand Up @@ -311,19 +304,11 @@ e2-dae $FEDPEGARG
e1-cli generate 101
b-cli generate 101

# We have to lock up some of the funds first. Regtest(what we're running) has all funds as OP_TRUE
# but this is not the case in testnet/production. Doesn't matter where we send it
# inside Bitcoin, this is just a hack to lock some funds up.
e1-cli sendtomainchain $(b-cli getnewaddress) 50

# Mature the pegout
e1-cli generate 101

# Now we can actually start pegging in. Examine the pegin address fields
e1-cli getpeginaddress
# Changes each time as it's a new sidechain address as well as new "tweak" for the watchmen keys
# mainchain_address : where you send your bitcoin from Bitcoin network
# sidechain_address : where the bitcoin will end up on the sidechain after pegging in
# witness_program: what script will have to be satisfied to spent the peg-in input

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

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

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

0 comments on commit 3ba146d

Please sign in to comment.