-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers_templates.go
136 lines (123 loc) · 6.09 KB
/
helpers_templates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package cmds
import (
"github.com/spf13/cobra"
"github.com/transmutate-io/atomicswap/cryptos"
"github.com/transmutate-io/atomicswap/internal/cmdutil"
"github.com/transmutate-io/atomicswap/internal/flagutil/exitcodes"
"github.com/transmutate-io/atomicswap/internal/tplutil"
"github.com/transmutate-io/atomicswap/trade"
"github.com/transmutate-io/cryptocore/types"
)
var (
cryptosListTemplates = []string{
"{{ .Name }}\n",
"{{ .Name }}, {{ .Short }}\n",
"{{ .Name }}, {{ .Short }}, {{ .Decimals }} decimal places\n",
"{{ .Name }}, {{ .Short }}, {{ .Decimals }} decimal places, {{ .Type }}\n",
}
watchableTradesTemplates = []string{
`{{ .name }}: {{ $s := .trade.Stager.Stage.String }}{{ if eq $s "lock-funds" -}}
wait for own funds deposit
{{- else if or (eq $s "send-proposal-response") (eq $s "wait-locked-funds") -}}
wait for trader funds deposit
{{- else -}}
wait for secret token (trader redeem)
{{- end }}
`,
}
blockInspectionTemplates = []string{
"",
"inspecting block at height {{ .height }}\n",
"inspecting block at height {{ .height }} ({{ .txCount }} transactions)\n",
}
depositChunkLogTemplates = []string{
`{{ if ne .prefix "" }}{{ .prefix }}: {{ end -}}
{{ .id }} {{ .amount }} {{ .crypto.Short }}
`,
`{{ if ne .prefix "" }}{{ .prefix }}: {{ end -}}
{{ .id }} {{ .amount }} {{ .crypto.Short }} ({{ .total }} {{.crypto.Short }} total)
`,
`{{ if ne .prefix "" }}{{ .prefix }}: {{ end -}}
{{ .id }} {{ .amount }} {{ .crypto.Short }} ({{ .total }} of {{ .target }} {{.crypto.Short }})
`,
}
tradeListTemplates = []string{
"{{ .name }}\n",
"{{ .name }} - {{ .trade.OwnInfo.Amount }} {{ .trade.OwnInfo.Crypto.Short }} for {{ .trade.TraderInfo.Amount }} {{ .trade.TraderInfo.Crypto.Short }}\n",
"{{ .name }} - {{ .trade.OwnInfo.Amount }} {{ .trade.OwnInfo.Crypto.Short }} (locked for {{ .trade.Duration.String }}) for {{ .trade.TraderInfo.Amount }} {{ .trade.TraderInfo.Crypto.Short }}\n",
"{{ .name }} - {{ .trade.OwnInfo.Amount }} {{ .trade.OwnInfo.Crypto.Short }} (locked for {{ .trade.Duration.String }}) for {{ .trade.TraderInfo.Amount }} {{ .trade.TraderInfo.Crypto.Short }} - {{ .trade.Stager.Stage }}\n",
}
lockSetInfoTemplates = []string{
`hash: {{ if ne .buyer.lockData.TokenHash.Hex .seller.lockData.TokenHash.Hex }}mis{{ end }}match
buyer:
recovery key data: {{ if ne .buyer.lockData.RecoveryKeyData.Hex .trade.RecoveryKey.Public.KeyData.Hex }}mis{{ end }}match
time lock expiry: {{ .buyer.lockData.LockTime.UTC }} (in {{ .buyer.lockData.LockTime.UTC.Sub now.UTC }})
time lock expiry: {{ .buyer.lockData.LockTime.UTC }} (in {{ .buyer.lockData.LockTime.UTC.Sub now.UTC }})
seller:
redeem key data: {{ if ne .seller.lockData.RedeemKeyData.Hex .trade.RedeemKey.Public.KeyData.Hex }}mis{{ end }}match
time lock expiry: {{ .seller.lockData.LockTime.UTC }} (in {{ .seller.lockData.LockTime.UTC.Sub now.UTC }}, {{ .buyer.lockData.LockTime.UTC.Sub .seller.lockData.LockTime.UTC }} before buyer)
`,
`hash: {{ if ne .buyer.lockData.TokenHash.Hex .seller.lockData.TokenHash.Hex }}mis{{ end }}match
buyer:
deposit address: {{ .buyer.depositAddr }}
redeem key data: {{ .buyer.lockData.RedeemKeyData.Hex }}
recovery key data: {{ if ne .buyer.lockData.RecoveryKeyData.Hex .trade.RecoveryKey.Public.KeyData.Hex }}mis{{ end }}match
time lock expiry: {{ .buyer.lockData.LockTime.UTC }} (in {{ .buyer.lockData.LockTime.UTC.Sub now.UTC }})
seller:
deposit address: {{ .seller.depositAddr }}
redeem key data: {{ if ne .seller.lockData.RedeemKeyData.Hex .trade.RedeemKey.Public.KeyData.Hex }}mis{{ end }}match
recovery key data: {{ .seller.lockData.RecoveryKeyData.Hex }}
time lock expiry: {{ .seller.lockData.LockTime.UTC }} (in {{ .seller.lockData.LockTime.UTC.Sub now.UTC }}, {{ .buyer.lockData.LockTime.UTC.Sub .seller.lockData.LockTime.UTC }} before buyer)
`,
`hash: {{ if ne .buyer.lockData.TokenHash.Hex .seller.lockData.TokenHash.Hex }}mis{{ end }}match
buyer:
deposit address: {{ .buyer.depositAddr}} ({{ .buyer.chain }})
redeem key data: {{ .buyer.lockData.RedeemKeyData.Hex }}
recovery key data: {{ if ne .buyer.lockData.RecoveryKeyData.Hex .trade.RecoveryKey.Public.KeyData.Hex }}mis{{ end }}match ({{ .buyer.lockData.RecoveryKeyData.Hex }}, {{ .trade.RecoveryKey.Public.KeyData.Hex }})
time lock expiry: {{ .buyer.lockData.LockTime.UTC }} (in {{ .buyer.lockData.LockTime.UTC.Sub now.UTC }})
seller:
deposit address: {{ .seller.depositAddr }} ({{ .seller.chain }})
redeem key data: {{ if ne .seller.lockData.RedeemKeyData.Hex .trade.RedeemKey.Public.KeyData.Hex }}mis{{ end }}match ({{ .seller.lockData.RedeemKeyData.Hex }}, {{ .trade.RedeemKey.Public.KeyData.Hex }})
recovery key data: {{ .seller.lockData.RecoveryKeyData.Hex }}
time lock expiry: {{ .seller.lockData.LockTime.UTC }} (in {{ .seller.lockData.LockTime.UTC.Sub now.UTC }}, {{ .buyer.lockData.LockTime.UTC.Sub .seller.lockData.LockTime.UTC }} before buyer)
`,
}
)
func newOutputInfo(prefix string, id string, crypto *cryptos.Crypto, amount, total, target types.Amount) tplutil.TemplateData {
return tplutil.TemplateData{
"prefix": prefix,
"id": id,
"crypto": crypto,
"amount": amount,
"total": total,
"target": target,
}
}
func newBlockInfo(height uint64, txCount int) tplutil.TemplateData {
return tplutil.TemplateData{"height": height, "txCount": txCount}
}
func newTradeInfo(name string, trade trade.Trade) tplutil.TemplateData {
return tplutil.TemplateData{"name": name, "trade": trade}
}
func newLockInfo(l trade.Lock, c *cryptos.Crypto) (tplutil.TemplateData, error) {
chain := _network.MustNetwork(c.Name)
addr, err := l.Address(chain)
if err != nil {
return nil, err
}
ld, err := l.LockData()
if err != nil {
return nil, err
}
return tplutil.TemplateData{"depositAddr": addr, "chain": chain, "lockData": ld}, nil
}
func mustNewLockInfo(cmd *cobra.Command, l trade.Lock, c *cryptos.Crypto) tplutil.TemplateData {
r, err := newLockInfo(l, c)
if err != nil {
cmdutil.ErrorExit(exitcodes.InvalidLockData, err)
}
return r
}
func newLockSetInfo(trade trade.Trade, buyer, seller tplutil.TemplateData) tplutil.TemplateData {
return tplutil.TemplateData{"trade": trade, "buyer": buyer, "seller": seller}
}