OSDN Git Service

7635ee798cfe0335d2ed289f12a906856bc4d56d
[bytom/shuttle.git] / main.go
1 package main
2
3 import (
4         "fmt"
5
6         "github.com/btm-swap-tool/swap"
7 )
8
9 func main() {
10         // balances := swap.ListBalances("a1")
11         // fmt.Println("balances:", balances)
12
13         // accounts := swap.ListAccounts()
14         // fmt.Println("accounts:", accounts)
15
16         // addresses := swap.ListAddresses("a1")
17         // fmt.Println("addresses:", addresses)
18
19         // pubkeyInfo := swap.ListPubkeys("a1")
20         // fmt.Println(pubkeyInfo)
21
22         accountIDLocked := "10CJPO1HG0A02"                                                   // accountIDLocked represents account which create locked contract
23         accountPasswordLocked := "12345"                                                     // accountPasswordLocked represents account password which create locked contract
24         assetRequested := "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" // assetRequested represents asset ID which can unlock contract
25         amountRequested := uint64(1000000000)                                                // amountRequested represents asset amount which can unlock contract
26         seller := "00145dd7b82556226d563b6e7d573fe61d23bd461c1f"                             // control program which want to receive assetRequested
27         cancelKey := "3e5d7d52d334964eef173021ef6a04dc0807ac8c41700fe718f5a80c2109f79e"      // cancelKey can cancel swap contract
28         assetIDLocked := "bae7e17bb8f5d0cfbfd87a92f3204da082d388d4c9b10e8dcd36b3d0a18ceb3a"  // assetIDLocked represents locked asset ID
29         amountLocked := uint64(20000000000)                                                  // amountLocked represents locked asset amount
30         txFee := uint64(50000000)                                                            // txFee represents transaction fee
31
32         accountIDUnlocked := "10CKAD3000A02"                                 // accountIDUnlocked represents account ID which create unlocked contract
33         buyerContolProgram := "00140fdee108543d305308097019ceb5aec3da60ec66" // buyerContolProgram represents buyer control program
34         // accountPasswordUnlocked := "12345"                                   // accountPasswordUnlocked represents account password which create locked contract
35
36         // compile locked contract
37         contractInfo := swap.CompileLockContract(assetRequested, seller, cancelKey, amountRequested)
38         fmt.Println("--> contract info:", contractInfo)
39
40         // build locked contract
41         txLocked := swap.BuildLockTransaction(accountIDLocked, assetIDLocked, contractInfo.Program, amountLocked, txFee)
42         fmt.Println("--> txLocked:", string(txLocked))
43
44         // sign locked contract transaction
45         signedTransaction := swap.SignTransaction(accountPasswordLocked, string(txLocked))
46         fmt.Println("--> signedTransaction:", signedTransaction)
47
48         // submit signed transaction
49         txID := swap.SubmitTransaction(signedTransaction)
50         fmt.Println("--> txID:", txID)
51
52         // get contract output ID
53         contractUTXOID, err := swap.GetContractUTXOID(txID, contractInfo.Program)
54         if err != nil {
55                 fmt.Println(err)
56         }
57         fmt.Println("--> contractUTXOID:", contractUTXOID)
58
59         //
60         // contractUTXOID = "38c0b998f8437aebe2be45e3c1893551ce303ff940fd2fcbb696f003233bdf5b"
61         txUnlocked := swap.BuildUnlockContractTransaction(accountIDUnlocked, contractUTXOID, seller, assetIDLocked, assetRequested, buyerContolProgram, amountRequested, amountLocked, txFee)
62         fmt.Println("--> txUnlocked:", string(txUnlocked))
63 }