Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit e3740a1

Browse files
committed
Fix fixedfee disputes from v4
1 parent b01f6bc commit e3740a1

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

core/moderation.go

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"path"
1111
"path/filepath"
12+
"strconv"
1213

1314
routing "gx/ipfs/QmSY3nkMNLzh9GdbFKK5tT7YMfLpf52iUZ8ZRkr29MJaa5/go-libp2p-kad-dht"
1415
ma "gx/ipfs/QmTZBfrPJmjWsCvHEtX5FE6KimVJhsJg5sBbqEFYf4UZtL/go-multiaddr"
@@ -148,6 +149,9 @@ func (n *OpenBazaarNode) RemoveSelfAsModerator() error {
148149

149150
// GetModeratorFee is called by the Moderator when determining their take of the dispute
150151
func (n *OpenBazaarNode) GetModeratorFee(transactionTotal *big.Int, txCurrencyCode string) (*big.Int, error) {
152+
var curDef *pb.CurrencyDefinition
153+
var bigAmount string
154+
151155
file, err := ioutil.ReadFile(path.Join(n.RepoPath, "root", "profile.json"))
152156
if err != nil {
153157
return big.NewInt(0), err
@@ -168,7 +172,29 @@ func (n *OpenBazaarNode) GetModeratorFee(transactionTotal *big.Int, txCurrencyCo
168172
return feePercentAmt.AmountBigInt(), nil
169173

170174
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)
172198
if err != nil {
173199
return big.NewInt(0), fmt.Errorf("parse moderator fee currency: %s", err)
174200
}
@@ -188,6 +214,28 @@ func (n *OpenBazaarNode) GetModeratorFee(transactionTotal *big.Int, txCurrencyCo
188214
return convertedModFee.AmountBigInt(), nil
189215

190216
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+
191239
modFeeValue, err := repo.NewCurrencyValueFromProtobuf(profile.ModeratorInfo.Fee.FixedFee.BigAmount, profile.ModeratorInfo.Fee.FixedFee.AmountCurrency)
192240
if err != nil {
193241
return big.NewInt(0), fmt.Errorf("parse moderator fee currency: %s", err)

core/profile.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,15 @@ func ValidateProfile(profile *pb.Profile) error {
362362
}
363363
}
364364
if profile.ModeratorInfo.Fee != nil {
365+
var moderatorCurrencyCode string
366+
if profile.ModeratorInfo.Fee.FixedFee.AmountCurrency == nil {
367+
moderatorCurrencyCode = profile.ModeratorInfo.Fee.FixedFee.CurrencyCode
368+
} else {
369+
moderatorCurrencyCode = profile.ModeratorInfo.Fee.FixedFee.AmountCurrency.Code
370+
}
371+
365372
if profile.ModeratorInfo.Fee.FeeType != pb.Moderator_Fee_PERCENTAGE && profile.ModeratorInfo.Fee.FixedFee != nil &&
366-
len(profile.ModeratorInfo.Fee.FixedFee.AmountCurrency.Code) > repo.WordMaxCharacters {
373+
len(moderatorCurrencyCode) > repo.WordMaxCharacters {
367374
return fmt.Errorf("moderator fee currency code character length is greater than the max of %d", repo.WordMaxCharacters)
368375
}
369376
}

0 commit comments

Comments
 (0)