Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change in allowed maximum decimal places #200

Merged
merged 5 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion command/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"time"

"github.com/rubixchain/rubixgoplatform/core"
"github.com/rubixchain/rubixgoplatform/core/model"
"github.com/rubixchain/rubixgoplatform/crypto"
"github.com/rubixchain/rubixgoplatform/did"
Expand Down Expand Up @@ -371,6 +372,6 @@ func (cmd *Command) GetAccountInfo() {
cmd.log.Error("Failed to get account info", "message", info.Message)
} else {
cmd.log.Info("Successfully got the account information")
fmt.Printf("RBT : %10.5f, Locked RBT : %10.5f, Pledged RBT : %10.5f, Pinned RBT : %10.5f\n", info.AccountInfo[0].RBTAmount, info.AccountInfo[0].LockedRBT, info.AccountInfo[0].PledgedRBT, info.AccountInfo[0].PinnedRBT)
fmt.Printf("RBT : %10.*f, Locked RBT : %10.*f, Pledged RBT : %10.*f, Pinned RBT : %10.*f\n", core.MaxDecimalPlaces, info.AccountInfo[0].RBTAmount, core.MaxDecimalPlaces, info.AccountInfo[0].LockedRBT, core.MaxDecimalPlaces, info.AccountInfo[0].PledgedRBT, core.MaxDecimalPlaces, info.AccountInfo[0].PinnedRBT)
}
}
4 changes: 2 additions & 2 deletions command/smartContract.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ func (cmd *Command) deploySmartcontract() {
cmd.log.Error("Invalid deployer DID")
return
}
if cmd.rbtAmount < 0.00001 {
cmd.log.Error("Invalid RBT amount. Minimum RBT amount should be 0.00001")
if cmd.rbtAmount < 0.001 {
cmd.log.Error("Invalid RBT amount. Minimum RBT amount should be 0.001")
return
}
if cmd.transType < 1 || cmd.transType > 2 {
Expand Down
6 changes: 3 additions & 3 deletions command/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (cmd *Command) TransferRBT() {
cmd.log.Error("Invalid sender or receiver DID")
return
}
if cmd.rbtAmount < 0.00001 {
cmd.log.Error("Invalid RBT amount. RBT amount should be atlease 0.00001")
if cmd.rbtAmount < 0.001 {
cmd.log.Error("Invalid RBT amount. RBT amount should be atlease 0.001")
return
}
if cmd.transType < 1 || cmd.transType > 2 {
Expand Down Expand Up @@ -97,7 +97,7 @@ func (cmd *Command) SelfTransferRBT() {
Type: cmd.transType,
}

br, err := cmd.c.TransferRBT(&rt)
br, err := cmd.c.SelfTransferRBT(&rt)
if err != nil {
cmd.log.Error("Failed to self RBT transfer", "err", err)
return
Expand Down
2 changes: 1 addition & 1 deletion core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const (
MainNetDir string = "MainNet"
TestNetDir string = "TestNet"
TestNetDIDDir string = "TestNetDID/"
MaxDecimalPlaces int = 5
MaxDecimalPlaces int = 3
)

const (
Expand Down
4 changes: 2 additions & 2 deletions core/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (c *Core) initiateRBTTransfer(reqID string, req *model.RBTTransferRequest)
ti := contract.TokenInfo{
Token: tokensForTxn[i].TokenID,
TokenType: tt,
TokenValue: tokensForTxn[i].TokenValue,
TokenValue: floatPrecision(tokensForTxn[i].TokenValue, MaxDecimalPlaces),
OwnerDID: tokensForTxn[i].DID,
BlockID: bid,
}
Expand Down Expand Up @@ -489,7 +489,7 @@ func (c *Core) completePinning(st time.Time, reqID string, req *model.RBTPinRequ
ti := contract.TokenInfo{
Token: tokensForTxn[i].TokenID,
TokenType: tt,
TokenValue: tokensForTxn[i].TokenValue,
TokenValue: floatPrecision(tokensForTxn[i].TokenValue, MaxDecimalPlaces),
OwnerDID: did,
BlockID: bid,
}
Expand Down
4 changes: 2 additions & 2 deletions core/uitl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func (c *Core) getTotalAmountFromTokenHashes(tokenHashes []string) (float64, err
return 0.0, fmt.Errorf("getTotalAmountFromTokenHashes: failed to read token %v, err: %v", tokenHash, err)
}

totalAmount += walletToken.TokenValue
totalAmount += floatPrecision(walletToken.TokenValue, MaxDecimalPlaces)
}

return totalAmount, nil
return floatPrecision(totalAmount, MaxDecimalPlaces), nil
}

func (c *Core) RACPartTokenType() int {
Expand Down
6 changes: 3 additions & 3 deletions server/smart_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ func (s *Server) APIDeploySmartContract(req *ensweb.Request) *ensweb.Result {
return s.BasicResponse(req, false, "Invalid input", nil)
}

if deployReq.RBTAmount < 0.00001 {
s.log.Error("Invalid RBT amount. Minimum RBT amount should be 0.00001")
return s.BasicResponse(req, false, "Invalid RBT amount. Minimum RBT amount should be 0.00001", nil)
if deployReq.RBTAmount < 0.001 {
s.log.Error("Invalid RBT amount. Minimum RBT amount should be 0.001")
return s.BasicResponse(req, false, "Invalid RBT amount. Minimum RBT amount should be 0.001", nil)
}
if deployReq.QuorumType < 1 || deployReq.QuorumType > 2 {
s.log.Error("Invalid quorum type")
Expand Down
6 changes: 3 additions & 3 deletions server/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ func (s *Server) APIInitiateRBTTransfer(req *ensweb.Request) *ensweb.Result {
s.log.Error("Invalid sender or receiver DID")
return s.BasicResponse(req, false, "Invalid sender or receiver DID", nil)
}
if rbtReq.TokenCount < 0.00001 {
s.log.Error("Invalid RBT amount. RBT amount should be atlease 0.00001")
return s.BasicResponse(req, false, "Invalid RBT amount. RBT amount should be atlease 0.00001", nil)
if rbtReq.TokenCount < 0.001 {
s.log.Error("Invalid RBT amount. RBT amount should be atlease 0.001")
return s.BasicResponse(req, false, "Invalid RBT amount. RBT amount should be atlease 0.001", nil)
}
if rbtReq.Type < 1 || rbtReq.Type > 2 {
s.log.Error("Invalid trans type. TransType should be 1 or 2")
Expand Down