Some time ago George published his work on BTC Atomic Swaps via HTLC: Cope Edition. I’ve been wanting to look at the code and create the necessary tools to interact with the contract.
For this I’ve recently published the C# version of the Zenon CLI and created a htlc branch for interacting with George’s code changes.
In order to make it more accessible for everyone I also created a tutorial I believe even the most non-tech savvy among us can follow.
first off, you can get a list of all commands by typing in znn-cli.exe or a detailed help of the command by typing in znn-cli.exe [command].
For example, to get the detailed help info for the htlc.create command, just type: znn-cli.exe htlc.create.
This will give you the following help info:
-p, --passphrase Use this passphrase for the keyStore or enter it manually in a secure way
-k, --keyStore Select the local keyStore (defaults to "available keyStore if only one is present")
-i, --index (Default: 0) Address index
-n, --netId (Default: 1) Specify the network id to use
-u, --url (Default: ws://127.0.0.1:35998) Provide a websocket znnd connection URL with a port
--help Display this help screen.
--version Display version information.
hashLockedAddress (pos. 1) Required.
tokenStandard (pos. 2) [ZNN/QSR/ZTS] Required.
amount (pos. 3) Required.
expirationTime (pos. 4) Required. Total seconds from now
hashType (pos. 5) Required. 0 = SHA3-256
keyMaxSize (pos. 6) Required.
preimage (pos. 7)
So, the last three arguments mean:
0 = hashType (currently only hash type 0 is supported)
32 = keyMaxSize (determines the maximum pre-image size).
“all your znn belong to us” = pre-image (currently only tekst is supported. Looking to add option to add base64)
If the lock is expired Alice can reclaim her funds by calling.
./znn-cli htlc.reclaim [hash id]
and receive all unreceived transactions, just like Bob did in the toturial.
yes. Looks like the hash has changed. Does that seem right?
Unreceived 100.00000000 tZNN from z1qxemdeddedxhtlcxxxxxxxxxxxxxxxxxygecvw. Use the hash 5da40a52b824efe63f87d2784e84569a0d20639fd7426c2aac72b32358241c7d to receive
George implemented support for the sha-256 hashing algoritme. I’ve updated the tools and integrated the functionality.
To try it out, you can either remove the existing builds and follow the tutorial from scratch or follow the instructions below to update and rebuild both repositories.
Linux
BICH go-zenon
cd ~/repos/go-zenon
git config pull.rebase false
git pull
git merge origin/htlc
make znnd
Use the createHash command to create a sha-256 hash.
./znn-cli createHash "all your znn belong to us" 1
Don’t forget to specify the hash type when creating a htlc, by default it uses the sha3-256 hashing algoritme. Use the following command to display the help information for command.
x3639@x3639-virtual-machine:~/repos/go-zenon$ git pull
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge (the default strategy)
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.
We merged htlc into origin previously. And now we are trying to pull an update to go-zenon. I’m not a git expert, but looks like we should merge the code?