Hash Time Lock System Contract

Please read Hash Time Lock Contract introduction for detail.

Tutorial for Hash Time Lock (HTLC) System Contract

Introduction

The Hash Time Lock (HTLC) System Contract is a Seele built-in contract that supports cross-chain operations between different Seele chains or shards. It can also be chained with any block chain that supports smart contracts.

  • This system contract can be used directly between different Seele chains or shards to complete cross-chain operations; you can also use the contract written in solidity in labs to complete the cross-chain operation; of course, you could also use the combination of the two to complete the cross-chain.
  • In order for Seele and other chains that support smart contracts (such as ETH) for cross-chain operations, you need to use the contract in labs to complete the cross-chain between Seele and other block chains; or Seele uses the system contract and other chains use the contract in labs to complete the cross-chain.
  • This article is just a tutorial for the hash time lock system contract, for information on how to use contract written with solidity to complete the cross-chain please see labs

View commands

Run: client htlc -h for help

Example 1:

client htlc -h

NAME:

   client htlc - Hash time lock contract commands



USAGE:

   client htlc command [command options] [arguments...]



COMMANDS:

     create    create HTLC

     decode    decode HTLC contract information

     get       get HTLC information

     key       generate preimage key and key hash

     refund    refund from HTLC

     time      generate unix timestamp

     withdraw  withdraw from HTLC



OPTIONS:

   --help, -h  show help

Example 2: View subcommands

client htlc create -h

NAME:

   client htlc create - create HTLC



USAGE:

   client htlc create [command options] [arguments...]



OPTIONS:

   --address value, -a value  address for client to request (default: "127.0.0.1:8027")

   --from value               key file of the sender

   --to value                 to address

   --amount value             amount value, unit is fan

   --fee value                transaction fee

   --nonce value              transaction nonce (default: 0)

   --hash value               hash value in hex

   --time value               time lock in the HTLC (default: 0)

Tutorial

Introduction: Alice and Bob are having cross-chain operation or some kind of transaction, Alice is the initiator on the Seele chain, Bob is the receiver; Bob is the initiator on the seele2 chain, Alice is the receiver. Alice and Bob need to have account on both seele1 and seele2.

  • Alice creates a hash time lock contract on seele1
  • Bob verifies that whether the contract created by Alice conforms to the contract based on the contract hash value and key hash value sent by Alice.
  • If Bob approves the check, Bob creates a hash time lock on seele2 according to the key hash value sent by Alice; Otherwise, Alice takes back the amount after the lock time expires.
  • Alice verifies that the contract created by Bob conforms to the contract based on the hash value of the contract sent by Bob on the seele2.
  • If Alice approves the check, then Alice gets the amount on the seele2; otherwise, Bob takes back the amount after the lockout time has elapsed.
  • Bob gets the private key on seele2 based on the result of after Alice gets the amount
  • Bob gets the amount on seele1
  • If Bob or Alice does not get the amount during the lockout time, Alice and Bob can take back the amount after the lockout time has elapsed. #### On seele1
    1. Generate private key
client htlc key

preimage: 0xa7e1fe2f00137100321fd2b5970cb681462a72802d0bb2e97988892326aed2c3

hash: 0xb0f8234614bb7e54e6c4ca24ff54c3319fad607af6dd18593ae5679376248e5c


Description:preimage is the private key and hash is the hash value of the private key.
    1. Generation time, the time used to lock the transaction amount (Bob can take the amount in the transaction as long as it can provide preimage)
client htlc time --time 300

locktime: 1536906634


Description: Increase 300 seconds to the current time
    1. Alice gets the current balance for comparison
client getbalance --account 0x0a57a2714e193b7ac50475ce625f2dcfb483d741

{

        "Account": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",

        "Balance": 1000000000000

}
    1. Alice creates a Hash Time Lock (HTLC) system contract
Create Hash Time Lock (HTLC) system contract

client htlc create --from .\keyfile\shard1-0x0a57a2714e193b7ac50475ce625f2dcfb483d741 --to 0x2a87b6504cd00af95a83b9887112016a2a991cf1 --amount 10000000000 --fee 10 --hash 0xb0f8234614bb7e54e6c4ca24ff54c3319fad607af6dd18593ae5679376248e5c --time 1536906634

Please input your key file password:

account 0x0a57a2714e193b7ac50475ce625f2dcfb483d741 current nonce: 0, sending nonce: 0

{

        "HashLock": "0xb0f8234614bb7e54e6c4ca24ff54c3319fad607af6dd18593ae5679376248e5c",

        "TimeLock": 1536906634,

        "Tx": {

                "Hash": "0xc52ec83dd7c115d4ed49ca908fcbbc4b1d8f3d0ded0430ed124cfaa7d3bc5daf",

                "Data": {

                        "From": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",

                        "To": "0x0000000000000000000000000000000000000103",

                        "Amount": 10000000000,

                        "AccountNonce": 0,

                        "Fee": 10,

                        "Timestamp": 0,

                        "Payload": "0x007b22486173684c6f636b223a22307862306638323334363134626237653534653663346361323466663534633333313966616436303761663664643138353933616535363739333736323438653563222c2254696d654c6f636b223a313533363930363633342c22546f223a22307832613837623635303463643030616639356138336239383837313132303136613261393931636631227d"

                },

                "Signature": {

                        "Sig": "2fkr5/0qOfvrSw+UwH7Qfi2cVcYO4Gylklr8Jv7+EGhihVt6T4IAt/CPLYr88D4PlgkzxUtG0SPUBQ9JVISr4AA="

                }

        }

}



Check the balance after the contract is packaged into the block

client getbalance --account 0x0a57a2714e193b7ac50475ce625f2dcfb483d741

{

        "Account": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",

        "Balance": 989999990990

}



Check the transaction result after the contract is packaged into the block.

client getreceipt --hash 0xc52ec83dd7c115d4ed49ca908fcbbc4b1d8f3d0ded0430ed124cfaa7d3bc5daf



{

        "contract": "0x",

        "failed": false,

        "poststate": "0x82d64f5e694e7b6382f5144e2c64e05dbcaea1ae8e99e7300dccecae7f8b10d7",

        "result": "0x7b225478223a7b2248617368223a22307863353265633833646437633131356434656434396361393038666362626334623164386633643064656430343330656431323463666161376433626335646166222c2244617461223a7b2246726f6d223a22307830613537613237313465313933623761633530343735636536323566326463666234383364373431222c22546f223a22307830303030303030303030303030303030303030303030303030303030303030303030303030313033222c22416d6f756e74223a31303030303030303030302c224163636f756e744e6f6e6365223a302c22466565223a31302c2254696d657374616d70223a302c225061796c6f6164223a2230783030376232323438363137333638346336663633366232323361323233303738363233303636333833323333333433363331333436323632333736353335333436353336363333343633363133323334363636363335333436333333333333313339363636313634333633303337363136363336363436343331333833353339333336313635333533363337333933333337333633323334333836353335363332323263323235343639366436353463366636333662323233613331333533333336333933303336333633333334326332323534366632323361323233303738333236313338333736323336333533303334363336343330333036313636333933353631333833333632333933383338333733313331333233303331333636313332363133393339333136333636333132323764227d2c225369676e6174757265223a7b22536967223a2232666b72352f30714f66767253772b5577483751666932635663594f3447796c6b6c72384a76372b454768696856743654344941742f43504c597238384434506c676b7a78557447305350554251394a564953723441413d227d7d2c22486173684c6f636b223a22307862306638323334363134626237653534653663346361323466663534633333313966616436303761663664643138353933616535363739333736323438653563222c2254696d654c6f636b223a313533363930363633342c22546f223a22307832613837623635303463643030616639356138336239383837313132303136613261393931636631222c22526566756e646564223a66616c73652c2257697468647261776564223a66616c73652c22507265696d616765223a22227d",

        "totalFee": 9010,

        "txhash": "0xc52ec83dd7c115d4ed49ca908fcbbc4b1d8f3d0ded0430ed124cfaa7d3bc5daf",

        "usedGas": 100000

}





Decode the result field


client htlc decode --payload 0x7b225478223a7b2248617368223a22307863353265633833646437633 131356434656434396361393038666362626334623164386633643064656430343330656431323463666161376433626335646166222c2244617461223a7b2246726f6d223a22307830613537613237313465313933623761633530343735636536323566326463666234383364373431222c22546f223a22307830303030303030303030303030303030303030303030303030303030303030303030303030313033222c22416d6f756e74223a31303030303030303030302c224163636f756e744e6f6e6365223a302c22466565223a31302c2254696d657374616d70223a302c225061796c6f6164223a2230783030376232323438363137333638346336663633366232323361323233303738363233303636333833323333333433363331333436323632333736353335333436353336363333343633363133323334363636363335333436333333333333313339363636313634333633303337363136363336363436343331333833353339333336313635333533363337333933333337333633323334333836353335363332323263323235343639366436353463366636333662323233613331333533333336333933303336333633333334326332323534366632323361323233303738333236313338333736323336333533303334363336343330333036313636333933353631333833333632333933383338333733313331333233303331333636313332363133393339333136333636333132323764227d2c225369676e6174757265223a7b22536967223a2232666b72352f30714f66767253772b5577483751666932635663594f3447796c6b6c72384a76372b454768696856743654344941742f43504c597238384434506c676b7a78557447305350554251394a564953723441413d227d7d2c22486173684c6f636b223a22307862306638323334363134626237653534653663346361323466663534633333313966616436303761663664643138353933616535363739333736323438653563222c2254696d654c6f636b223a313533363930363633342c22546f223a22307832613837623635303463643030616639356138336239383837313132303136613261393931636631222c22526566756e646564223a66616c73652c2257697468647261776564223a66616c73652c22507265696d616765223a22227d

{

        "Tx": {

                "Hash": "0xc52ec83dd7c115d4ed49ca908fcbbc4b1d8f3d0ded0430ed124cfaa7d3bc5daf",

                "Data": {

                        "From": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",

                        "To": "0x0000000000000000000000000000000000000103",

                        "Amount": 10000000000,

                        "AccountNonce": 0,

                        "Fee": 10,

                        "Timestamp": 0,

                        "Payload": "0x007b22486173684c6f636b223a22307862306638323334363134626237653534653663346361323466663534633333313966616436303761663664643138353933616535363739333736323438653563222c2254696d654c6f636b223a313533363930363633342c22546f223a22307832613837623635303463643030616639356138336239383837313132303136613261393931636631227d"

                },

                "Signature": {

                        "Sig": "2fkr5/0qOfvrSw+UwH7Qfi2cVcYO4Gylklr8Jv7+EGhihVt6T4IAt/CPLYr88D4PlgkzxUtG0SPUBQ9JVISr4AA="

                }

        },

        "HashLock": "0xb0f8234614bb7e54e6c4ca24ff54c3319fad607af6dd18593ae5679376248e5c",

        "TimeLock": 1536906634,

        "To": "0x2a87b6504cd00af95a83b9887112016a2a991cf1",

        "Refunded": false,

        "Withdrawed": false,

        "Preimage": ""

}
  • 5.Bob uses the hash value of the hash time lock system contract sent by Alice and the hash value of the private key to see if Alice’s contract created on the seele1 meets the agreement of both parties.
Check the transaction result after the contract is packaged into the block.

client getreceipt --hash 0xc52ec83dd7c115d4ed49ca908fcbbc4b1d8f3d0ded0430ed124cfaa7d3bc5daf



{

        "contract": "0x",

        "failed": false,

        "poststate": "0x82d64f5e694e7b6382f5144e2c64e05dbcaea1ae8e99e7300dccecae7f8b10d7",

        "result": "0x7b225478223a7b2248617368223a22307863353265633833646437633131356434656434396361393038666362626334623164386633643064656430343330656431323463666161376433626335646166222c2244617461223a7b2246726f6d223a22307830613537613237313465313933623761633530343735636536323566326463666234383364373431222c22546f223a22307830303030303030303030303030303030303030303030303030303030303030303030303030313033222c22416d6f756e74223a31303030303030303030302c224163636f756e744e6f6e6365223a302c22466565223a31302c2254696d657374616d70223a302c225061796c6f6164223a2230783030376232323438363137333638346336663633366232323361323233303738363233303636333833323333333433363331333436323632333736353335333436353336363333343633363133323334363636363335333436333333333333313339363636313634333633303337363136363336363436343331333833353339333336313635333533363337333933333337333633323334333836353335363332323263323235343639366436353463366636333662323233613331333533333336333933303336333633333334326332323534366632323361323233303738333236313338333736323336333533303334363336343330333036313636333933353631333833333632333933383338333733313331333233303331333636313332363133393339333136333636333132323764227d2c225369676e6174757265223a7b22536967223a2232666b72352f30714f66767253772b5577483751666932635663594f3447796c6b6c72384a76372b454768696856743654344941742f43504c597238384434506c676b7a78557447305350554251394a564953723441413d227d7d2c22486173684c6f636b223a22307862306638323334363134626237653534653663346361323466663534633333313966616436303761663664643138353933616535363739333736323438653563222c2254696d654c6f636b223a313533363930363633342c22546f223a22307832613837623635303463643030616639356138336239383837313132303136613261393931636631222c22526566756e646564223a66616c73652c2257697468647261776564223a66616c73652c22507265696d616765223a22227d",

        "totalFee": 9010,

        "txhash": "0xc52ec83dd7c115d4ed49ca908fcbbc4b1d8f3d0ded0430ed124cfaa7d3bc5daf",

        "usedGas": 100000

}





Decode the result field


client htlc decode --payload 0x7b225478223a7b2248617368223a22307863353265633833646437633131356434656434396361393038666362626334623164386633643064656430343330656431323463666161376433626335646166222c2244617461223a7b2246726f6d223a22307830613537613237313465313933623761633530343735636536323566326463666234383364373431222c22546f223a22307830303030303030303030303030303030303030303030303030303030303030303030303030313033222c22416d6f756e74223a31303030303030303030302c224163636f756e744e6f6e6365223a302c22466565223a31302c2254696d657374616d70223a302c225061796c6f6164223a2230783030376232323438363137333638346336663633366232323361323233303738363233303636333833323333333433363331333436323632333736353335333436353336363333343633363133323334363636363335333436333333333333313339363636313634333633303337363136363336363436343331333833353339333336313635333533363337333933333337333633323334333836353335363332323263323235343639366436353463366636333662323233613331333533333336333933303336333633333334326332323534366632323361323233303738333236313338333736323336333533303334363336343330333036313636333933353631333833333632333933383338333733313331333233303331333636313332363133393339333136333636333132323764227d2c225369676e6174757265223a7b22536967223a2232666b72352f30714f66767253772b5577483751666932635663594f3447796c6b6c72384a76372b454768696856743654344941742f43504c597238384434506c676b7a78557447305350554251394a564953723441413d227d7d2c22486173684c6f636b223a22307862306638323334363134626237653534653663346361323466663534633333313966616436303761663664643138353933616535363739333736323438653563222c2254696d654c6f636b223a313533363930363633342c22546f223a22307832613837623635303463643030616639356138336239383837313132303136613261393931636631222c22526566756e646564223a66616c73652c2257697468647261776564223a66616c73652c22507265696d616765223a22227d

{

        "Tx": {

                "Hash": "0xc52ec83dd7c115d4ed49ca908fcbbc4b1d8f3d0ded0430ed124cfaa7d3bc5daf",

                "Data": {

                        "From": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",

                        "To": "0x0000000000000000000000000000000000000103",

                        "Amount": 10000000000,

                        "AccountNonce": 0,

                        "Fee": 10,

                        "Timestamp": 0,

                        "Payload": "0x007b22486173684c6f636b223a22307862306638323334363134626237653534653663346361323466663534633333313966616436303761663664643138353933616535363739333736323438653563222c2254696d654c6f636b223a313533363930363633342c22546f223a22307832613837623635303463643030616639356138336239383837313132303136613261393931636631227d"

                },

                "Signature": {

                        "Sig": "2fkr5/0qOfvrSw+UwH7Qfi2cVcYO4Gylklr8Jv7+EGhihVt6T4IAt/CPLYr88D4PlgkzxUtG0SPUBQ9JVISr4AA="

                }

        },

        "HashLock": "0xb0f8234614bb7e54e6c4ca24ff54c3319fad607af6dd18593ae5679376248e5c",

        "TimeLock": 1536906634,

        "To": "0x2a87b6504cd00af95a83b9887112016a2a991cf1",

        "Refunded": false,

        "Withdrawed": false,

        "Preimage": ""

}


Check if "To" is the account address on seele1, whether the amount in the "Tx" is agreed, and TimeLock, HashLock conforms to the convention and Refunded, withdrawed is false

On seele2

  • 6.If Bob validats in 5 conforms to the convention, Bob creates a contract on seele2, (refer to how Alice creates a contract, Bob does not need to create a new private key and private key hash, Bob also needs to produce a lock-up time agreed by both parties with the hash value of the private key passed over by Alice)
  • 7.Bob checks his balance information for comparison
client getbalance --account 0x2a87b6504cd00af95a83b9887112016a2a991cf1

{

        "Account": "0x2a87b6504cd00af95a83b9887112016a2a991cf1",

        "Balance": 1000000000000

}

On seele1

  • 8.Alice uses the hash value of the hash time lock system contract sent by Bob to see if the contract created by Bob on the seele2 meets the agreement of both parties (refer to step 5).

On seele2

  • 9.If the agreement is met, Alice gets the amount on seele2 (refer to step 10)

On seele1

  • 10.Bob withdraws money according to the hash value of the hash time lock system contract and private key provided by Alice. For private key acquisition, refer to step 5 (Note: After Alice withdraws the amount, Bob operates on on seele2 chain, and Preimage will be found. The field is changed from an empty string to a value, which is the private key)
After the contract is packaged into the block, check the transaction result.
client htlc withdraw --from .\keyfile\shard1-0x2a87b6504cd00af95a83b9887112016a2a991cf1

--fee 10 --hash 0xc52ec83dd7c115d4ed49ca908fcbbc4b1d8f3d0ded0430ed124cfaa7d3bc5daf --preimage 0xa7e1fe2f00137100321fd2b5970cb681462a72802d0bb2e97988892326aed2c3

Please input your key file password:

account 0x2a87b6504cd00af95a83b9887112016a2a991cf1 current nonce: 0, sending nonce: 0

{

        "Tx": {

                "Hash": "0x8d73463d73e0584131afa7e218470b50e8b44449c3634e47fd6053a61febdc47",

                "Data": {

                        "From": "0x2a87b6504cd00af95a83b9887112016a2a991cf1",

                        "To": "0x0000000000000000000000000000000000000103",

                        "Amount": 0,

                        "AccountNonce": 0,

                        "Fee": 10,

                        "Timestamp": 0,

                        "Payload": "0x017b2248617368223a22307863353265633833646437633131356434656434396361393038666362626334623164386633643064656430343330656431323463666161376433626335646166222c22507265696d616765223a22307861376531666532663030313337313030333231666432623539373063623638313436326137323830326430626232653937393838383932333236616564326333227d"

                },

                "Signature": {

                        "Sig": "yiHjETaU+FlYlhduah4sEdXFfiB/AIC0DNFFN875m+RnNN7opZJKvWKfSyppjF0l96yD7oyhS9w8YvgEAhZO+QA="

                }

        },

        "hash": "0xc52ec83dd7c115d4ed49ca908fcbbc4b1d8f3d0ded0430ed124cfaa7d3bc5daf",

        "preimage": "0xa7e1fe2f00137100321fd2b5970cb681462a72802d0bb2e97988892326aed2c3"

}



client getbalance --account 0x2a87b6504cd00af95a83b9887112016a2a991cf1

{

        "Account": "0x2a87b6504cd00af95a83b9887112016a2a991cf1",

        "Balance": 1009999999890

}



 client getreceipt --hash 0x8d73463d73e0584131afa7e218470b50e8b44449c3634e47fd6053a61febd c47

{

        "contract": "0x",

        "failed": false,

        "poststate": "0xecdb8dac56e436386637e0daf53e122327ef8cd3d0c883085876f2a9bb888527",

        "result": "0x7b225478223a7b2248617368223a22307863353265633833646437633131356434656434396361393038666362626334623164386633643064656430343330656431323463666161376433626335646166222c2244617461223a7b2246726f6d223a22307830613537613237313465313933623761633530343735636536323566326463666234383364373431222c22546f223a22307830303030303030303030303030303030303030303030303030303030303030303030303030313033222c22416d6f756e74223a31303030303030303030302c224163636f756e744e6f6e6365223a302c22466565223a31302c2254696d657374616d70223a302c225061796c6f6164223a2230783030376232323438363137333638346336663633366232323361323233303738363233303636333833323333333433363331333436323632333736353335333436353336363333343633363133323334363636363335333436333333333333313339363636313634333633303337363136363336363436343331333833353339333336313635333533363337333933333337333633323334333836353335363332323263323235343639366436353463366636333662323233613331333533333336333933303336333633333334326332323534366632323361323233303738333236313338333736323336333533303334363336343330333036313636333933353631333833333632333933383338333733313331333233303331333636313332363133393339333136333636333132323764227d2c225369676e6174757265223a7b22536967223a2232666b72352f30714f66767253772b5577483751666932635663594f3447796c6b6c72384a76372b454768696856743654344941742f43504c597238384434506c676b7a78557447305350554251394a564953723441413d227d7d2c22486173684c6f636b223a22307862306638323334363134626237653534653663346361323466663534633333313966616436303761663664643138353933616535363739333736323438653563222c2254696d654c6f636b223a313533363930363633342c22546f223a22307832613837623635303463643030616639356138336239383837313132303136613261393931636631222c22526566756e646564223a66616c73652c2257697468647261776564223a747275652c22507265696d616765223a22307861376531666532663030313337313030333231666432623539373063623638313436326137323830326430626232653937393838383932333236616564326333227d",

        "totalFee": 110,

        "txhash": "0x8d73463d73e0584131afa7e218470b50e8b44449c3634e47fd6053a61febdc47",

        "usedGas": 5000

}





client htlc decode --payload 0x7b225478223a7b2248617368223a22307863353265633833646437633 131356434656434396361393038666362626334623164386633643064656430343330656431323463666161376433626335646166222c2244617461223a7b2246726f6d223a22307830613537613237313465313933623761633530343735636536323566326463666234383364373431222c22546f223a22307830303030303030303030303030303030303030303030303030303030303030303030303030313033222c22416d6f756e74223a31303030303030303030302c224163636f756e744e6f6e6365223a302c22466565223a31302c2254696d657374616d70223a302c225061796c6f6164223a2230783030376232323438363137333638346336663633366232323361323233303738363233303636333833323333333433363331333436323632333736353335333436353336363333343633363133323334363636363335333436333333333333313339363636313634333633303337363136363336363436343331333833353339333336313635333533363337333933333337333633323334333836353335363332323263323235343639366436353463366636333662323233613331333533333336333933303336333633333334326332323534366632323361323233303738333236313338333736323336333533303334363336343330333036313636333933353631333833333632333933383338333733313331333233303331333636313332363133393339333136333636333132323764227d2c225369676e6174757265223a7b22536967223a2232666b72352f30714f66767253772b5577483751666932635663594f3447796c6b6c72384a76372b454768696856743654344941742f43504c597238384434506c676b7a78557447305350554251394a564953723441413d227d7d2c22486173684c6f636b223a22307862306638323334363134626237653534653663346361323466663534633333313966616436303761663664643138353933616535363739333736323438653563222c2254696d654c6f636b223a313533363930363633342c22546f223a22307832613837623635303463643030616639356138336239383837313132303136613261393931636631222c22526566756e646564223a66616c73652c2257697468647261776564223a747275652c22507265696d616765223a22307861376531666532663030313337313030333231666432623539373063623638313436326137323830326430626232653937393838383932333236616564326333227d

{

        "Tx": {

                "Hash": "0xc52ec83dd7c115d4ed49ca908fcbbc4b1d8f3d0ded0430ed124cfaa7d3bc5daf",

                "Data": {

                        "From": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",

                        "To": "0x0000000000000000000000000000000000000103",

                        "Amount": 10000000000,

                        "AccountNonce": 0,

                        "Fee": 10,

                        "Timestamp": 0,

                        "Payload": "0x007b22486173684c6f636b223a22307862306638323334363134626237653534653663346361323466663534633333313966616436303761663664643138353933616535363739333736323438653563222c2254696d654c6f636b223a313533363930363633342c22546f223a22307832613837623635303463643030616639356138336239383837313132303136613261393931636631227d"

                },

                "Signature": {

                        "Sig": "2fkr5/0qOfvrSw+UwH7Qfi2cVcYO4Gylklr8Jv7+EGhihVt6T4IAt/CPLYr88D4PlgkzxUtG0SPUBQ9JVISr4AA="

                }

        },

        "HashLock": "0xb0f8234614bb7e54e6c4ca24ff54c3319fad607af6dd18593ae5679376248e5c",

        "TimeLock": 1536906634,

        "To": "0x2a87b6504cd00af95a83b9887112016a2a991cf1",

        "Refunded": false,

        "Withdrawed": true,

        "Preimage": "0xa7e1fe2f00137100321fd2b5970cb681462a72802d0bb2e97988892326aed2c3"

}
  • 11.Fake user retrieves the amount after the lock time
client htlc refund --from .\keyfile\shard1-0x2a87b6504cd00af95a83b9887112016a2a991cf1 -- fee 10 --hash 0xc52ec83dd7c115d4ed49ca908fcbbc4b1d8f3d0ded0430ed124cfaa7d3bc5daf

Please input your key file password:

account 0x2a87b6504cd00af95a83b9887112016a2a991cf1 current nonce: 1, sending nonce: 1

{

        "Tx": {

                "Hash": "0x3eddaa00d9fa8c2980c3dd683625ffa2f37eb66fbdcb9cf37d2b0335d481aa1b",

                "Data": {

                        "From": "0x2a87b6504cd00af95a83b9887112016a2a991cf1",

                        "To": "0x0000000000000000000000000000000000000103",

                        "Amount": 0,

                        "AccountNonce": 1,

                        "Fee": 10,

                        "Timestamp": 0,

                        "Payload": "0x02c52ec83dd7c115d4ed49ca908fcbbc4b1d8f3d0ded0430ed124cfaa7d3bc5daf"

                },

                "Signature": {

                        "Sig": "K1XWtmj5iDfj4cRnl0QagumdBPl6gTRXIYHTG2do4cdBA/fVFi/KIWGev5Eks1qDJBx/G0Y0gfRzK8InQLHQBwA="

                }

        },

        "hash": "0xc52ec83dd7c115d4ed49ca908fcbbc4b1d8f3d0ded0430ed124cfaa7d3bc5daf"

}



client getreceipt --hash 0x3eddaa00d9fa8c2980c3dd683625ffa2f37eb66fbdcb9cf37d2b0335d481a a1b

{

        "contract": "0x",

        "failed": true,

        "poststate": "0xa6598a0205040c1acfa1ddc1e4b1f65337e3629d5eb460628f713f773f33da11",

        "result": "Failed to refund, only owner is allowed",

        "totalFee": 110,

        "txhash": "0x3eddaa00d9fa8c2980c3dd683625ffa2f37eb66fbdcb9cf37d2b0335d481aa1b",

        "usedGas": 5000

}
  • 12.Has already withdrawed and then refunded
client htlc refund --from .\keyfile\shard1-0x0a57a2714e193b7ac50475ce625f2dcfb483d741 -- fee 10 --hash 0xc52ec83dd7c115d4ed49ca908fcbbc4b1d8f3d0ded0430ed124cfaa7d3bc5daf

Please input your key file password:

account 0x0a57a2714e193b7ac50475ce625f2dcfb483d741 current nonce: 1, sending nonce: 1

{

        "Tx": {

                "Hash": "0x218560f2433bc28dd9bf4fc37ae87df78550dee5a51ef17d2c5d719112dd1eab",

                "Data": {

                        "From": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",

                        "To": "0x0000000000000000000000000000000000000103",

                        "Amount": 0,

                        "AccountNonce": 1,

                        "Fee": 10,

                        "Timestamp": 0,

                        "Payload": "0x02c52ec83dd7c115d4ed49ca908fcbbc4b1d8f3d0ded0430ed124cfaa7d3bc5daf"

                },

                "Signature": {

                        "Sig": "6RjccmTHRLN5uKtND3uO2UQ6Pr/KWHqHjGmJ7W1g8UYtBLpwc988Kmgv0GJyWp3OtG24Zhebpu7fbufzD+R+NQA="

                }

        },

        "hash": "0xc52ec83dd7c115d4ed49ca908fcbbc4b1d8f3d0ded0430ed124cfaa7d3bc5daf"

}



client getreceipt --hash 0x218560f2433bc28dd9bf4fc37ae87df78550dee5a51ef17d2c5d719112dd1 eab

{

        "contract": "0x",

        "failed": true,

        "poststate": "0x5d7d6d0b73a4cf11db8953b06f9b23a6c16c07acbb64b149c7f1bf5c5e65b63c",

        "result": "Failed to refund, receiver have withdrawed",

        "totalFee": 110,

        "txhash": "0x218560f2433bc28dd9bf4fc37ae87df78550dee5a51ef17d2c5d719112dd1eab",

        "usedGas": 5000

}
  • 13.Already refund, refund again will fail (refer to step 12)
  • 14.The lock time has not passed, refund will fail (refer to step 12)
  • 15.Already withdraw, withdraw again will fail (refer to step 10)
  • 16.Provide a fake private key, withdraw will fail (refer to step 10)
  • 17.Fake recipient initiate a withdraw will fail (refer to step 10)
  • 18.Withdraw after lock time expired will fail (refer to step 10)