-
Notifications
You must be signed in to change notification settings - Fork 1
Hash Time Lock contract
The following is a brief description of the transfer operations between different Seele's chains or slices. For other chain (such as Ethereum) and seele cross-chain operation, please refer to the following steps, just need to replace one of the chains or fragments into the chain of Ethereum.
- 1、 Required at least two Seele chains or shards.
Seele could be deploy with two separate chains or multiple slices in one chain, the documenation is at Start seele,Build you own cluster,Join Seele test network. You could also directly use the test network chain or fragment without deploying any Seele.
- 2、 Deploy hash time lock contract
Run git clone https://github.com/seeleteam/labs.git to download the source codes,add github.com/seeleteam/labs to gopath,change directory to ./github.com/seeleteam/labs/swap/ and then execute go build will build the swap executable file. In Windows, run swap.exe –h to view the help information, in Linux run ./swap –h to view the help information.
- For example, in Windows
swap.exe -h
NAME:
swap client - interact with node swap contract
USAGE:
swap.exe [global options] command [command options] [arguments...]
COMMANDS:
create create a new contract for htlc transaction on chain
gensecret generate secret and secret hash, secret hash is generated by sha256
getbalance get account balance
getContractById get the transaction info from the contract by contract id
getreceipt get receipt by transaction hash
init deploy the contract in seele
participate create a new contract for htlc transaction on other chain
refund refund seele from the contract
unpack decode the result of getContractById command
withdraw get seele from the contract
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
init is used to deploy the base contract to the Seele block chain network, that is deploying the hash time lock to the chain for subsequent use.
-
address
is the address and port of chain to be linked to, default is 127.0.0.1:8027 -
fee
is the transaction fee -
from
is the user's private key file, which needs to be produced using Seele's client key and the savekey command, see Seele API Documents for reference. -
nonce
is the user's transaction count, default is 0 for the user's current value
print the transaction information
Committed transactions are stored in ./config/deploy.json
swap init –h to see command variables
swap init --address 127.0.0.1:8027 --from ./keyfile/alice.key --fee 100 --nonce 0
Result:
{
"Hash": "0x457b76764a98a951dcc4720a7d32f4383bb904b79c27ec5f04ae97e9b9411a6c",
"Data": {
"From": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",
"To": "0x0000000000000000000000000000000000000000",
"Amount": 0,
"AccountNonce": 3,
"Fee": 10,
"Timestamp": 0,
"Payload": "0x608060405234801561001057600080fd5b50610bde806100206000396000f3006080604052600436106100615763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663335ef5bd811461006657806363615149146100925780637249fbb6146100c1578063e16c7d98146100d9575b600080fd5b610080600160a060020a0360043516602435604435610142565b60408051918252519081900360200190f35b34801561009e57600080fd5b506100ad6004356024356104c5565b604080519115158252519081900360200190f35b3480156100cd57600080fd5b506100ad60043561083e565b3480156100e557600080fd5b506100f1600435610b0c565b60408051600160a060020a03998a1681529790981660208801528688019590955260608601939093526080850191909152151560a0840152151560c083015260e08201529051908190036101000190f35b600034811061019b576040805160e560020a62461bcd02815260206004820152601560248201527f6d73672e76616c7565206d757374206265203e20300000000000000000000000604482015290519081900360640190fd5b81428111610219576040805160e560020a62461bcd02815260206004820152602360248201527f74696d656c6f636b2074696d65206d75737420626520696e207468652066757460448201527f7572650000000000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b604080516c01000000000000000000000000338102602080840191909152600160a060020a03891690910260348301523460488301526068820187905260888083018790528351808403909101815260a8909201928390528151600293918291908401908083835b602083106102a05780518252601f199092019160209182019101610281565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa1580156102df573d6000803e3d6000fd5b5050506040513d60208110156102f457600080fd5b5051915061030182610b95565b1561030b57600080fd5b6101006040519081016040528033600160a060020a0316815260200186600160a060020a0316815260200134815260200185600019168152602001848152602001600015158152602001600015158152602001600060010260001916815250600080846000191660001916815260200190815260200160002060008201518160000160006101000a815481600160a060020a030219169083600160a060020a0316021790555060208201518160010160006101000a815481600160a060020a030219169083600160a060020a0316021790555060408201518160020155606082015181600301906000191690556080820151816004015560a08201518160050160006101000a81548160ff02191690831515021790555060c08201518160050160016101000a81548160ff02191690831515021790555060e0820151816006019060001916905590505084600160a060020a031633600160a060020a031683600019167f329a8316ed9c3b2299597538371c2944c5026574e803b1ec31d6113e1cd67bde348888604051808481526020018360001916600019168152602001828152602001935050505060405180910390a4509392505050565b600080836104d281610b95565b1515610528576040805160e560020a62461bcd02815260206004820152601960248201527f636f6e7472616374496420646f6573206e6f7420657869737400000000000000604482015290519081900360640190fd5b60408051602080820187905282518083038201815291830192839052815188938893600293909282918401908083835b602083106105775780518252601f199092019160209182019101610558565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa1580156105b6573d6000803e3d6000fd5b5050506040513d60208110156105cb57600080fd5b505160008381526020819052604090206003015414610634576040805160e560020a62461bcd02815260206004820152601c60248201527f686173686c6f636b206861736820646f6573206e6f74206d6174636800000000604482015290519081900360640190fd5b6000878152602081905260409020600101548790600160a060020a031633146106a7576040805160e560020a62461bcd02815260206004820152601a60248201527f776974686472617761626c653a206e6f74207265636569766572000000000000604482015290519081900360640190fd5b60008181526020819052604090206005015460ff1615610711576040805160e560020a62461bcd02815260206004820152601f60248201527f776974686472617761626c653a20616c72656164792077697468647261776e00604482015290519081900360640190fd5b600081815260208190526040902060040154421061079f576040805160e560020a62461bcd02815260206004820152603160248201527f776974686472617761626c653a2074696d656c6f636b2074696d65206d75737460448201527f20626520696e2074686520667574757265000000000000000000000000000000606482015290519081900360840190fd5b600088815260208190526040808220600681018a905560058101805460ff1916600190811790915581015460028201549251919850600160a060020a03169282156108fc02929190818181858888f19350505050158015610804573d6000803e3d6000fd5b5060405188907fd6fd4c8e45bf0c70693141c7ce46451b6a6a28ac8386fca2ba914044e0e2391690600090a2506001979650505050505050565b6000808261084b81610b95565b15156108a1576040805160e560020a62461bcd02815260206004820152601960248201527f636f6e7472616374496420646f6573206e6f7420657869737400000000000000604482015290519081900360640190fd5b6000848152602081905260409020548490600160a060020a03163314610911576040805160e560020a62461bcd02815260206004820152601660248201527f726566756e6461626c653a206e6f742073656e64657200000000000000000000604482015290519081900360640190fd5b600081815260208190526040902060050154610100900460ff1615610980576040805160e560020a62461bcd02815260206004820152601c60248201527f726566756e6461626c653a20616c726561647920726566756e64656400000000604482015290519081900360640190fd5b60008181526020819052604090206005015460ff16156109ea576040805160e560020a62461bcd02815260206004820152601d60248201527f726566756e6461626c653a20616c72656164792077697468647261776e000000604482015290519081900360640190fd5b600081815260208190526040902060040154421015610a79576040805160e560020a62461bcd02815260206004820152602360248201527f726566756e6461626c653a2074696d656c6f636b206e6f74207965742070617360448201527f7365640000000000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b60008581526020819052604080822060058101805461ff001916610100179055805460028201549251919650600160a060020a03169282156108fc02929190818181858888f19350505050158015610ad5573d6000803e3d6000fd5b5060405185907f989b3a845197c9aec15f8982bbb30b5da714050e662a7a287bb1a94c81e2e70e90600090a2506001949350505050565b6000806000806000806000806000610b238a610b95565b1515610b2e57610b89565b50505060008781526020819052604090208054600182015460028301546003840154600485015460058601546006870154600160a060020a039687169d50959094169a509198509650945060ff808216945061010090910416915b50919395975091939597565b600090815260208190526040902054600160a060020a03161515905600a165627a7a723058206ae87e62dfff3a6c14b5a0e7f82bf8658c82e68a35b897d310bbdf23038b8fee0029"
},
"Signature": {
"Sig": "9QrWejZXXlo/PqVDpUiPSb9IuCqoy/Sx6LqP8HaO8F83tMQccPvl7IgaeLKDuipeVLJPgd4tEYn/CUYbXX4CKAE="
}
}
gensecret is for generating the hash value of the keys
none
print the key and key hash in hexadecimal format
The hash value of the secret keys is in hexadecimal format, and stored in ./config/hashkey.json
swap gensecret
Result:
secret hex: 0x261c680e5be606bc023d200f5019d2b63807a05079b431751d606c0bd8b53015
secretHash hex: 0x56915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2
create will create a transaction based on the contract created in init, will lock the initiator transfer amount for 48 hours
-
address
specify the address to send the transaction to,default is 127.0.0.1:8027 -
from
user's private key file -
to
receiver's address in hexadecimal format -
amount
the transfer amount -
fee
transaction fee -
secrethash
private key's hash value,in hexadecimal format -
nonce
user transaction count, the default is 0 for user's current value
Initiate transaction, and stored in ./config/create.json
swap create --address 127.0.0.1:8027 --from .\keyfile\shard1-0x0a57a2714e193b7ac50475ce625f2dcfb483d741 --to 0x91d341d70ab3859a60840e120e28a17c5c2f64a1 --amount 10000 --fee 100 --secrethash 0x56915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2
Results:
{
"Hash": "0x15e7143c38fc905e7f0905c198b53f75a704331c5ccd1eeaba9c0f0cc970074e",
"Data": {
"From": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",
"To": "0x13b001e4915c13dcff90f0751b4c145b21110002",
"Amount": 10000,
"AccountNonce": 4,
"Fee": 100,
"Timestamp": 0,
"Payload": "0x335ef5bd00000000000000000000000091d341d70ab3859a60840e120e28a17c5c2f64a156915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2000000000000000000000000000000000000000000000000000000005b80cd8b"
},
"Signature": {
"Sig": "ypHxG4wHd9rawyVSK+U+1by8i8XbtZkceoBkBz9MhDFQ9z3KOwvz5Jtb+LGce5HWXClZOWSqJRiAvtgzi8xRYQA="
}
}
participate is creating a transaction on another Seele chain based on the contract created in init, which will lock the initiator transfer amount for 24 hours.
-
address
the address to send transactions to,default is 127.0.0.1:8027 -
from
is the private key file -
to
recipient address in hexadecimal format -
amount
transfer amount -
fee
transaction fee -
secrethash
secrethash hash value of the private key, in hexadeimal format, the secrethash should be the one being used by create -
nonce
transaction count,default is 0
commited transactions, stored in ./config/participate.json
swap participate --address 127.0.0.1:8027 --from .\keyfile\shard2-0x2a23825407740fa7163069257c57452c4d4fc3d1 --to 0x0a57a2714e193b7ac50475ce625f2dcfb483d741 --amount 10000 --fee 100 --secrethash 0x56915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2
Result:
{
"Hash": "0x15e7143c38fc905e7f0905c198b53f75a704331c5ccd1eeaba9c0f0cc970074e",
"Data": {
"From": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",
"To": "0x13b001e4915c13dcff90f0751b4c145b21110002",
"Amount": 10000,
"AccountNonce": 4,
"Fee": 100,
"Timestamp": 0,
"Payload": "0x335ef5bd00000000000000000000000091d341d70ab3859a60840e120e28a17c5c2f64a156915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2000000000000000000000000000000000000000000000000000000005b80cd8b"
},
"Signature": {
"Sig": "ypHxG4wHd9rawyVSK+U+1by8i8XbtZkceoBkBz9MhDFQ9z3KOwvz5Jtb+LGce5HWXClZOWSqJRiAvtgzi8xRYQA="
}
}
refund Get back the sent Seele after the lock time
-
address
is the address to send transactions to,default is 127.0.0.1:8027 127.0.0.1:8027 -
from
is the private key file -
fee
is the transaction fee -
nonce
is the transaction count,default is 0 -
contractId
the ID of the transaction to be queried, in hexadecimal format; the ID is the hash value of the result of create or participate, call the getreceipt command of the Seele client to see the result field. Runclient getreceipt --hash <hash> --address host:port
orswap getreceipt --hash <hash> --address host:port
, the result field of the returned result is the contractId
client getreceipt --hash 0xbc4e5bfd44832ff5005cd77117c382ab7e0d592a7de3d0dc71dd64061006d5f6 --address 127.0.0.1:8027
or
swap getreceipt --hash 0xbc4e5bfd44832ff5005cd77117c382ab7e0d592a7de3d0dc71dd64061006d5f6 --address 127.0.0.1:8027
Result:
{
"contract": "0x",
"failed": false,
"logs": [
{
"address": "0x13b001e4915c13dcff90f0751b4c145b21110002",
"data": [
"0x0000000000000000000000000000000000000000000000000000000000002710",
"0x56915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2",
"0x000000000000000000000000000000000000000000000000000000005b7f7ee7"
],
"topics": "[0x329a8316ed9c3b2299597538371c2944c5026574e803b1ec31d6113e1cd67bde, 0xfc2ab449cc8c66ceacfab3e7c9fb68bdeeecefa4c6905db2431e98d2950cbb4a, 0x0000000000000000000000000a57a2714e193b7ac50475ce625f2dcfb483d741, 0x00000000000000000000000091d341d70ab3859a60840e120e28a17c5c2f64a1]"
}
],
"poststate": "0xe117fdeba7847029d9f7d8f5bef41bffc2d14df795b198e64389b7a92af099ef",
"result": "0xfc2ab449cc8c66ceacfab3e7c9fb68bdeeecefa4c6905db2431e98d2950cbb4a",
"txhash": "0xbc4e5bfd44832ff5005cd77117c382ab7e0d592a7de3d0dc71dd64061006d5f6"
}
the result field is the contractId
transaction is stored in ./config/refund.json
swap refund --from .\keyfile\shard1-0x0a57a2714e193b7ac50475ce625f2dcfb483d741 --fee 10 --address 127.0.0.1:8027 --nonce 0 --contractId 0xfc2ab449cc8c66ceacfab3e7c9fb68bdeeecefa4c6905db2431e98d2950cbb4a
Return result:
{
"Hash": "0xb8e73f3fd31d465f833b340b4fc27885bc0975f8e09c5517e9698ec7a2a64f9f",
"Data": {
"From": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",
"To": "0x13b001e4915c13dcff90f0751b4c145b21110002",
"Amount": 0,
"AccountNonce": 8,
"Fee": 10,
"Timestamp": 0,
"Payload": "0x7249fbb6fc2ab449cc8c66ceacfab3e7c9fb68bdeeecefa4c6905db2431e98d2950cbb4a"
},
"Signature": {
"Sig": "Trl6LJkTr7LM6AR2H/rdLmT7ZzRiAikUmTuyZ01bAxAM94PL4WuW+PBDMcBj1Cih0h6lyJwwY30ytn66g/toMAA="
}
}
withdraw getting the Seele tokens from the contract
-
address
is the address to send transactions to,default is 127.0.0.1:8027 -
from
is the private key file -
secret
raw data for production of secrethash,in hexadecimal format -
fee
transaction fee -
nonce
transaction count,default is 0 -
contractId
the ID of the transaction to be queried,in hexadecimal format
transaction is stored in ./config/withdraw.json
swap withdraw --address 127.0.0.1:8027 --from .\keyfile\bob.key --secret 0x261c680e5be606bc023d200f5019d2b63807a05079b431751d606c0bd8b53015 --fee 10 --nonce 0 --contractId 0xfc2ab449cc8c66ceacfab3e7c9fb68bdeeecefa4c6905db2431e98d2950cbb4a
Result:
{
"Hash": "0x502caedee71ac376a2c667f1ddcd79460d8b02906f9a2367095a78d1b9222306",
"Data": {
"From": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",
"To": "0x13b001e4915c13dcff90f0751b4c145b21110002",
"Amount": 0,
"AccountNonce": 9,
"Fee": 10,
"Timestamp": 0,
"Payload": "0x63615149fc2ab449cc8c66ceacfab3e7c9fb68bdeeecefa4c6905db2431e98d2950cbb4a261c680e5be606bc023d200f5019d2b63807a05079b431751d606c0bd8b53015"
},
"Signature": {
"Sig": "1dEoWAeaolpMx9uB74ZzHpXogTRW0ZJYzd2HCWgDBEY9Pg/pJzmLAUnhJm5BnJ8DglF1rSelL9Zp4ZHsCFjWAgA="
}
}
getContractById is used to obtain the transaction information initiated by the sender.
-
address
is the address to send transactions to,default is 127.0.0.1:8027 -
from
is the private key file -
fee
is the transaction fee -
nonce
is the transaction count,default is 0 -
contractId
is the ID of the transaction to be queried, in hexadecimal format
transaction is stored in ./config/contract.json
swap getContractById --address 127.0.0.1:8028 --from .\keyfile\alice.key --fee 10 --contractId 0xfc2ab449cc8c66ceacfab3e7c9fb68bdeeecefa4c6905db2431e98d2950cbb4a
{
"Hash": "0x5443407e3a865651db3b9dc939174bb0df6ca52f02d0b542d0c1ba6ac8452b35",
"Data": {
"From": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",
"To": "0xe17a6a769b20d6e54fdc063d51172074c1fc0102",
"Amount": 0,
"AccountNonce": 7,
"Fee": 10,
"Timestamp": 0,
"Payload": "0xe16c7d98fe036d9d54657dd5301ed52b36f65c65cb6e29feb0a70367c8f8900c247467b9"
},
"Signature": {
"Sig": "8mu9bArsPcVJunEISF3r8t/WAsKmQ4LQOflj0aNHc/1N4+HXhFe/x3ZdQESr6fHf3Dc3AcQn2UfNI5YXI31rlwA="
}
}
unpack is use to decode the return result in the contract after the execution of getContractById
-
address
is the address to send transactions to,default is 127.0.0.1:8027 -
hash
the hash value of the transaction, returning the hash field in the result after executing getContractById , or the hash field in ./config/contract.json
contractId is the corresponding transfer ID stored in ./config/contractinfo.json
example:
swap unpack --hash 0x5443407e3a865651db3b9dc939174bb0df6ca52f02d0b542d0c1ba6ac8452b35
result:
{
"Sender": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",
"Receiver": "0x91d341d70ab3859a60840e120e28a17c5c2f64a1",
"Amount": 100000000,
"Hashlock": "0x0021377512d226cc1b7151bd4732452f5c7f1cfb9f0285350f95be3e82c3f6be",
"Timelock": 1535177397,
"Withdrawn": false,
"Refunded": false,
"Preimage": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
Notes: According to the information listed, check if the receiver is in its own account, the amount is consistent, the hashlock is the secrethash advertised by the initiator, the timelock is about 48 hours from the moment, the withdrawal is desirable, and the refund has been executed, then decide whether to create a transaction using the participant.
getreceipt is used to get the result of a transaction or contract execution
-
address
is the address to send transactions to,default is 127.0.0.1:8027 -
hash
is the hash value of the transaction
receipt is the result
swap getreceipt --hash 0x1783a4aee339a337c5eb2c040fe6503529f1e49bb023a93ad3d38dc1c28c66f6 --address 127.0.0.1:8027
{
"contract": "0x",
"failed": false,
"logs": [
{
"address": "0xe17a6a769b20d6e54fdc063d51172074c1fc0102",
"topics": "[0xd6fd4c8e45bf0c70693141c7ce46451b6a6a28ac8386fca2ba914044e0e23916, 0xfe036d9d54657dd5301ed52b36f65c65cb6e29feb0a70367c8f8900c247467b9]"
}
],
"poststate": "0x5483317a79cf26615702fae674ffc818d830cdc0a5ca8d1ec1848d101caa3457",
"result": "0x0000000000000000000000000000000000000000000000000000000000000001",
"txhash": "0x1783a4aee339a337c5eb2c040fe6503529f1e49bb023a93ad3d38dc1c28c66f6"
}
getbalance is use to getting the balance in the account
-
address
is the address to send transactions to,default is 127.0.0.1:8027 -
account
is the account address in hexadecimal format
remaining balance
swap getbalance --account 0x0a57a2714e193b7ac50475ce625f2dcfb483d741 --address 127.0.0.1:8027
{
"Account": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",
"Balance": 999599767610
}
help, h is for getting help
Two different Seele chain seele1 and seele2 exchanges Refer to start seele for starting two Seele chains or two shards:
- 1、
swap init --address <ip-port> --fee <int> --from <file> --nonce <number> to deploy contract
swap init --address 127.0.0.1:8027 --fee 100 --from .\keyfile\shard1-0x0a57a2714e193b7ac50475ce625f2dcfb483d741 --nonce 0 to deploy to seele1
swap init --address 127.0.0.1:8028 --fee 100 --from .\keyfile\shard2-0x2a23825407740fa7163069257c57452c4d4fc3d1 --nonce 0 to deploy to seele2
- 2、Both Alice and Bob agreed to initiate the exchange.
Note: Alice and Bob need to have their own address on both the seele1 and seele2.
- Alice executes swap gensecret to generate private key and private key hash value.
swap gensecret
result:
secret hex: 0x261c680e5be606bc023d200f5019d2b63807a05079b431751d606c0bd8b53015
secretHash hex: 0x56915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2
- 3、Alice runs
swap create --address<ip:port> --from <key file> --to <receiver account> --amount <number> --secrethash <secret hash> --fee <number> --nonce <number>
swap create --from .\keyfile\shard1-0x0a57a2714e193b7ac50475ce625f2dcfb483d741 --to 0x025af35f527dfab6ddbdc39da16870e4906e6fe1 --amount 100000000 --secrethash 0x56915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2 --fee 10
- 4、Bob runs
swap getContractById --address <ip:port> --from <key file> --fee <number> --nonce <number> --contractId <hex string>
How to get the contractId? Perform a swap create operation by Alice to return the hash field of the result, execute client getreceipt --hash <hash> on the client
or use swap getreceipt --address <ip:port> --hash <hash>
client getreceipt --hash 0xf9ab3c269e384ce5c2e3bb1a68635672e97e9c5b450af3f652122df19d5e81e0
{
"contract": "0x",
"failed": false,
"logs": [
{
"address": "0xe17a6a769b20d6e54fdc063d51172074c1fc0102",
"data": [
"0x0000000000000000000000000000000000000000000000000000000005f5e100",
"0x56915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2",
"0x000000000000000000000000000000000000000000000000000000005b810495"
],
"topics": "[0x329a8316ed9c3b2299597538371c2944c5026574e803b1ec31d6113e1cd67bde, 0xfe036d9d54657dd5301ed52b36f65c65cb6e29feb0a70367c8f8900c247467b9, 0x0000000000000000000000000a57a2714e193b7ac50475ce625f2dcfb483d741, 0x000000000000000000000000025af35f527dfab6ddbdc39da16870e4906e6fe1]"
}
],
"poststate": "0xfe118c80518c7f0e2b27861035b1e156a0b30e991f45ba3ba3d3b7c079d63304",
"result": "0xfe036d9d54657dd5301ed52b36f65c65cb6e29feb0a70367c8f8900c247467b9",
"txhash": "0xf9ab3c269e384ce5c2e3bb1a68635672e97e9c5b450af3f652122df19d5e81e0"
}
or
swap getreceipt --hash 0xf9ab3c269e384ce5c2e3bb1a68635672e97e9c5b450af3f652122df19d5e81e0
{
"contract": "0x",
"failed": false,
"logs": [
{
"address": "0xe17a6a769b20d6e54fdc063d51172074c1fc0102",
"data": [
"0x0000000000000000000000000000000000000000000000000000000005f5e100",
"0x56915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2",
"0x000000000000000000000000000000000000000000000000000000005b810495"
],
"topics": "[0x329a8316ed9c3b2299597538371c2944c5026574e803b1ec31d6113e1cd67bde, 0xfe036d9d54657dd5301ed52b36f65c65cb6e29feb0a70367c8f8900c247467b9, 0x0000000000000000000000000a57a2714e193b7ac50475ce625f2dcfb483d741, 0x000000000000000000000000025af35f527dfab6ddbdc39da16870e4906e6fe1]"
}
],
"poststate": "0xfe118c80518c7f0e2b27861035b1e156a0b30e991f45ba3ba3d3b7c079d63304",
"result": "0xfe036d9d54657dd5301ed52b36f65c65cb6e29feb0a70367c8f8900c247467b9",
"txhash": "0xf9ab3c269e384ce5c2e3bb1a68635672e97e9c5b450af3f652122df19d5e81e0"
}
The result field is the contractId
run:swap getContractById --from .\keyfile\bob.key
--fee 10 --contractId 0xfe036d9d54657dd5301ed52b36f65c65cb6e29feb0a70367c8f8900c247467b9
result:{
"Hash": "0x5443407e3a865651db3b9dc939174bb0df6ca52f02d0b542d0c1ba6ac8452b35",
"Data": {
"From": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",
"To": "0xe17a6a769b20d6e54fdc063d51172074c1fc0102",
"Amount": 0,
"AccountNonce": 7,
"Fee": 10,
"Timestamp": 0,
"Payload": "0xe16c7d98fe036d9d54657dd5301ed52b36f65c65cb6e29feb0a70367c8f8900c247467b9"
},
"Signature": {
"Sig": "8mu9bArsPcVJunEISF3r8t/WAsKmQ4LQOflj0aNHc/1N4+HXhFe/x3ZdQESr6fHf3Dc3AcQn2UfNI5YXI31rlwA="
}
}
run:swap unpack --hash 0x5443407e3a865651db3b9dc939174bb0df6ca52f02d0b542d0c1ba6ac8452b35
result:{
"Sender": "0x0a57a2714e193b7ac50475ce625f2dcfb483d741",
"Receiver": "0x025af35f527dfab6ddbdc39da16870e4906e6fe1",
"Amount": 100000000,
"Hashlock": "0x56915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2",
"Timelock": 1535181973,
"Withdrawn": false,
"Refunded": false,
"Preimage": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
Bob verifies the above information, whether if the receiver is its own address, the amount is agreed by both parties, the hashlock is the value that Alice tells Bob, the timelock is about 48 hours from the moment, the withdrawal is false, the refund is false, and whether preimage is 0
- 5、If Bob verifies that the data matches in step 4, Bob creates a transaction in another chain (seele2 chain).
swap participate --address <ip:port> --from <key file> --to <receiver account> --secrethash <secret hash> --fee <number> --nonce <number>
run:
swap participate --address 127.0.0.1:8028 --from .\keyfile\shard2-0x007d1b1ea335e8e4a74c0be781d828dc7db934b1 --to 0x55a60155b5b10d423701be281774f606a61c3d01 --amount 100000000 --secrethash 0x56915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2 --fee 10
result:
{
"Hash": "0xe530e9eb1cfbcfe7ecb36345218577e6c0abbdeca50e8146918487b400401022",
"Data": {
"From": "0x007d1b1ea335e8e4a74c0be781d828dc7db934b1",
"To": "0x7220b2dcb83d8a2f844ea0464bd58e56d1ba0102",
"Amount": 100000000,
"AccountNonce": 2,
"Fee": 10,
"Timestamp": 0,
"Payload": "0x335ef5bd00000000000000000000000055a60155b5b10d423701be281774f606a61c3d0156915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2000000000000000000000000000000000000000000000000000000005b7fb91e"
},
"Signature": {
"Sig": "kjvf/525AJddpaB85sC9IX1veitdZVQsG8i9Sc03i5kJ8+pIqLiCdNwVv6el6Uq/zohUX04LPbeRcF1HqdNwbwE="
}
}
- 6、Alice also wants to see if the data matches
client getreceipt --hash 0xe530e9eb1cfbcfe7ecb36345218577e6c0abbdeca50e8146918487b400401022
{
"contract": "0x",
"failed": false,
"logs": [
{
"address": "0x7220b2dcb83d8a2f844ea0464bd58e56d1ba0102",
"data": [
"0x0000000000000000000000000000000000000000000000000000000005f5e100",
"0x56915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2",
"0x000000000000000000000000000000000000000000000000000000005b7fb91e"
],
"topics": "[0x329a8316ed9c3b2299597538371c2944c5026574e803b1ec31d6113e1cd67bde, 0x2259ed93f1781758502609efa0179cd66d988bf1549420ee25a8e726a51fad31, 0x000000000000000000000000007d1b1ea335e8e4a74c0be781d828dc7db934b1, 0x00000000000000000000000055a60155b5b10d423701be281774f606a61c3d01]"
}
],
"poststate": "0x3c6c45afc28245d89e81ffb5522cbd70e1828d4e94b1764a1843423966794f0c",
"result": "0x2259ed93f1781758502609efa0179cd66d988bf1549420ee25a8e726a51fad31",
"txhash": "0xe530e9eb1cfbcfe7ecb36345218577e6c0abbdeca50e8146918487b400401022"
}
or
swap getreceipt --hash 0xe530e9eb1cfbcfe7ecb36345218577e6c0abbdeca50e8146918487b400401022
{
"contract": "0x",
"failed": false,
"logs": [
{
"address": "0x7220b2dcb83d8a2f844ea0464bd58e56d1ba0102",
"data": [
"0x0000000000000000000000000000000000000000000000000000000005f5e100",
"0x56915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2",
"0x000000000000000000000000000000000000000000000000000000005b7fb91e"
],
"topics": "[0x329a8316ed9c3b2299597538371c2944c5026574e803b1ec31d6113e1cd67bde, 0x2259ed93f1781758502609efa0179cd66d988bf1549420ee25a8e726a51fad31, 0x000000000000000000000000007d1b1ea335e8e4a74c0be781d828dc7db934b1, 0x00000000000000000000000055a60155b5b10d423701be281774f606a61c3d01]"
}
],
"poststate": "0x3c6c45afc28245d89e81ffb5522cbd70e1828d4e94b1764a1843423966794f0c",
"result": "0x2259ed93f1781758502609efa0179cd66d988bf1549420ee25a8e726a51fad31",
"txhash": "0xe530e9eb1cfbcfe7ecb36345218577e6c0abbdeca50e8146918487b400401022"
}
the result field is contractId
run:
swap getContractById --address 127.0.0.1:8028 --from .\keyfile\alice.key --fee 10 --contractId 0x2259ed93f1781758502609efa0179cd66d988bf1549420ee25a8e726a51fad31
{
"Hash": "0xa05115d9bb67fde01790e89d0db89d7611044d40720b5dd486748350d7da59d6",
"Data": {
"From": "0x007d1b1ea335e8e4a74c0be781d828dc7db934b1",
"To": "0x7220b2dcb83d8a2f844ea0464bd58e56d1ba0102",
"Amount": 0,
"AccountNonce": 3,
"Fee": 10,
"Timestamp": 0,
"Payload": "0xe16c7d982259ed93f1781758502609efa0179cd66d988bf1549420ee25a8e726a51fad31"
},
"Signature": {
"Sig": "CKpR9TmzBE+YLCu36obL5iaQTNpcNYBy7c7ViGxUR1VzpT9ON0Em2WvNdtJqOvAsXMk0oWYote+VzdGEtF00FwE="
}
}
run:
swap unpack --hash 0xa05115d9bb67fde01790e89d0db89d7611044d40720b5dd486748350d7da59d6 --address 127.0.0.1:8028
{
"Sender": "0x007d1b1ea335e8e4a74c0be781d828dc7db934b1",
"Receiver": "0x55a60155b5b10d423701be281774f606a61c3d01",
"Amount": 100000000,
"Hashlock": "0x56915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2",
"Timelock": 1535097118,
"Withdrawn": false,
"Refunded": false,
"Preimage": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
Alice checks the above information, check if the receiver is its own address, the amount is agreed by both parties, the hashlock is the value that Alice tells Bob, the timelock is about 24 hours from the moment, the withdrawal is false, the refund is false, and preimage is 0
- 7、Alice gets the Seele token from the transaction initiated by Bob (seele2 chain)
swap withdraw --from .\bob.key --secret 0x261c680e5be606bc023d200f5019d2b63807a05079b431751d606c0bd8b53015 --fee 10 --contractId 0xfe036d9d54657dd5301ed52b36f65c65cb6e29feb0a70367c8f8900c247467b9 --address 127.0.0.1:8027
{
"Hash": "0x1783a4aee339a337c5eb2c040fe6503529f1e49bb023a93ad3d38dc1c28c66f6",
"Data": {
"From": "0x025af35f527dfab6ddbdc39da16870e4906e6fe1",
"To": "0xe17a6a769b20d6e54fdc063d51172074c1fc0102",
"Amount": 0,
"AccountNonce": 0,
"Fee": 10,
"Timestamp": 0,
"Payload": "0x63615149fe036d9d54657dd5301ed52b36f65c65cb6e29feb0a70367c8f8900c247467b9261c680e5be606bc023d200f5019d2b63807a05079b431751d606c0bd8b53015"
},
"Signature": {
"Sig": "OpXcAlayQznHg6Um+5jCp19OOoFkwGdz0iFN+4IfrSh2SwEu95Ep04PczF69BtYIN77lHgsZiD7G79Cp4LmCxgA="
}
}
client getreceipt --hash 0x1783a4aee339a337c5eb2c040fe6503529f1e49bb023a93ad3d38dc1c28c66f6 view execution result
or
swap getreceipt --hash 0x1783a4aee339a337c5eb2c040fe6503529f1e49bb023a93ad3d38dc1c28c66f6 view execution result
client getbalance --address <ip:port> --account <receiver account>
client getbalance --address 127.0.0.1:8028 --account 0x55a60155b5b10d423701be281774f606a61c3d01
or
swap getbalance --address 127.0.0.1:8028 --account 0x55a60155b5b10d423701be281774f606a61c3d01
{
"Account": "0x55a60155b5b10d423701be281774f606a61c3d01",
"Balance": 199998990
}
By checking balance, Alice found Seele tokens are in the account.
- 8、Bob needs to see the results of Alice's withdrawal to get the secret.
swap getContractById --address 127.0.0.1:8028 --from .\keyfile\alice.key --fee 10 --contractId 0x2259ed93f1781758502609efa0179cd66d988bf1549420ee25a8e726a51fad31
{
"Hash": "0x11ea4062ce87fb97a20206d0695ad8dbe270b4fa392ae6e1e3de0af7761dc0aa",
"Data": {
"From": "0x007d1b1ea335e8e4a74c0be781d828dc7db934b1",
"To": "0x7220b2dcb83d8a2f844ea0464bd58e56d1ba0102",
"Amount": 0,
"AccountNonce": 7,
"Fee": 10,
"Timestamp": 0,
"Payload": "0xe16c7d982259ed93f1781758502609efa0179cd66d988bf1549420ee25a8e726a51fad31"
},
"Signature": {
"Sig": "FrWbEspQQ+u9dfSxq612JgRlAC1zSXjgitfwiHXbf8xFNZ0i/2LiKDlEXo+pYioVitCbnQVJu0tVrPSy5ugyuwE="
}
}
swap unpack --hash 0x11ea4062ce87fb97a20206d0695ad8dbe270b4fa392ae6e1e3de0af7761dc0aa --address 127.0.0.1:8028
{
"Sender": "0x007d1b1ea335e8e4a74c0be781d828dc7db934b1",
"Receiver": "0x55a60155b5b10d423701be281774f606a61c3d01",
"Amount": 100000000,
"Hashlock": "0x56915589f4cb70dbb631009f3f073e456eea72e7ecbd9238b6b93cfcd9f844c2",
"Timelock": 1535097118,
"Withdrawn": true,
"Refunded": false,
"Preimage": "0x261c680e5be606bc023d200f5019d2b63807a05079b431751d606c0bd8b53015"
}
preimage field is the secret
-
10、Bob uses the secret obtained above to get the tokens from the transaction initiated by Alice (seele1 chain), the operation steps are the same as 7
-
11、Note that if Alice and Bob do not use the withdraw to obtain the Seele tokens within the specified time, then after the lock time of the timelock (alice is 48 hours, Bob is 24 hours), the tokens could be locked by the refund command.
swap refund --from .\alice.key --fee 10 --address 127.0.0.1:8027 --contractId 0xfe036d9d54657dd5301ed52b36f65c65cb6e29feb0a70367c8f8900c247467b9
{
"Hash": "0xdf4fece572d1801b4447e3f443c1450310179074a2c0f44316b1cccc185bf728",
"Data": {
"From": "0x55a60155b5b10d423701be281774f606a61c3d01",
"To": "0x7220b2dcb83d8a2f844ea0464bd58e56d1ba0102",
"Amount": 0,
"AccountNonce": 1,
"Fee": 10,
"Timestamp": 0,
"Payload": "0x7249fbb62259ed93f1781758502609efa0179cd66d988bf1549420ee25a8e726a51fad31"
},
"Signature": {
"Sig": "40qXsNEmaTh+1tuYPP5fDxC9BowEMCpBTthmwnLrNhZVj8Av+sOp0EYNLP3dtnjG7/dAePBGUzLj3XEsEjb3JQE="
}
}
swap refund --from .\bob.key --fee 10 --address 127.0.0.1:8027 --contractId 0x2259ed93f1781758502609efa0179cd66d988bf1549420ee25a8e726a51fad31
{
"Hash": "0xdf4fece572d1801b4447e3f443c1450310179074a2c0f44316b1cccc185bf728",
"Data": {
"From": "0x55a60155b5b10d423701be281774f606a61c3d01",
"To": "0x7220b2dcb83d8a2f844ea0464bd58e56d1ba0102",
"Amount": 0,
"AccountNonce": 1,
"Fee": 10,
"Timestamp": 0,
"Payload": "0x7249fbb62259ed93f1781758502609efa0179cd66d988bf1549420ee25a8e726a51fad31"
},
"Signature": {
"Sig": "40qXsNEmaTh+1tuYPP5fDxC9BowEMCpBTthmwnLrNhZVj8Av+sOp0EYNLP3dtnjG7/dAePBGUzLj3XEsEjb3JQE="
}
}
You could view the contract execution result by the command: client getreceipt --address <ip:port> --hash <hash>
or swap getreceipt --address <ip:port> --hash <hash>
to view the contract execution