Hi everyone,
I’ve updated the Dart SDK and Dart CLI with support for Sporks and HTLC.
I’m requesting community testing to ensure the implementations are accurate and ready for production.
For HTLC-related content, check out:
- @CryptoFish’s C# CLI
- @georgezgeorgez’s go-zenon
- @CryptoFish’s HTLC Scenarios for C# CLI
- BICH DAO’s HTLC Discussion
Below are instructions to get you started, along with scenarios to test some of the new functions in Dart CLI.
Feel free to try the other HTLC functions that aren’t mentioned in this post.
Please let me know if you encounter any issues.
Setting up the environment
Details
-
Follow @CryptoFish’s Windows or Linux tutorials for setting up devnet
- Omit the remaining instructions when you reach “Zenon CLI for .NET” and follow the steps below to test functionality in Dart
-
You may instead use my devnet node if you don’t want to set one up
- Append
--url ws://node.zenon.fun:36998
to all commands - Send me a DM if you need tokens
- Explorer details
- Append
-
git clone -b spork_htlc https://github.com/Sol-Sanctum/znn_cli_dart.git && cd znn_cli_dart
-
Depending on your OS:
- Windows:
make windows
- Linux:
make linux
- Windows:
-
cd build
-
Depending on your OS:
- Windows:
znn-cli.exe
- Linux:
./znn-cli
- Windows:
Setting up wallets
Details
The primary address of Alice is z1qqjnwjjpnue8xmmpanz6csze6tcmtzzdtfsww7
The primary address of Bob is z1qpsjv3wzzuuzdudg7tf6uhvr6sk4ag8me42ua4
Create Alice wallet with password secret
znn-cli wallet.createFromMnemonic "route become dream access impulse price inform obtain engage ski believe awful
absent pig thing vibrant possible exotic flee pepper marble rural fire fancy" secret Alice
Create Bob wallet with password secret
znn-cli wallet.createFromMnemonic "alone emotion announce page spend eager middle lucky frame craft junk artefact upper finger drive corn version slot blade picnic festival wealth critic silver" secret Bob
Fuse Plasma to both addresses
znn-cli plasma.fuse z1qqjnwjjpnue8xmmpanz6csze6tcmtzzdtfsww7 5000 -k Alice
znn-cli plasma.fuse z1qpsjv3wzzuuzdudg7tf6uhvr6sk4ag8me42ua4 5000 -k Alice
Optional - Send Bob some tokens
znn-cli send z1qpsjv3wzzuuzdudg7tf6uhvr6sk4ag8me42ua4 100 ZNN -k Alice
znn-cli send z1qpsjv3wzzuuzdudg7tf6uhvr6sk4ag8me42ua4 100 QSR -k Alice
HTLC Scenarios (Copied from here)
Alice wants to buy something from Bob
Alice wants to buy something from Bob. She will give Bob 1 hour the time to deliver her the goods in exchange for 100 ZNN.
Alice checks her balance to make sure she has enough funds.
znn-cli balance -k Alice
Alice locks 100 ZNN for Bob for 1 hour, generating a random preimage.
Keep the preimage for a future step.
znn-cli htlc.create z1qpsjv3wzzuuzdudg7tf6uhvr6sk4ag8me42ua4 ZNN 100 3600 -k Alice
Example output:
Creating htlc with amount 100.00000000 tZNN using preimage IDPF68R3VjI2vR1HlhbUpvwoW
Can be unlocked by z1qpsjv3wzzuuzdudg7tf6uhvr6sk4ag8me42ua4 with hashlock 4c4b3f1e4ba60c3b35a644a5535375ce6114d4f1369a9b8171ca66f603cd5b79 hashtype 0
Alice makes sure the HTLC is created and the funds have been deducted from her account before notifying Bob.
znn-cli htlc.timeLocked z1qqjnwjjpnue8xmmpanz6csze6tcmtzzdtfsww7
znn-cli balance -k Alice
Alice notifies Bob for him to inspect the HTLC.
znn-cli htlc.hashLocked -k Bob
Bob inspects the HTLC and agrees to the conditions and writes down the HTLC hash id.
Bob has 1 hour the time to do his part of the deal. Once finished, Alice will reveal the pre-image to Bob so that he can unlock the 100 ZNN.
znn-cli htlc.unlock [hash id] [preimage] -k Bob
Bob has unlocked the 100 ZNN which the contract has send to his wallet. Bob needs to receive the unreceived transactions.
znn-cli receiveAll -k Bob
Bob checks his balance to make sure everything is fine.
znn-cli balance -k Bob
Atomic Swapping
Two users want to swap tokens in a trust-less manner.
Alice will send 10 ZNN to Bob; Bob will send 100 QSR to Alice.
For this scenario, Alice will need two terminals and Bob will need one.
- Note: we’re assuming both parties already have these assets and fused QSR for plasma.
- Alice locks 10 ZNN for Bob for 1 hour, generating a random preimage.
znn-cli htlc.create z1qpsjv3wzzuuzdudg7tf6uhvr6sk4ag8me42ua4 ZNN 10 3600 -k Alice
- Save the randomly-generated preimage
- Assuming hashLockType: 0
-
Alice will send Bob the hashLock.
- Doesn’t matter how, Alice sends the hashLock by email, SMS, instant message, etc.
-
Bob receives the hashLock from Alice and locks his 100 QSR using the same hashLock.
znn-cli htlc.create z1qqjnwjjpnue8xmmpanz6csze6tcmtzzdtfsww7 QSR 100 3600 [hashLock] -k Bob
-
Bob confirms that the HTLC was created.
znn-cli htlc.timeLocked z1qpsjv3wzzuuzdudg7tf6uhvr6sk4ag8me42ua4
or
znn-cli htlc.hashLocked z1qqjnwjjpnue8xmmpanz6csze6tcmtzzdtfsww7
-
Bob notes the hltcId and sends it to Alice.
- Note: he merely needs to inform Alice that it’s been created. She can check the details herself (Step 7).
-
Shortly after Step 5, Bob starts monitoring the all HTLCs associated with his address.
znn-cli htlc.monitorAll -k Bob
-
Alice confirms that Bob has configured the HTLC with the correct hashLock.
znn-cli htlc.timeLocked z1qpsjv3wzzuuzdudg7tf6uhvr6sk4ag8me42ua4
or
znn-cli htlc.hashLocked z1qqjnwjjpnue8xmmpanz6csze6tcmtzzdtfsww7
-
For the sake of this demo, Alice decides to monitor all HTLCs associated with her address, as well.
In Terminal 1:
znn-cli htlc.monitorAll -k Alice
-
Alice is ready to unlock Bob’s funds
In Terminal 2:
znn-cli htlc.unlock [Bob's htlcId] [preimage] -k Alice
Alice’s Terminal 2: htlc is unlocked, funds ready to be received.
Alice’s Terminal 1: after a few momentums, Bob will discover the preimage, unlock Alice’s HTLC automatically, and Alice will see a confirmation of that result
Bob’s Terminal: Bob will discover the preimage and unlock Alice’s HTLC automatically
Both parties need to run znn-cli receiveAll -k [keystore]
to receive their funds.
Alice did not need to trust that Bob had the funds; they were locked in escrow with a hashLock that she could unlock.
Bob did not need to trust that Alice had the funds; they were locked in escrow before he submitted his transaction.
Sporks
High level process
- A new feature is implemented in go-zenon, tested in devnet, and is ready to be deployed to mainnet.
- The owner of the spork address creates a new spork, signaling to network participants that a soft-fork is potentially going to occur.
- The devs add the spork’s hash id to go-zenon and release the updated code to users
- After most network participants have adopted the new code, the owner of the spork address activates the spork, disabling any nodes that did not install the new code.
Scenario
A new feature is being deployed! We need to create and activate a spork in order for the feature to go live.
Note: we will need to make a few changes in order to achieve this since we do not control the spork address.
For this scenario, you will setup your own devnet.
-
Follow @CryptoFish’s Windows or Linux tutorials but also do the following:
- Before
make znnd
Edit this file in your local repository:
Comment theblock.Address
checks at lines 34 and 97//if block.Address != *types.SporkAddress { // return constants.ErrPermissionDenied //}
- Omit the remaining instructions when you reach “Zenon CLI for .NET”
- Before
-
git clone -b spork_htlc https://github.com/Sol-Sanctum/znn_cli_dart.git && cd znn_cli_dart
-
Depending on your OS:
- Windows:
make windows
- Linux:
make linux
- Windows:
-
cd build
-
Depending on your OS:
- Windows:
znn-cli.exe
- Linux:
znn-cli
- Windows:
-
Display a list of sporks on the network
znn-cli spork.list
-
Create a new “Example-spork” spork
znn-cli spork.create "Example-spork" "Acta Non Verba" -k Alice
-
Save the new spork’s
Hash
for the next stepznn-cli spork.list
-
Now the network participants need to update znnd/libznn with that spork
- Edit this file in your local repository
Update thevar
with two changes:-
Add a new spork:
ExampleSpork = NewImplementedSpork("Hash from Step 7")
-
Include it in the ImplementedSporksMap:
ExampleSpork.SporkId: true,
-
- Edit this file in your local repository
-
Now
make znnd
again and run the new binary on all participating network infrastructure (pillars and nodes)
- For this example, we just need to run it on the pillar.
- After the pillar starts producing momentums, return to znn_cli_dart and run:
znn-cli spork.activate <Hash from Step 7> -k Alice
- Display a list of sporks on the network
znn-cli spork.list
Example-spork
should beActivated