/
exchangesda_internal.go
85 lines (68 loc) · 2.43 KB
/
exchangesda_internal.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
// Copyright 2022 ProximaX Limited. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package sdk
import "fmt"
type sdaOfferBalanceDTO struct {
MosaicIdGive uint64DTO `json:"mosaicIdGive"`
MosaicIdGet uint64DTO `json:"mosaicIdGet"`
CurrentAmountGive uint64DTO `json:"currentMosaicGiveAmount"`
CurrentAmountGet uint64DTO `json:"currentMosaicGetAmount"`
InitialAmountGive uint64DTO `json:"initialMosaicGiveAmount"`
InitialAmountGet uint64DTO `json:"initialMosaicGetAmount"`
Owner string `json:"owner"`
Deadline uint64DTO `json:"deadline"`
}
type sdaOfferBalanceDTOs []*sdaOfferBalanceDTO
func (ref *sdaOfferBalanceDTOs) toStruct(networkType NetworkType) ([]*SdaOfferBalance, error) {
var (
dtos = *ref
offers = make([]*SdaOfferBalance, len(*ref))
)
for i, dto := range dtos {
owner, err := NewAccountFromPublicKey(dto.Owner, networkType)
if err != nil {
return nil, err
}
mosaicIdGive, err := NewMosaicId(dto.MosaicIdGive.toUint64())
if err != nil {
return nil, err
}
mosaicIdGet, err := NewMosaicId(dto.MosaicIdGet.toUint64())
if err != nil {
return nil, err
}
offers[i] = &SdaOfferBalance{
Owner: owner,
MosaicGive: newMosaicPanic(mosaicIdGive, dto.CurrentAmountGive.toStruct()),
MosaicGet: newMosaicPanic(mosaicIdGet, dto.CurrentAmountGet.toStruct()),
InitialAmountGive: dto.InitialAmountGive.toStruct(),
InitialAmountGet: dto.InitialAmountGet.toStruct(),
Deadline: dto.Deadline.toStruct(),
}
}
return offers, nil
}
type sdaExchangeDTO struct {
ExchangeSda struct {
Owner string `json:"owner"`
SdaOfferBalances sdaOfferBalanceDTOs `json:"sdaOfferBalances"`
} `json:"exchangesda"`
}
func (ref *sdaExchangeDTO) toStruct(networkType NetworkType) (*UserSdaExchangeInfo, error) {
sdaExchangeInfo := UserSdaExchangeInfo{}
owner, err := NewAccountFromPublicKey(ref.ExchangeSda.Owner, networkType)
if err != nil {
return nil, err
}
for _, dto := range ref.ExchangeSda.SdaOfferBalances {
dto.Owner = owner.PublicKey
}
offers, err := ref.ExchangeSda.SdaOfferBalances.toStruct(networkType)
if err != nil {
return nil, fmt.Errorf("sdk.sdaExchangeDTO.toStruct ExchangeSda.SdaOfferBalances.toStruct: %v", err)
}
sdaExchangeInfo.Owner = owner
sdaExchangeInfo.SdaOfferBalances = offers
return &sdaExchangeInfo, nil
}