Skip to content

Commit

Permalink
Squash all commits
Browse files Browse the repository at this point in the history
  • Loading branch information
vaishnav-ch committed Nov 1, 2024
1 parent 20f40e3 commit 1fd73ce
Show file tree
Hide file tree
Showing 30 changed files with 2,565 additions and 97 deletions.
90 changes: 89 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,92 @@ This following options are used for this command
NOTE: Don't provide the flag -blockCount in case you want to validate all the blocks of the token chain
```
```
Create FT Command
: To create FTs

```
./rubixgoplatform createft
The following flags are used for this command
-did string
DID address (default "")
-ftName string
Name of the FT to be created (default "")
-ftCount integer
Number of FTs to be created (default "0")
-rbtAmount integer
Amount of RBT to be used for creating the FT (default "0")
-port string
Server/Host port (default "20000")
```
Transfer FT Command
: To transfer FT

```
./rubixgoplatform transferft
The following flags are used for this command
-ftName string
Name of the FT to be transferred (default "")
-ftCount integer
Number of FTs to be created (default "0")
-senderAddr string
Sender address (default "")
-receiverAddr string
Receiver address (default "")
-port string
Server/Host port (default "20000")
-transType int
Transaction type (default 2)
-fp string
Force password to authenticate transfer (default "")
-creatorDID string
FT Creator DID address (default "")
NOTE: -fp flag is used when there is a password already created during DID creation
-creatorDID flag is used when there are multiple FTs with same name
```
Get FT Info Command
: To get info of all FTs with the DID.

```
./rubixgoplatform getftinfo
The following flags are used for this command
-did string
DID address (default "")
-port string
Server/Host port (default "20000")
```
Dump FT command
: To dump the token chain of an FT.

```
./rubixgoplatform dumpft
This following flags are used for this command
-port string
Server/Host port (default "20000")
-token string
FT token ID (default "")
```


1 change: 1 addition & 0 deletions block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const (
TokenExecutedType string = "10"
TokenContractCommited string = "11"
TokenPinnedAsService string = "12"
TokenIsBurntForFT string = "13"
)

const (
Expand Down
13 changes: 13 additions & 0 deletions client/diagnostic.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ func (c *Client) DumpTokenChain(token string, blockID string) (*model.TCDumpRepl
return &drep, nil
}

func (c *Client) DumpFTTokenChain(token string, blockID string) (*model.TCDumpReply, error) {
dr := &model.TCDumpRequest{
Token: token,
BlockID: blockID,
}
var drep model.TCDumpReply
err := c.sendJSONRequest("POST", setup.APIDumpFTTokenChainBlock, nil, dr, &drep)
if err != nil {
return nil, err
}
return &drep, nil
}

func (c *Client) DumpSmartContractTokenChain(token string, blockID string) (*model.TCDumpReply, error) {
dr := &model.TCDumpRequest{
Token: token,
Expand Down
44 changes: 44 additions & 0 deletions client/ft.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package client

import (
"time"

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

func (c *Client) CreateFT(did string, ftName string, ftCount int, wholeToken float64) (*model.BasicResponse, error) {
createFTReq := model.CreateFTReq{
DID: did,
FTName: ftName,
FTCount: ftCount,
TokenCount: wholeToken,
}
var basicresponse model.BasicResponse
err := c.sendJSONRequest("POST", setup.APICreateFT, nil, &createFTReq, &basicresponse)
if err != nil {
return nil, err
}
return &basicresponse, nil
}

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

func (c *Client) GetFTInfo(didStr string) (*model.GetFTInfo, error) {
m := make(map[string]string)
m["did"] = didStr
var info model.GetFTInfo
err := c.sendJSONRequest("GET", setup.APIGetFTInfo, m, nil, &info)
if err != nil {
return nil, err
}
return &info, nil
}
26 changes: 26 additions & 0 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ const (
PinTokenCmd string = "pinToken"
RecoverTokensCmd string = "recoverToken"
ValidateTokenchainCmd string = "validatetokenchain"
CreateFTCmd string = "create-ft"
DumpFTTokenChainCmd string = "dump-ft"
TransferFTCmd string = "transfer-ft"
GetFTInfoCmd string = "get-ft-info-by-did"
ValidateTokenCmd string = "validatetoken"
DumpNFTTokenChainCmd string = "dump-nft-tokenchain"
DeployNFTCmd string = "deploy-nft"
Expand Down Expand Up @@ -151,6 +155,10 @@ var commands = []string{VersionCmd,
RecoverTokensCmd,
CheckQuorumStatusCmd,
ValidateTokenchainCmd,
CreateFTCmd,
DumpFTTokenChainCmd,
TransferFTCmd,
GetFTInfoCmd,
ValidateTokenCmd,
DumpNFTTokenChainCmd,
DeployNFTCmd,
Expand Down Expand Up @@ -206,6 +214,10 @@ var commandsHelp = []string{"To get tool version",
"This command will initiate a self RBT transfer",
"This command will unpledge all the pledged tokens",
"This command will unpledge all PoW based pledge tokens and drop the unpledgequeue table",
"This command will create FT",
"This command will dump the token chain of FT",
"This command will transfer FT",
"This command will give the balance of FTs",
"This command will pin the token",
"This command will recover the token",
"This command will check the quorum status",
Expand Down Expand Up @@ -297,6 +309,9 @@ type Command struct {
artifact string
nft string
nftData string
ftName string
ftCount int
creatorDID string
}

func showVersion() {
Expand Down Expand Up @@ -501,6 +516,9 @@ func Run(args []string) {
flag.StringVar(&cmd.metadata, "metadata", "", "NFT metadata")
flag.StringVar(&cmd.artifact, "artifact", "", "NFT artifact")
flag.StringVar(&cmd.nftData, "nftData", "", "The nft data")
flag.StringVar(&cmd.ftName, "ftName", "", "Name of FT to be created")
flag.IntVar(&cmd.ftCount, "ftCount", 0, "Number of FTs to be created")
flag.StringVar(&cmd.creatorDID, "creatorDID", "", "DID of creator of FT")

if len(os.Args) < 2 {
fmt.Println("Invalid Command")
Expand Down Expand Up @@ -678,6 +696,14 @@ func Run(args []string) {
cmd.RecoverTokens()
case ValidateTokenchainCmd:
cmd.ValidateTokenchain()
case CreateFTCmd:
cmd.createFT()
case DumpFTTokenChainCmd:
cmd.dumpFTTokenchain()
case TransferFTCmd:
cmd.transferFT()
case GetFTInfoCmd:
cmd.getFTinfo()
case ValidateTokenCmd:
cmd.ValidateToken()
case ExecuteNFTCmd:
Expand Down
41 changes: 41 additions & 0 deletions command/diagnostic.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,47 @@ func (cmd *Command) dumpTokenChain() {
cmd.log.Info("Token chain dumped successfully!")
}

func (cmd *Command) dumpFTTokenchain() {
blocks := make([]map[string]interface{}, 0)
blockID := ""
for {
ds, err := cmd.c.DumpFTTokenChain(cmd.token, blockID)
if err != nil {
cmd.log.Error("Failed to dump token chain", "err", err)
return
}
if !ds.Status {
cmd.log.Error("Failed to dump token chain", "msg", ds.Message)
return
}
for _, blk := range ds.Blocks {
b := block.InitBlock(blk, nil)
if b != nil {
blocks = append(blocks, b.GetBlockMap())
} else {
cmd.log.Error("Invalid block")
}
}
blockID = ds.NextBlockID
if ds.NextBlockID == "" {
break
}
}
str, err := tcMarshal("", blocks)
if err != nil {
cmd.log.Error("Failed to dump token chain", "err", err)
return
}
f, err := os.Create("dump.json")
if err != nil {
cmd.log.Error("Failed to dump token chain", "err", err)
return
}
f.WriteString(str)
f.Close()
cmd.log.Info("Token chain dumped successfully!")
}

func (cmd *Command) dumpSmartContractTokenChain() {
if cmd.smartContractToken == "" {
cmd.log.Info("smart contract token id cannot be empty")
Expand Down
Loading

0 comments on commit 1fd73ce

Please sign in to comment.