forked from omnilaboratory/obd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.go
300 lines (266 loc) · 11.4 KB
/
messages.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
package bean
import (
"github.com/omnilaboratory/obd/bean/chainhash"
"github.com/omnilaboratory/obd/bean/enum"
)
var CurrObdNodeInfo ObdNodeInfo
type ObdNodeInfo struct {
P2pAddress string `json:"p2p_address"`
WebsocketLink string `json:"websocket_link"`
}
//obd客户端请求消息体
type RequestMessage struct {
Type enum.MsgType `json:"type"`
SenderNodePeerId string `json:"sender_node_peer_id"`
SenderUserPeerId string `json:"sender_user_peer_id"`
RecipientUserPeerId string `json:"recipient_user_peer_id"`
RecipientNodePeerId string `json:"recipient_node_peer_id"`
Data string `json:"data"`
}
//obd答复消息体
type ReplyMessage struct {
Type enum.MsgType `json:"type"`
Status bool `json:"status"`
From string `json:"from"`
To string `json:"to"`
Result interface{} `json:"result"`
}
type UserState int
const (
UserState_ErrorState UserState = -1
UserState_Offline UserState = 0
UserState_OnLine UserState = 1
)
//TLV 附加消息
type typeLengthValue struct {
ValueType string `json:"value_type"`
Length int `json:"length"`
Value interface{} `json:"value"`
}
// -100032
type SendChannelOpen struct {
//充值的pubKey
FundingPubKey string `json:"funding_pubkey"`
FunderAddressIndex int `json:"funder_address_index"`
IsPrivate bool `json:"is_private"` // channel is a private channel, can not use htlc hop
typeLengthValue
}
//https://github.com/obdlayer/Omni-BOLT-spec/blob/master/OmniBOLT-03-RSMC-and-OmniLayer-Transactions.md
// type = -32 请求方的obd发给接收方的obd的通道开通请求
// type = -110032 接收方obd发给接收方客户端的消息
type RequestOpenChannel struct {
SendChannelOpen
ChainHash string `json:"chain_hash"`
TemporaryChannelId string `json:"temporary_channel_id"`
FundingSatoshis uint64 `json:"funding_satoshis"`
PushMsat uint64 `json:"push_msat"`
DustLimitSatoshis uint64 `json:"dust_limit_satoshis"`
MaxHtlcValueInFlightMsat uint64 `json:"max_htlc_value_in_flight_msat"`
ChannelReserveSatoshis uint64 `json:"channel_reserve_satoshis"`
HtlcMinimumMsat uint64 `json:"htlc_minimum_msat"`
FeeRatePerKw uint32 `json:"fee_rate_per_kw"`
ToSelfDelay uint16 `json:"to_self_delay"`
MaxAcceptedHtlcs uint16 `json:"max_accepted_htlcs"` //最多可以接受多少给hltc请求 500
FunderNodeAddress string `json:"funder_node_address"`
FunderPeerId string `json:"funder_peer_id"`
FundingAddress string `json:"funding_address"`
RevocationBasePoint chainhash.Point `json:"revocation_base_point"`
PaymentBasePoint chainhash.Point `json:"payment_base_point"`
DelayedPaymentBasePoint chainhash.Point `json:"delayed_payment_base_point"`
HtlcBasePoint chainhash.Point `json:"htlc_base_point"`
}
// -100033 接收方给自己的obd发送回复开通通道的请求
type SendSignOpenChannel struct {
FundingPubKey string `json:"funding_pubkey"`
FundeeAddressIndex int `json:"fundee_address_index"`
TemporaryChannelId string `json:"temporary_channel_id"`
Approval bool `json:"approval"`
typeLengthValue
}
//type: -38 (close_channel)
type CloseChannel struct {
ChannelId string `json:"channel_id"`
typeLengthValue
}
//type: -39 (close_channel_sign)
type CloseChannelSign struct {
ChannelId string `json:"channel_id"`
RequestCloseChannelHash string `json:"request_close_channel_hash"`
Approval bool `json:"approval"` // true agree false disagree
typeLengthValue
}
// type: -100340
type SendRequestFundingBtc struct {
TemporaryChannelId string `json:"temporary_channel_id"`
FundingTxHex string `json:"funding_tx_hex"`
typeLengthValue
}
// type: -340
// type: -110340
type FundingBtcOfP2p struct {
TemporaryChannelId string `json:"temporary_channel_id"`
FundingTxid string `json:"funding_txid"`
FundingBtcHex string `json:"funding_btc_hex"`
FundingRedeemHex string `json:"funding_redeem_hex"`
FunderNodeAddress string `json:"funder_node_address"`
FunderPeerId string `json:"funder_peer_id"`
SignData NeedClientSignHexData `json:"sign_data"`
}
//type: -100350 (SendSignFundingBtc)
type SendSignFundingBtc struct {
TemporaryChannelId string `json:"temporary_channel_id"`
FundingTxid string `json:"funding_txid"`
SignedMinerRedeemTransactionHex string `json:"signed_miner_redeem_transaction_hex"`
Approval bool `json:"approval"`
typeLengthValue
}
// type: -100034
type FundingAssetOfP2p struct {
//临时通道id
TemporaryChannelId string `json:"temporary_channel_id"`
ChannelId string `json:"channel_id"`
//充值hex
FundingOmniHex string `json:"funding_omni_hex"`
C1aRsmcHex string `json:"c1a_rsmc_hex"`
RsmcTempAddressPubKey string `json:"rsmc_temp_address_pub_key"`
SignData NeedClientSignHexData `json:"sign_data"`
FunderNodeAddress string `json:"funder_node_address"`
FunderPeerId string `json:"funder_peer_id"`
}
// -MsgType_Funding_134 100134
type SendRequestFunding struct {
TemporaryChannelId string `json:"temporary_channel_id"`
BtcAmount float64 `json:"btc_amount"`
PropertyId int64 `json:"property_id"`
AssetAmount float64 `json:"asset_amount"`
}
// -100034
type SendRequestAssetFunding struct {
TemporaryChannelId string `json:"temporary_channel_id"`
FundingTxHex string `json:"funding_tx_hex"`
TempAddressIndex int `json:"temp_address_index"`
TempAddressPubKey string `json:"temp_address_pub_key"`
typeLengthValue
}
// -101034
type AliceSignC1aOfAssetFunding struct {
SignedC1aHex string `json:"signed_c1a_hex"`
typeLengthValue
}
//type: -100035 (funding_signed)
type SignAssetFunding struct {
TemporaryChannelId string `json:"temporary_channel_id"`
SignedAliceRsmcHex string `json:"signed_alice_rsmc_hex"`
typeLengthValue
}
//type: -101035 (funding_signed)
type NeedSignRdAndBrOfAssetFunding struct {
TemporaryChannelId string `json:"temporary_channel_id"`
AliceRdSignData map[string]interface{} `json:"alice_rd_sign_data"`
AliceBrSignData map[string]interface{} `json:"alice_br_sign_data"`
}
//type: -101035 (funding_signed)
type SignRdAndBrOfAssetFunding struct {
TemporaryChannelId string `json:"temporary_channel_id"`
BrId int64 `json:"br_id"`
RdSignedHex string `json:"rd_signed_hex"`
BrSignedHex string `json:"br_signed_hex"`
typeLengthValue
}
// -101134
type AliceSignRDOfAssetFunding struct {
ChannelId string `json:"channel_id"`
RdSignedHex string `json:"rd_signed_hex"`
typeLengthValue
}
//51->52
type HtlcCloseCloserSignTxInfoToClosee struct {
ChannelId string `json:"channel_id"`
CloseeSignedRsmcHex string `json:"closee_signed_rsmc_hex"`
CloseeRsmcRdHex string `json:"closee_rsmc_rd_hex"`
CloseeSignedToCounterpartyTxHex string `json:"closee_signed_to_counterparty_tx_hex"`
}
// 付款人的obd发给收款人的obd的消息体 在请求htlc交易 40->41
type AliceRequestAddHtlc struct {
ChannelId string `json:"channel_id"`
Amount float64 `json:"amount"`
RoutingPacket string `json:"routing_packet"`
CltvExpiry int `json:"cltv_expiry"` //发起者设定的总的等待的区块个数
PayerCommitmentTxHash string `json:"payer_commitment_tx_hash"`
Memo string `json:"memo"`
H string `json:"h"`
ToCounterpartyTxHex string `json:"to_counterparty_tx_hex"`
HtlcTxHex string `json:"htlc_tx_hex"`
RsmcTxHex string `json:"rsmc_tx_hex"`
LastTempAddressPrivateKey string `json:"last_temp_address_private_key"`
CurrRsmcTempAddressPubKey string `json:"curr_rsmc_temp_address_pub_key"`
CurrHtlcTempAddressPubKey string `json:"curr_htlc_temp_address_pub_key"`
CurrHtlcTempAddressForHt1aPubKey string `json:"curr_htlc_temp_address_for_ht1a_pub_key"`
PayerNodeAddress string `json:"payer_node_address"`
PayerPeerId string `json:"payer_peer_id"`
}
// p2p消息 收款人的obd发给付款人的obd的消息体 在获得R后
// p2p消息 请求关闭htlc交易
type RequestCloseHtlcTxOfP2p struct {
ChannelId string `json:"channel_id"`
LastRsmcTempAddressPrivateKey string `json:"last_rsmc_temp_address_private_key"`
LastHtlcTempAddressPrivateKey string `json:"last_htlc_temp_address_private_key"`
LastHtlcTempAddressForHtnxPrivateKey string `json:"last_htlc_temp_address_for_htnx_private_key"`
CurrRsmcTempAddressPubKey string `json:"curr_rsmc_temp_address_pub_key"`
RsmcHex string `json:"rsmc_hex"`
ToCounterpartyTxHex string `json:"to_counterparty_tx_hex"`
CommitmentTxHash string `json:"commitment_tx_hash"`
SenderNodeAddress string `json:"sender_node_address"`
SenderPeerId string `json:"sender_peer_id"`
}
// ws消息 收款人的obd发给付款人的obd的消息体 在获得R后
// -110050
type RequestCloseHtlcTxOfWs struct {
RequestCloseHtlcTxOfP2p
MsgHash string `json:"msg_hash"`
}
//type -80: MsgType_Atomic_Swap_80
type AtomicSwapRequest struct {
ChannelIdFrom string `json:"channel_id_from"`
ChannelIdTo string `json:"channel_id_to"`
RecipientUserPeerId string `json:"recipient_user_peer_id"`
PropertySent int64 `json:"property_sent"`
Amount float64 `json:"amount"`
ExchangeRate float64 `json:"exchange_rate"`
PropertyReceived int64 `json:"property_received"`
TransactionId string `json:"transaction_id"`
TimeLocker uint32 `json:"time_locker"`
typeLengthValue
}
//type -81: MsgType_Atomic_Swap_Accept_N81
type AtomicSwapAccepted struct {
AtomicSwapRequest
TargetTransactionId string `json:"target_transaction_id"` // 针对的目标交易id
}
type NeedClientSignHexData struct {
TemporaryChannelId string `json:"temporary_channel_id"`
Hex string `json:"hex"`
Inputs interface{} `json:"inputs"`
IsMultisig bool `json:"is_multisig"`
PubKeyA string `json:"pub_key_a"`
PubKeyB string `json:"pub_key_b"`
TotalInAmount float64 `json:"total_in_amount"`
TotalOutAmount float64 `json:"total_out_amount"`
}
// 正式通道的需要客户端签名的信息体
type NeedClientSignTxData struct {
Hex string `json:"hex"`
Inputs interface{} `json:"inputs"`
IsMultisig bool `json:"is_multisig"`
PubKeyA string `json:"pub_key_a"`
PubKeyB string `json:"pub_key_b"`
PrivateKey string `json:"private_key"`
}
type NeedClientSignRawBRTxData struct {
NeedClientSignTxData
BrId int `json:"br_id"`
}
type RawTxInputItem struct {
ScriptPubKey string `json:"scriptPubKey"`
RedeemScript string `json:"redeem_script"`
}