shuttleを使用してbytom上のチェーン間資産交換を実現

10730 ワード

最近、元のチェーン上の異なる資産交換ツールshuttleに基づいて注目されています.このツールは、同じチェーン上の異なる資産の交換だけでなく、異なるブロックチェーンプラットフォーム上の複数の資産の交換も実現できるからです.このツールは資産が取引の過程で完全に中心化され、第三者の介入がなく、資産の交換過程における安全性と原子性を保証した.では、このツールの使い方を見てみましょう.
このツールの主な機能は、異なる資産を元のチェーンで交換することであり、まず元のチェーンで異なる資産を交換することである.これは主に貨幣交換契約を用いて資産の交換を行う.従来のプライマリ・サイド・チェーン上でチェーン間資産交換を行う場合、ハッシュ・タイム・ロック契約を使用して2つの異なるチェーン上の資産交換を完了します.
次に、操作の具体的な手順を見てみましょう.
第一歩:まずノード環境を構築する
1.1 golangのバージョンは1.12より高く、$GOPATH環境ディレクトリも設定されています.
1.2 bytomノードを起動して配置し、参考:bytom readme.md
1.3ソースコード構築:Shuttleはまだテストフェーズにあるため、リポジトリコードは常に変更されます.ソースコードからツールを直接構築できます.次のコマンドを参照してください.
 $ git clone https://github.com/Bytom/shuttle.git $GOPATH/src/github.com/shuttle
 $ cd $GOPATH/src/github.com/shuttle
 $ make install

Shuttle help関連コマンドは次のとおりです.
 $ swap -h
 swap is a commond line client for bytom contract

 Usage:
   swap [flags]
   swap [command]

vailable Commands:
  callHTLC       call HTLC contract for asset swapping
  callTradeoff   call tradeoff contract for asset swapping
  cancelHTLC     cancel HTLC contract for asset swapping
  cancelTradeoff cancel tradeoff contract for asset swapping
  deployHTLC     deploy HTLC contract
  deployTradeoff deploy tradeoff contract
  help           Help about any command

Flags:
  -h, --help   help for swap

Use "swap [command] --help" for more information about a command.



ステップ2:同じチェーン上でチェーン間資産交換を行う
単一のチェーンで元の資産と交換したい場合は、bytomプライマリチェーンでもvaporサイドチェーンでも、Tradeoff契約を直接使用して資産の交換を実現します.交換フローチャート全体は次のとおりです.
まずbytomノードを起動し、テストのためにsolnetノードを起動することができます.
$ bytomd init --chain_id=solonet --home $HOME/bytom/solonet # init bytom solonet node
$ bytomd node --home $HOME/bytom/solonet --mining           # launch bytom solonet node and start mining

テストノードを構築した後、ブロックチェーンにアカウントを作成し、資産(issue asset)を発行してテストすることができます.
アカウントリファレンスの作成
資産参照の発行
例えば、bytomプライマリチェーンでは、アカウントAは200 BTC、アカウントBは10 BTMであり、shuttleツールで交換することができる.
2.1 tradeoff契約の正式な導入(契約導入関連コマンドおよび関連パラメータ)
$ swap deployTradeoff -h
deploy tradeoff contract

Usage:
swap deployTradeoff   [contract flags(paramenters and locked value)] [txFee flag] [URL flags(ip and port)] [flags]

Flags:
     --amountLocked uint       tradeoff contract locked value with amount //       
     --amountRequested uint    tradeoff contract paramenter with requested amount  //           
     --assetLocked string      tradeoff contract locked value with assetID //  ID
     --assetRequested string   tradeoff contract paramenter with requested assetID //     ID
     --cancelKey string        tradeoff contract paramenter with seller pubkey for cancelling the contract //         pubkey
 -h, --help                    help for deployTradeoff
     --ip string               network address (default "127.0.0.1")
     --port string             network port (default "9888")
     --seller string           tradeoff contract paramenter with seller control-program
     --txFee uint              contract transaction fee (default 40000000)


次に、導入契約をインスタンス化する手順を示します.
$ swap deployTradeoff 10CJPO1HG0A02 12345 --amountLocked 20000000000 --amountRequested 1000000000 --assetLocked bae7e17bb8f5d0cfbfd87a92f3204da082d388d4c9b10e8dcd36b3d0a18ceb3a --assetRequested ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff --cancelKey 3e5d7d52d334964eef173021ef6a04dc0807ac8c41700fe718f5a80c2109f79e --seller 00145dd7b82556226d563b6e7d573fe61d23bd461c1f --txFee 40000000
--> contractUTXOID: 34996b0838108de8c614bc018e8fdbbfc08a47ffbe0fd6d7f41892b90de3999f

契約の配置が完了した後、2.5分後、元のチェーンの新しいブロックよりも鉱夫に梱包された後、配置された契約が認証されます.
2.2 tradeoff契約の呼び出し(以下、契約を呼び出すコマンド)
$ swap callTradeoff -h
call tradeoff contract for asset swapping

Usage:
swap callTradeoff     [txFee flag] [URL flags(ip and port)] [flags]

Flags:
-h, --help          help for callTradeoff
  --ip string     network address (default "127.0.0.1")
  --port string   network port (default "9888")
  --txFee uint    contract transaction fee (default 40000000)
  

呼び出し契約のインスタンス化パラメータは次のとおりです.
 $ swap callTradeoff 10CKAD3000A02 12345 00140fdee108543d305308097019ceb5aec3da60ec66 34996b0838108de8c614bc018e8fdbbfc08a47ffbe0fd6d7f41892b90de3999f
 --> txID: 55e43274d2d92504a903a13e3f6517d63434fc19a2fa0e1fc0a9a5c8c75e8f6c
 

呼び出しが完了すると、取引が新しいブロックで確認されると、資産交換プロセス全体が完了します.以下の図です.
交換完了後、現在口座Aは200 BTC、口座Bは10 BTMとなっている.
2.3 tradeoff契約の取消し(以下tradeoff契約の取消しに関する命令)
tradeoff契約取引をキャンセルしたい人がいる場合は、次のようにコマンドを呼び出してキャンセルできます.
$ swap cancelTradeoff -h
cancel tradeoff contract for asset swapping

Usage:
swap cancelTradeoff     [txFee flag] [URL flags(ip and port)] [flags]

Flags:
-h, --help          help for cancelTradeoff
   --ip string     network address (default "127.0.0.1")
   --port string   network port (default "9888")
   --txFee uint    contract transaction fee (default 40000000)
   

tradeoff契約の取り消しのインスタンス化は、次のとおりです.
 $ swap deployTradeoff 10CJPO1HG0A02 12345 --amountLocked 20000000000 --amountRequested 1000000000 --assetLocked bae7e17bb8f5d0cfbfd87a92f3204da082d388d4c9b10e8dcd36b3d0a18ceb3a --assetRequested ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff --cancelKey 3e5d7d52d334964eef173021ef6a04dc0807ac8c41700fe718f5a80c2109f79e --seller 00145dd7b82556226d563b6e7d573fe61d23bd461c1f --txFee 40000000
  --> contractUTXOID: e898ea907f8586b3211a46b69d0cddd363f8a850f559656570eb6afc6ac382c5

 $ swap cancelTradeoff 10CJPO1HG0A02 12345 00145b0a81adc5c2d68a9967082a09c96e82d62aa058  e898ea907f8586b3211a46b69d0cddd363f8a850f559656570eb6afc6ac382c5  
 --> txID: 0f75db743196b8b2e514c49d6483dfba9bd5ab8e913a7559ecaea0324977313f

以下の例を示します.
上記のプロセス全体は、同じチェーン上で異なる資産を交換するプロセス全体であり、bytomとvaporを例に挙げると、異なるチェーン上の2つの資産を交換するプロセスを見てみましょう.
ステップ3:異なるチェーン上の資産を交換する
このツールを使用してbytomとvaporで資産を交換できます.
3.1 bytomノードとvaporノードの構築と起動
テストを容易にするために.bytomとvaporのsolonetノードを起動できます
bytom solonetノードを起動するには、次の手順に従います.
$ bytomd init --chain_id=solonet --home $HOME/bytom/solonet # init bytom   solonet node
$ bytomd node --home $HOME/bytom/solonet --mining           # launch bytom solonet node and start mining

vapor solonetノードを起動するには、次の手順に従います.
$ vapord init --chain_id=solonet --home $HOME/bytom/vapor-solonet # init vapor solonet node
$ vapord node --home $HOME/bytom/vapor-solonet --mining           # launch vapor solonet node and start mining


3.2 HTLC契約の配置(契約の配置命令は以下の通り)
 $ swap deployHTLC -h
 deploy HTLC contract

 Usage:
 swap deployHTLC   [contract flags(paramenters and locked value)] [txFee flag] [URL flags(ip and port)] [flags]

 Flags:
  --amountLocked uint    HTLC contract locked value with amount
  --assetLocked string   HTLC contract locked value with assetID
  --blockHeight uint     HTLC contract locked value with blockHeight
  --hash string          HTLC contract locked value with hash
-h, --help                 help for deployHTLC
  --ip string            network address (default "127.0.0.1")
  --port string          network port (default "9888")
  --recipient string     HTLC contract paramenter with recipientPublicKey
  --sender string        HTLC contract paramenter with sender PublicKey
  --txFee uint           contract transaction fee (default 40000000)


HTLC契約の導入例のパラメータは次のとおりです.
 $ swap deployHTLC 11BB7TC8G0A02 12345 --sender 7262584844d4c14f512d1b6c9838e62c320e1d7887e7185bfea920c72a944e44 --recipient 562013c2f9082f1db52a2571034428921dd6eec8c010c2b2387f5b6125ff4aa7 --blockHeight 1200 --hash 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 --assetLocked bae7e17bb8f5d0cfbfd87a92f3204da082d388d4c9b10e8dcd36b3d0a18ceb3a --amountLocked 20000000000
 --> contractUTXOID: e1b104a03f4135b45d1c4c5fabbdca4dd0555653a588b71d790d45c4ffb2c50e
 
 

3.3 HTLC契約の呼び出し
$ swap callHTLC -h
call HTLC contract for asset swapping

Usage:
swap callHTLC      [txFee flag] [URL flags(ip and port)] [flags]

Flags:
 -h, --help          help for callHTLC
   --ip string     network address (default "127.0.0.1")
   --port string   network port (default "9888")
   --txFee uint    contract transaction fee (default 40000000)
   

HTLC契約を呼び出す実力化パラメータは以下の通りです.
$ swap callHTLC 11BB86V300A04 12345 0014230cb75fcfcc70c580ce7f1d21c1e374d27334a8 68656c6c6f e1b104a03f4135b45d1c4c5fabbdca4dd0555653a588b71d790d45c4ffb2c50e
--> txID: df57b7906684e3d85adf59073ccbc0a3c5114b165626e9791f3269e9e57c319e

実際の交換プロセスは次のとおりです.
3.4 HTLC契約の取り消し(命令パラメータは以下の通り)
$ swap cancelHTLC -h
cancel HTLC contract for asset swapping

Usage:
swap cancelHTLC     [txFee flag] [URL flags(ip and port)] [flags]

Flags:
-h, --help          help for cancelHTLC
  --ip string     network address (default "127.0.0.1")
  --port string   network port (default "9888")
  --txFee uint    contract transaction fee (default 40000000)
  

HTLC契約の取り消しの実例化パラメータは以下の通りです.
$ swap deployHTLC 11BB7TC8G0A02 12345 --sender 7262584844d4c14f512d1b6c9838e62c320e1d7887e7185bfea920c72a944e44 --recipient 562013c2f9082f1db52a2571034428921dd6eec8c010c2b2387f5b6125ff4aa7 --blockHeight 1200 --hash 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 --assetLocked bae7e17bb8f5d0cfbfd87a92f3204da082d388d4c9b10e8dcd36b3d0a18ceb3a --amountLocked 20000000000
--> contractUTXOID: 68ed6b948b93544ea135482f1acd93d6b10cdc88f52d44133d264a5ee86b1ebd
$ swap cancelHTLC 11BB7TC8G0A02 12345 001434fec270871c1f3420db85831f59511b2dd2a026 68ed6b948b93544ea135482f1acd93d6b10cdc88f52d44133d264a5ee86b1ebd
--> txID: c70a467e94b287d29c6d91a2cb6f8ef3c7ef4dba315d99acf2dc9ff698996270 

以下の例を示します.
HTLC契約をキャンセルした後、a 4はHTLC契約で両替した資産を自動的に口座に戻す.これらはいずれもa口座のbytomでの操作であり,a 5口座は同時にサイドチェーンで同じ操作を実現すればよい.
ここまでshuttleを使った資産交換の流れは完全に終わりましたので、体験を歓迎します.使用中に何か問題があったら、微信:youths_1994詳細コンサルティング.