Skip to content

Commit

Permalink
Merge pull request #204 from rubixchain/development
Browse files Browse the repository at this point in the history
release: v0.0.18
  • Loading branch information
gklps authored Aug 1, 2024
2 parents 7b8a65b + 5ccbd47 commit e1b6b9a
Show file tree
Hide file tree
Showing 106 changed files with 5,447 additions and 1,332 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ linux/
mac/
windows/
dist/
test_swarm_key/

# used for testing purpose
!node_registry.json
!node_registry.json
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,48 @@ To get all explorer urls
This following options are used for this command
-port string
Server/Host port (default "20000")
```
To add the peer details manually
: To add the peer details by providing peerID, did and didType of the peer

```
./rubixgoplatform addpeerdetails
This following options are used for this command
-port string
Server/Host port (default "20000")
-peerID string
Peerd ID
-did string
DID address (default "")
-didType int
DID type (0-Basic Mode, 1-Standard Mode, 2-Wallet Mode, 3-Child Mode, 4-Light Mode) (default 0)
```

To check details about the token states for which pledging has been done
: To check for what token states the pledging has been done, and which tokens are pledged

```
./rubixgoplatform getpledgedtokendetails
This following options are used for this command
-port string
Server/Host port (default "20000")
```

To check tokenstatehash status
: To check if a particular tokenstatehash is exhausted, i.e if it has been transferred further

```
./rubixgoplatform tokenstatehash
This following options are used for this command
-port string
Server/Host port (default "20000")
-tokenstatehash string
TokenState Hash, for which the status needs to be checked
```
56 changes: 46 additions & 10 deletions block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const (
TCSmartContractDataKey string = "9"
TCTokenValueKey string = "10"
TCChildTokensKey string = "11"
TCSenderSignatureKey string = "12"
TCEpochKey string = "epoch"
)

const (
Expand All @@ -54,19 +56,22 @@ const (
TokenDeployedType string = "09"
TokenExecutedType string = "10"
TokenContractCommited string = "11"
TokenPinnedAsService string = "12"
)

type TokenChainBlock struct {
TransactionType string `json:"transactionType"`
TokenOwner string `json:"owner"`
GenesisBlock *GenesisBlock `json:"genesisBlock"`
TransInfo *TransInfo `json:"transInfo"`
PledgeDetails []PledgeDetail `json:"pledgeDetails"`
QuorumSignature []string `json:"quorumSignature"`
SmartContract []byte `json:"smartContract"`
SmartContractData string `json:"smartContractData"`
TokenValue float64 `json:"tokenValue"`
ChildTokens []string `json:"childTokens"`
TransactionType string `json:"transactionType"`
TokenOwner string `json:"owner"`
GenesisBlock *GenesisBlock `json:"genesisBlock"`
TransInfo *TransInfo `json:"transInfo"`
PledgeDetails []PledgeDetail `json:"pledgeDetails"`
QuorumSignature []CreditSignature `json:"quorumSignature"`
SmartContract []byte `json:"smartContract"`
SmartContractData string `json:"smartContractData"`
TokenValue float64 `json:"tokenValue"`
ChildTokens []string `json:"childTokens"`
InitiatorSignature *InitiatorSignature `json:"initiatorSignature"`
Epoch int `json:"epoch"`
}

type PledgeDetail struct {
Expand All @@ -83,6 +88,22 @@ type Block struct {
log logger.Logger
}

type CreditSignature struct {
Signature string `json:"signature"`
PrivSignature string `json:"priv_signature"`
DID string `json:"did"`
Hash string `json:"hash"`
SignType string `json:"sign_type"` //represents sign type (PkiSign == 0 or NlssSign==1)
}

type InitiatorSignature struct {
NLSS_share string `json:"nlss_share_signature"`
Private_sign string `json:"priv_signature"`
DID string `json:"initiator_did"`
Hash string `json:"hash"`
SignType int `json:"sign_type"` //represents sign type (PkiSign == 0 or NlssSign==1)
}

type BlockOption func(b *Block)

func NoSignature() BlockOption {
Expand Down Expand Up @@ -151,6 +172,9 @@ func CreateNewBlock(ctcb map[string]*Block, tcb *TokenChainBlock) *Block {
if tcb.SmartContractData != "" {
ntcb[TCSmartContractDataKey] = tcb.SmartContractData
}
if tcb.InitiatorSignature != nil {
ntcb[TCSenderSignatureKey] = tcb.InitiatorSignature
}

if floatPrecisionToMaxDecimalPlaces(tcb.TokenValue) > floatPrecisionToMaxDecimalPlaces(0) {
ntcb[TCTokenValueKey] = floatPrecisionToMaxDecimalPlaces(tcb.TokenValue)
Expand All @@ -162,6 +186,10 @@ func CreateNewBlock(ctcb map[string]*Block, tcb *TokenChainBlock) *Block {
ntcb[TCChildTokensKey] = tcb.ChildTokens
}

if tcb.Epoch != 0 {
ntcb[TCEpochKey] = tcb.Epoch
}

blk := InitBlock(nil, ntcb)
return blk
}
Expand All @@ -170,6 +198,7 @@ func (b *Block) blkDecode() error {
var m map[string]interface{}
err := cbor.Unmarshal(b.bb, &m)
if err != nil {
fmt.Println("failed to decode block", err.Error(), err)
return nil
}
si, sok := m[TCBlockContentSigKey]
Expand Down Expand Up @@ -575,6 +604,9 @@ func (b *Block) GetReceiverDID() string {
func (b *Block) GetDeployerDID() string {
return b.getTrasnInfoString(TIDeployerDIDKey)
}
func (b *Block) GetPinningNodeDID() string {
return b.getTrasnInfoString(TIPinningDIDKey)
}

func (b *Block) GetExecutorDID() string {
return b.getTrasnInfoString(TIExecutorDIDKey)
Expand Down Expand Up @@ -689,3 +721,7 @@ func (b *Block) GetTokenValue() float64 {
func (b *Block) GetChildTokens() []string {
return util.GetStringSliceFromMap(b.bm, TCChildTokensKey)
}

func (b *Block) GetEpoch() int64 {
return int64(util.GetIntFromMap(b.bm, TCEpochKey))
}
23 changes: 14 additions & 9 deletions block/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
TIDeployerDIDKey string = "8"
TIExecutorDIDKey string = "9"
TICommitedTokensKey string = "10"
TIPinningDIDKey string = "11"
)

const (
Expand All @@ -69,15 +70,16 @@ type TransTokens struct {
}

type TransInfo struct {
SenderDID string `json:"senderDID"`
ReceiverDID string `json:"receiverDID"`
Comment string `json:"comment"`
TID string `json:"tid"`
Block []byte `json:"block"`
RefID string `json:"refID"`
Tokens []TransTokens `json:"tokens"`
DeployerDID string `json:"deployerDID"`
ExecutorDID string `json:"executorDID"`
SenderDID string `json:"senderDID"`
ReceiverDID string `json:"receiverDID"`
Comment string `json:"comment"`
TID string `json:"tid"`
Block []byte `json:"block"`
RefID string `json:"refID"`
Tokens []TransTokens `json:"tokens"`
DeployerDID string `json:"deployerDID"`
ExecutorDID string `json:"executorDID"`
PinningNodeDID string `json:"pinningNodeDID"`
}

func newTransToken(b *Block, tt *TransTokens) map[string]interface{} {
Expand Down Expand Up @@ -123,6 +125,9 @@ func newTransInfo(ctcb map[string]*Block, ti *TransInfo) map[string]interface{}
if ti.ReceiverDID != "" {
ntib[TIReceiverDIDKey] = ti.ReceiverDID
}
if ti.PinningNodeDID != "" {
ntib[TIPinningDIDKey] = ti.PinningNodeDID
}
if ti.DeployerDID != "" {
ntib[TIDeployerDIDKey] = ti.DeployerDID
}
Expand Down
17 changes: 17 additions & 0 deletions client/addpeer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package client

import (
"github.com/rubixchain/rubixgoplatform/core/model"
"github.com/rubixchain/rubixgoplatform/core/wallet"
"github.com/rubixchain/rubixgoplatform/setup"
)

func (c *Client) AddPeer(peer_detail *wallet.DIDPeerMap) (string, bool) {

var rm model.BasicResponse
err := c.sendJSONRequest("POST", setup.APIAddPeerDetails, nil, &peer_detail, &rm)
if err != nil {
return err.Error(), false
}
return rm.Message, rm.Status
}
10 changes: 9 additions & 1 deletion client/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c *Client) GetAllDIDs() (*model.GetAccountInfo, error) {
}

func (c *Client) CreateDID(cfg *did.DIDCreate) (string, bool) {
if cfg.Type < did.LiteDIDMode && cfg.Type > did.WalletDIDMode {
if cfg.Type < did.BasicDIDMode && cfg.Type > did.LiteDIDMode {
return "Invalid DID mode", false
}
switch cfg.Type {
Expand Down Expand Up @@ -186,6 +186,14 @@ func (c *Client) SetupDID(dc *did.DIDCreate) (string, bool) {
!strings.Contains(dc.QuorumPrivKeyFile, did.QuorumPvtKeyFileName) {
return "Required files are missing", false
}
default:
if !strings.Contains(dc.PubImgFile, did.PubShareFileName) ||
!strings.Contains(dc.DIDImgFileName, did.DIDImgFileName) ||
!strings.Contains(dc.PubKeyFile, did.PubKeyFileName) ||
!strings.Contains(dc.QuorumPubKeyFile, did.QuorumPubKeyFileName) ||
!strings.Contains(dc.QuorumPrivKeyFile, did.QuorumPvtKeyFileName) {
return "Required files are missing", false
}
}
jd, err := json.Marshal(&dc)
if err != nil {
Expand Down
7 changes: 0 additions & 7 deletions client/ping.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package client

import (
"strings"
"time"

"github.com/rubixchain/rubixgoplatform/core/model"
Expand All @@ -21,12 +20,6 @@ func (c *Client) Ping(peerID string) (string, bool) {

func (c *Client) CheckQuorumStatus(quorumAddress string) (string, bool) {
q := make(map[string]string)
// Split the string into two parts based on a delimiter
parts := strings.Split(quorumAddress, ".")
if len(parts) != 2 {
// Handle the case where the string doesn't contain exactly two parts
return "Invalid quorumAddress format", false
}
q["quorumAddress"] = quorumAddress
var rm model.BasicResponse
err := c.sendJSONRequest("GET", setup.APICheckQuorumStatus, q, nil, &rm, 2*time.Minute)
Expand Down
18 changes: 16 additions & 2 deletions client/quorum.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package client

import (
"encoding/json"
"io/ioutil"
"fmt"
"os"
"regexp"
"strings"

"github.com/rubixchain/rubixgoplatform/core"
"github.com/rubixchain/rubixgoplatform/core/model"
Expand All @@ -14,7 +17,7 @@ func (c *Client) AddQuorum(quorumList string) (string, bool) {
c.log.Error("Quorum list required")
return "Quorum list required", false
}
qlb, err := ioutil.ReadFile(quorumList)
qlb, err := os.ReadFile(quorumList)
if err != nil {
c.log.Error("Invalid file", "err", err)
return "Invalid file, failed to add quorum list", false
Expand All @@ -25,6 +28,17 @@ func (c *Client) AddQuorum(quorumList string) (string, bool) {
c.log.Error("Invalid file, failed to add quorum list", "err", err)
return "Invalid file, failed to add quorum list", false
}
if len(ql) < 5 {
c.log.Error("Length of Quorum list should be atleast 5")
return "Length of Quorum list should be atleast 5", false
}
for _, q := range ql {
is_alphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(q.Address)
if !strings.HasPrefix(q.Address, "bafybmi") || len(q.Address) != 59 || !is_alphanumeric {
c.log.Error(fmt.Sprintf("Invalid quorum DID : %s", q.Address))
return fmt.Sprintf("Invalid quorum DID : %s", q.Address), false
}
}
var resp model.BasicResponse
err = c.sendJSONRequest("POST", setup.APIAddQuorum, nil, &ql, &resp)
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions client/recover.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package client

import (
"time"

"github.com/rubixchain/rubixgoplatform/core/model"
"github.com/rubixchain/rubixgoplatform/setup"
)

func (c *Client) RecoverRBT(rt *model.RBTRecoverRequest) (*model.BasicResponse, error) {
var br model.BasicResponse
err := c.sendJSONRequest("POST", setup.APIRecoverRBT, nil, rt, &br, time.Minute*2)
if err != nil {
c.log.Error("Failed to Recover RBT from the pinning node", "err", err)
return nil, err
}
return &br, nil
}
24 changes: 24 additions & 0 deletions client/token.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package client

import (
"time"

"github.com/rubixchain/rubixgoplatform/core/model"
"github.com/rubixchain/rubixgoplatform/setup"
)
Expand Down Expand Up @@ -29,3 +31,25 @@ func (c *Client) GetAllTokens(didStr string, tokenType string) (*model.TokenResp
}
return &tr, nil
}

func (c *Client) GetPledgedTokenDetails() (*model.TokenStateResponse, error) {
var tr model.TokenStateResponse
err := c.sendJSONRequest("GET", setup.APIGetPledgedTokenDetails, nil, nil, &tr, time.Minute*2)
if err != nil {
c.log.Error("Failed to get pledged token details", "err", err)
return nil, err
}
return &tr, nil
}

func (c *Client) GetPinnedInfo(TokenStateHash string) (*model.BasicResponse, error) {
m := make(map[string]string)
m["tokenstatehash"] = TokenStateHash
var br model.BasicResponse
err := c.sendJSONRequest("DELETE", setup.APICheckPinnedState, m, nil, &br, time.Minute*2)
if err != nil {
c.log.Error("Failed to get Pins", "err", err)
return nil, err
}
return &br, nil
}
20 changes: 20 additions & 0 deletions client/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,23 @@ func (c *Client) TransferRBT(rt *model.RBTTransferRequest) (*model.BasicResponse
}
return &br, nil
}

func (c *Client) SelfTransferRBT(rt *model.RBTTransferRequest) (*model.BasicResponse, error) {
var br model.BasicResponse
err := c.sendJSONRequest("POST", setup.APISelfTransfer, nil, rt, &br, time.Minute*2)
if err != nil {
c.log.Error("Failed RBT Transfer", "err", err)
return nil, err
}
return &br, nil
}

func (c *Client) PinRBT(rt *model.RBTPinRequest) (*model.BasicResponse, error) {
var br model.BasicResponse
err := c.sendJSONRequest("POST", setup.APIInitiatePinRBT, nil, rt, &br, time.Minute*2)
if err != nil {
c.log.Error("Failed to Pin RBT as a service", "err", err)
return nil, err
}
return &br, nil
}
Loading

0 comments on commit e1b6b9a

Please sign in to comment.