9
9
"os"
10
10
"path"
11
11
"path/filepath"
12
+ "strconv"
12
13
13
14
routing "gx/ipfs/QmSY3nkMNLzh9GdbFKK5tT7YMfLpf52iUZ8ZRkr29MJaa5/go-libp2p-kad-dht"
14
15
ma "gx/ipfs/QmTZBfrPJmjWsCvHEtX5FE6KimVJhsJg5sBbqEFYf4UZtL/go-multiaddr"
@@ -148,6 +149,9 @@ func (n *OpenBazaarNode) RemoveSelfAsModerator() error {
148
149
149
150
// GetModeratorFee is called by the Moderator when determining their take of the dispute
150
151
func (n * OpenBazaarNode ) GetModeratorFee (transactionTotal * big.Int , txCurrencyCode string ) (* big.Int , error ) {
152
+ var curDef * pb.CurrencyDefinition
153
+ var bigAmount string
154
+
151
155
file , err := ioutil .ReadFile (path .Join (n .RepoPath , "root" , "profile.json" ))
152
156
if err != nil {
153
157
return big .NewInt (0 ), err
@@ -168,7 +172,29 @@ func (n *OpenBazaarNode) GetModeratorFee(transactionTotal *big.Int, txCurrencyCo
168
172
return feePercentAmt .AmountBigInt (), nil
169
173
170
174
case pb .Moderator_Fee_FIXED :
171
- modFeeValue , err := repo .NewCurrencyValueFromProtobuf (profile .ModeratorInfo .Fee .FixedFee .BigAmount , profile .ModeratorInfo .Fee .FixedFee .AmountCurrency )
175
+ if profile .ModeratorInfo .Fee .FixedFee .AmountCurrency == nil {
176
+ currency , err := n .LookupCurrency (profile .ModeratorInfo .Fee .FixedFee .CurrencyCode )
177
+ if err != nil {
178
+ return nil , err
179
+ }
180
+ curDef = & pb.CurrencyDefinition {
181
+ Code : currency .Code .String (),
182
+ Divisibility : uint32 (currency .Divisibility ),
183
+ }
184
+ bigAmount = strconv .FormatUint (profile .ModeratorInfo .Fee .FixedFee .Amount , 10 )
185
+ } else {
186
+ currency , err := n .LookupCurrency (profile .ModeratorInfo .Fee .FixedFee .AmountCurrency .Code )
187
+ if err != nil {
188
+ return nil , err
189
+ }
190
+ curDef = & pb.CurrencyDefinition {
191
+ Code : currency .Code .String (),
192
+ Divisibility : uint32 (currency .Divisibility ),
193
+ }
194
+ bigAmount = profile .ModeratorInfo .Fee .FixedFee .BigAmount
195
+ }
196
+
197
+ modFeeValue , err := repo .NewCurrencyValueFromProtobuf (bigAmount , curDef )
172
198
if err != nil {
173
199
return big .NewInt (0 ), fmt .Errorf ("parse moderator fee currency: %s" , err )
174
200
}
@@ -188,6 +214,28 @@ func (n *OpenBazaarNode) GetModeratorFee(transactionTotal *big.Int, txCurrencyCo
188
214
return convertedModFee .AmountBigInt (), nil
189
215
190
216
case pb .Moderator_Fee_FIXED_PLUS_PERCENTAGE :
217
+ if profile .ModeratorInfo .Fee .FixedFee .AmountCurrency == nil {
218
+ currency , err := n .LookupCurrency (profile .ModeratorInfo .Fee .FixedFee .CurrencyCode )
219
+ if err != nil {
220
+ return nil , err
221
+ }
222
+ curDef = & pb.CurrencyDefinition {
223
+ Code : currency .Code .String (),
224
+ Divisibility : uint32 (currency .Divisibility ),
225
+ }
226
+ bigAmount = strconv .FormatUint (profile .ModeratorInfo .Fee .FixedFee .Amount , 10 )
227
+ } else {
228
+ currency , err := n .LookupCurrency (profile .ModeratorInfo .Fee .FixedFee .AmountCurrency .Code )
229
+ if err != nil {
230
+ return nil , err
231
+ }
232
+ curDef = & pb.CurrencyDefinition {
233
+ Code : currency .Code .String (),
234
+ Divisibility : uint32 (currency .Divisibility ),
235
+ }
236
+ bigAmount = profile .ModeratorInfo .Fee .FixedFee .BigAmount
237
+ }
238
+
191
239
modFeeValue , err := repo .NewCurrencyValueFromProtobuf (profile .ModeratorInfo .Fee .FixedFee .BigAmount , profile .ModeratorInfo .Fee .FixedFee .AmountCurrency )
192
240
if err != nil {
193
241
return big .NewInt (0 ), fmt .Errorf ("parse moderator fee currency: %s" , err )
0 commit comments