|
1 | 1 | package fusionplus |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "encoding/hex" |
5 | 4 | "errors" |
6 | 5 | "fmt" |
7 | 6 | "math/big" |
8 | 7 | "sort" |
9 | 8 | "strings" |
10 | 9 |
|
11 | 10 | "github.com/1inch/1inch-sdk-go/internal/bytesbuilder" |
12 | | - "github.com/1inch/1inch-sdk-go/internal/bytesiterator" |
13 | 11 | "github.com/ethereum/go-ethereum/common" |
14 | | - "github.com/ethereum/go-ethereum/common/hexutil" |
15 | 12 | ) |
16 | 13 |
|
17 | 14 | type SettlementPostInteractionData struct { |
@@ -67,104 +64,10 @@ func NewSettlementPostInteractionData(data SettlementSuffixData) (*SettlementPos |
67 | 64 | }, nil |
68 | 65 | } |
69 | 66 |
|
70 | | -func Decode(data string) (SettlementPostInteractionData, error) { |
71 | | - bytes, err := hexutil.Decode(data) |
72 | | - if err != nil { |
73 | | - return SettlementPostInteractionData{}, errors.New("invalid hex string") |
74 | | - } |
75 | | - |
76 | | - flags := big.NewInt(int64(bytes[len(bytes)-1])) |
77 | | - bytesWithoutFlags := bytes[:len(bytes)-1] |
78 | | - |
79 | | - iter := bytesiterator.New(bytesWithoutFlags) |
80 | | - //var bankFee *big.Int |
81 | | - var customReceiver common.Address |
82 | | - |
83 | | - //if flags.Bit(0) == 1 { |
84 | | - // bankFee, err = iter.NextUint32() |
85 | | - // if err != nil { |
86 | | - // return SettlementPostInteractionData{}, err |
87 | | - // } |
88 | | - //} |
89 | | - |
90 | | - if flags.Bit(1) == 1 { |
91 | | - |
92 | | - //ratio, err := iter.NextUint16() |
93 | | - //if err != nil { |
94 | | - // return SettlementPostInteractionData{}, err |
95 | | - //} |
96 | | - // |
97 | | - //receiver, err := iter.NextUint160() |
98 | | - //if err != nil { |
99 | | - // return SettlementPostInteractionData{}, err |
100 | | - //} |
101 | | - // |
102 | | - //integratorFee = &IntegratorFee{ |
103 | | - // Ratio: ratio, |
104 | | - // Receiver: common.HexToAddress(receiver.Text(16)), |
105 | | - //} |
106 | | - |
107 | | - if flags.Bit(2) == 1 { |
108 | | - |
109 | | - customReceiverRaw, err := iter.NextUint160() |
110 | | - if err != nil { |
111 | | - return SettlementPostInteractionData{}, err |
112 | | - } |
113 | | - |
114 | | - customReceiver = common.HexToAddress(customReceiverRaw.Text(16)) |
115 | | - } |
116 | | - } |
117 | | - |
118 | | - resolvingStartTime, err := iter.NextUint32() |
119 | | - if err != nil { |
120 | | - return SettlementPostInteractionData{}, err |
121 | | - } |
122 | | - var whitelist []WhitelistItem |
123 | | - |
124 | | - for !iter.IsEmpty() { |
125 | | - addressHalfRaw, err := iter.NextBytes(10) |
126 | | - if err != nil { |
127 | | - return SettlementPostInteractionData{}, err |
128 | | - } |
129 | | - addressHalf := hex.EncodeToString(addressHalfRaw) |
130 | | - delay, err := iter.NextUint16() |
131 | | - if err != nil { |
132 | | - return SettlementPostInteractionData{}, err |
133 | | - } |
134 | | - whitelist = append(whitelist, WhitelistItem{ |
135 | | - AddressHalf: addressHalf, |
136 | | - Delay: delay, |
137 | | - }) |
138 | | - } |
139 | | - |
140 | | - return SettlementPostInteractionData{ |
141 | | - ResolvingStartTime: resolvingStartTime, |
142 | | - Whitelist: whitelist, |
143 | | - CustomReceiver: customReceiver, |
144 | | - }, nil |
145 | | -} |
146 | | - |
147 | 67 | func (spid SettlementPostInteractionData) Encode() (string, error) { |
148 | 68 | bitMask := big.NewInt(0) |
149 | 69 | bytes := bytesbuilder.New() |
150 | 70 |
|
151 | | - //if spid.BankFee != nil && spid.BankFee.Cmp(big.NewInt(0)) != 0 { |
152 | | - // bitMask.SetBit(bitMask, 0, 1) |
153 | | - // bytes.AddUint32(spid.BankFee) |
154 | | - //} |
155 | | - // |
156 | | - //if spid.IntegratorFee != nil && spid.IntegratorFee.Ratio.Cmp(big.NewInt(0)) != 0 { |
157 | | - // bitMask.SetBit(bitMask, 1, 1) |
158 | | - // bytes.AddUint16(spid.IntegratorFee.Ratio) |
159 | | - // bytes.AddAddress(spid.IntegratorFee.Receiver) |
160 | | - // |
161 | | - // // TODO this check is probably not good enough |
162 | | - // if spid.CustomReceiver.Hex() != "0x0000000000000000000000000000000000000000" { |
163 | | - // bitMask.SetBit(bitMask, 2, 1) |
164 | | - // bytes.AddAddress(spid.CustomReceiver) |
165 | | - // } |
166 | | - //} |
167 | | - |
168 | 71 | bytes.AddUint32(spid.ResolvingStartTime) |
169 | 72 |
|
170 | 73 | for _, wl := range spid.Whitelist { |
|
0 commit comments