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

Use of cobra package to refactor CLI #172

Draft
wants to merge 29 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1ab5a77
refactor: use of cobra golang package to refactor CLI; use of path.Jo…
arnabghose997 May 31, 2024
4770610
use of path.Join() for cleaner path concatenation
arnabghose997 May 31, 2024
d3c9ebf
Merge branch 'development' of https://github.com/rubixchain/rubixgopl…
arnabghose997 May 31, 2024
dcf2fe7
token chain validation for transferred RBTs
maneeSHA-256 Jul 5, 2024
10e8a15
Merge branch 'development' of https://github.com/rubixchain/rubixgopl…
maneeSHA-256 Jul 5, 2024
b97261d
resolving error with signer validation
maneeSHA-256 Jul 8, 2024
22b7d57
Adding TC dump decoder
gklps Jul 10, 2024
31bfcda
smart contract token chain validation
maneeSHA-256 Jul 10, 2024
5ffd9dd
added validation for trans types: pledged, unpledged and contract com…
maneeSHA-256 Jul 10, 2024
bbefd50
Adding tokenchain decoder for tokenchain dump
gklps Jul 10, 2024
80709e0
removing redundant import functions
gklps Jul 10, 2024
23c47b9
Expanding TC decoder to SmartContracts
gklps Jul 11, 2024
0162fbf
update README and handle errors for missing flags
maneeSHA-256 Jul 11, 2024
1cca611
removing smart contract bug fixes from this branch
maneeSHA-256 Jul 11, 2024
1b08731
Merge branch 'development' of https://github.com/rubixchain/rubixgopl…
maneeSHA-256 Jul 17, 2024
beaaa7f
removing recurring validations and updating smart contract validations
maneeSHA-256 Jul 17, 2024
9b758f3
This commit will enable decode tokenchain
gklps Jul 23, 2024
4eb669f
some quick cleanup
gklps Jul 23, 2024
bafd2af
Code cleanup
gklps Jul 23, 2024
68b5218
incorporated changes till PR #191
arnabghose997 Jul 24, 2024
0fc64bb
incorporated changes from PR #189
arnabghose997 Jul 25, 2024
b2f3b0f
Merge branch 'development' of https://github.com/rubixchain/rubixgopl…
arnabghose997 Jul 25, 2024
5dda916
added 'epoch' in keyMapping
arnabghose997 Jul 26, 2024
5a19c20
incorporated changes from PR #190
arnabghose997 Jul 29, 2024
e99edcc
Merge branch 'development' into maneesha/tokenchain-validation
maneeSHA-256 Jul 29, 2024
e22f2a3
handling errors and unnecessary flags
maneeSHA-256 Jul 29, 2024
7593733
handling validation of synced tokenchains
maneeSHA-256 Jul 29, 2024
ee5edac
added chain validation command from PR #185
arnabghose997 Jul 30, 2024
97c4d8c
added doc for validate-chain command
arnabghose997 Jul 30, 2024
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
471 changes: 118 additions & 353 deletions README.md

Large diffs are not rendered by default.

126 changes: 108 additions & 18 deletions block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ import (
// }

const (
TCTokenTypeKey string = "1"
TCTransTypeKey string = "2"
TCTokenOwnerKey string = "3"
TCGenesisBlockKey string = "4"
TCTransInfoKey string = "5"
TCSmartContractKey string = "6"
TCQuorumSignatureKey string = "7"
TCPledgeDetailsKey string = "8"
TCBlockHashKey string = "98"
TCSignatureKey string = "99"
TCBlockContentKey string = "1"
TCBlockContentSigKey string = "2"
TCSmartContractDataKey string = "9"
TCTokenValueKey string = "10"
TCChildTokensKey string = "11"
TCSenderSignatureKey string = "12"
TCEpochKey string = "epoch"
TCTokenTypeKey string = "1"
TCTransTypeKey string = "2"
TCTokenOwnerKey string = "3"
TCGenesisBlockKey string = "4"
TCTransInfoKey string = "5"
TCSmartContractKey string = "6"
TCQuorumSignatureKey string = "7"
TCPledgeDetailsKey string = "8"
TCBlockHashKey string = "98"
TCSignatureKey string = "99"
TCBlockContentKey string = "1"
TCBlockContentSigKey string = "2"
TCSmartContractDataKey string = "9"
TCTokenValueKey string = "10"
TCChildTokensKey string = "11"
TCInitiatorSignatureKey string = "12"
TCEpochKey string = "epoch"
)

const (
Expand All @@ -59,6 +59,22 @@ const (
TokenPinnedAsService string = "12"
)

const (
Initiator_NLSS_share string = "nlss_share_signature"
Initiator_Private_sign string = "priv_signature"
Initiator_DID string = "initiator_did"
Initiator_Hash string = "hash"
Initiator_SignType string = "sign_type"
)

const (
CreditSig_Signature string = "signature"
CreditSig_PrivSignature string = "priv_signature"
CreditSig_DID string = "did"
CreditSig_Hash string = "hash"
CreditSig_SignType string = "sign_type"
)

type TokenChainBlock struct {
TransactionType string `json:"transactionType"`
TokenOwner string `json:"owner"`
Expand Down Expand Up @@ -173,7 +189,7 @@ func CreateNewBlock(ctcb map[string]*Block, tcb *TokenChainBlock) *Block {
ntcb[TCSmartContractDataKey] = tcb.SmartContractData
}
if tcb.InitiatorSignature != nil {
ntcb[TCSenderSignatureKey] = tcb.InitiatorSignature
ntcb[TCInitiatorSignatureKey] = tcb.InitiatorSignature
}

if floatPrecisionToMaxDecimalPlaces(tcb.TokenValue) > floatPrecisionToMaxDecimalPlaces(0) {
Expand Down Expand Up @@ -725,3 +741,77 @@ func (b *Block) GetChildTokens() []string {
func (b *Block) GetEpoch() int64 {
return int64(util.GetIntFromMap(b.bm, TCEpochKey))
}

// Fetch initiator signature details from the given block
func (b *Block) GetInitiatorSignature() *InitiatorSignature {
var initiator_sign InitiatorSignature
s, ok := b.bm[TCInitiatorSignatureKey]
if !ok || s == nil {
return nil
}
//fetch initiator did
did_ := util.GetFromMap(s, Initiator_DID)
initiator_sign.DID = did_.(string)
//fetch initiator sign type
sign_type_ := util.GetFromMap(s, Initiator_SignType)
initiator_sign.SignType = int(sign_type_.(uint64))
//fetch initiator nlss share sign
nlss_share_ := util.GetFromMap(s, Initiator_NLSS_share)
initiator_sign.NLSS_share = nlss_share_.(string)
//fetch initiator private sign
priv_sign_ := util.GetFromMap(s, Initiator_Private_sign)
initiator_sign.Private_sign = priv_sign_.(string)
//fetch initiator hash / signed data
signed_data_ := util.GetFromMap(s, Initiator_Hash)
initiator_sign.Hash = signed_data_.(string)

return &initiator_sign
}

// Fetch quorums' signature details from the given block
func (b *Block) GetQuorumSignatureList() ([]CreditSignature, error) {
var quorum_sign_list []CreditSignature
s := b.bm[TCQuorumSignatureKey]

qrmSignList_map, ok := s.([]interface{})
if !ok {
fmt.Println("not of type []interface{}")
return nil, fmt.Errorf("failed to fetch quorums' signature information from block map")
}
for _, qrmSignList_ := range qrmSignList_map {
var quorum_sig CreditSignature
//fetch quorum did
qrm_did := util.GetFromMap(qrmSignList_, CreditSig_DID)
quorum_sig.DID = qrm_did.(string)
// //fetch quorum sign type
sign_type_ := util.GetFromMap(qrmSignList_, CreditSig_SignType)
quorum_sig.SignType = sign_type_.(string)
// //fetch quorum nlss share sign
nlss_share_ := util.GetFromMap(qrmSignList_, CreditSig_Signature)
quorum_sig.Signature = nlss_share_.(string)
// //fetch quorum private sign
priv_sign_ := util.GetFromMap(qrmSignList_, CreditSig_PrivSignature)
quorum_sig.PrivSignature = priv_sign_.(string)
quorum_sign_list = append(quorum_sign_list, quorum_sig)
}

return quorum_sign_list, nil
}

// calculate block hash from block data
func (b *Block) CalculateBlockHash() (string, error) {
var m map[string]interface{}

err := cbor.Unmarshal(b.bb, &m)
if err != nil {
return "", err
}
bc, ok := m[TCBlockContentKey]
if !ok {
return "", fmt.Errorf("invalid block, block content missing")
}
hb := util.CalculateHash(bc.([]byte), "SHA3-256")
block_hash := util.HexToStr(hb)

return block_hash, nil
}
17 changes: 17 additions & 0 deletions client/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package client
import (
"time"

"strconv"

"github.com/rubixchain/rubixgoplatform/core/model"
"github.com/rubixchain/rubixgoplatform/setup"
)
Expand Down Expand Up @@ -53,3 +55,18 @@ func (c *Client) GetPinnedInfo(TokenStateHash string) (*model.BasicResponse, err
}
return &br, nil
}

func (c *Client) ValidateTokenchain(user_did string, smartContractChainValidation bool, token string, blockCount int) (*model.BasicResponse, error) {
q := make(map[string]string)
q["did"] = user_did
q["token"] = token
q["blockcount"] = strconv.Itoa(blockCount)
q["SCChainValidation"] = strconv.FormatBool(smartContractChainValidation)

var br model.BasicResponse
err := c.sendJSONRequest("GET", setup.APIValidateTokenChain, q, nil, &br)
if err != nil {
return nil, err
}
return &br, nil
}
194 changes: 194 additions & 0 deletions command/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
# Rubix CLI

The `command` package builds a structured and extensible Command-Line Interface for Rubix Blockchain Platform.

## Commands

Rubix CLI has the following top-level commands:

- [boostrap](#bootstrap-command)
- [chain-dump](#chain-dump-command)
- [config](#config-command)
- [did](#did-command)
- [explorer](#explorer-command)
- [node](#node-command)
- [node peer](#node-peer)
- [quorum](#quorum-command)
- [run](#run-command)
- [tx](#tx-commands)
- [tx rbt](#tx-rbt)
- [tx smart-contract](#tx-smart-contract)
- [tx nft](#tx-nft)
- [tx data-token](#tx-data-token)
- [upgrade](#upgrade-command)
- [pin-service](#pin-service-command)
- [validate-chain](#validate-chain-command)
- [version](#version-command)

`addr` and `port` are Global Glags, which can be used in any command. Their default values are `localhost` and `20000` respectively.

Run `rubixgoplatform -h` to know more

### `bootstrap` Command

It consists of subcommands that are associated with managing boostrap nodes:

- `add`: Add IPFS bootstrap peers
- `list`: List all bootstrap peers from the configuration
- `remove`: Remove bootstrap peer(s) from the configuration
- `remove-all`: Removes all bootstrap peers from the configuration

To know more about the flags, run `rubixgoplatform bootstrap [command] --help`

### `chain-dump` Command

It consists of subcommands that are associated with Token chain and SmartContract chain dumps.

- `smart-contract`: Get the dump of Smart Contract chain
- `token`: Get the dump of Token chain
- `decode-token-chain`: Decodes token chain dump

To know more about the flags, run `rubixgoplatform chain-dump [command] --help`

### `config` Command

It consists of subcommands that are associated with setting up DB and Services.

- `setup-db`: Setup Database
- `setup-service`: Setup Service

To know more about the flags, run `rubixgoplatform config [command] --help`

### `did` Command

It consists of subcommands that are associated with managing DIDs

- `balance`: Get the account balance information of a DID
- `create`: Create a DID
- `list`: Fetch every DID present in the node
- `register`: Register DID

To know more about the flags, run `rubixgoplatform did [command] --help`

### `explorer` Command

It consists of subcommands that are associated with explorer.

- `add`: Add Explorer URLs
- `list`: List all Explorer URLs
- `remove`: Remove Explorer URLs

To know more about the flags, run `rubixgoplatform explorer [command] --help`

### `node` Command

It consists of subcommands that are associated with Rubix node.

- `lock-rbt-tokens`: Lock RBT tokens
- `migrate`: Migrate Node
- `peer`: Peer related subcommands
- `release-rbt-tokens`: Release all locked RBT tokens
- `shutdown`: shut down the node
- `token-state-pinned-info`: Check if a Token state is pinned

To know more about the flags, run `rubixgoplatform node [command] --help`

<a name="node-peer"></a>**`node peer` Commands**

It consists of subcommands associated with peer info of a node

- `add`: Add Peer details
- `local-id`: Get the local IPFS peer id
- `ping`: pings a peer
- `quorum-status`: check the status of quorum

To know more about the flags, run `rubixgoplatform node peer [command] --help`

### `quorum` Command

It consists of subcommands that are associated with Quorums.

- `add`: Add addresses present with quorumlist.json in the node
- `list`: List all Quorums
- `remove-all`: Remove all Quorums
- `setup`: Setup up DID as a Quorum
- `list-token-states`: List all pledge token states of a node
- `unpledge`: Unpledge all pledged tokens

To know more about the flags, run `rubixgoplatform quorum [command] --help`

### `run` Command

This command is used to run a Rubix node. To know more about the flags, run `rubixgoplatform run [command] --help`

### `tx` Commands

It consists of subcommands that are associated with transactions related to RBT tokens, Smart Contracts and NFT.

<a name="tx-rbt"></a>**`tx rbt` Commands**

It consists of subcommands associated with RBT tokens

- `generate-test-tokens`: Generate Test RBT tokens
- `transfer`: Transfer RBT tokens
- `self-transfer`: Self transfer RBT tokens

To know more about the flags, run `rubixgoplatform tx rbt [command] --help`

<a name="tx-smart-contract"></a>**`tx smart-contract` Commands**

It consists of subcommands associated with Smart Contracts

- `deploy`: Deploy a Smart Contract
- `execute`: Execute a Smart Contract
- `fetch`: Fetch a Smart Contract Token
- `generate`: Generate a Smart Contract Token
- `publish`: Publish a Smart Contract Token
- `subscribe`: Subscribe to a Smart Contract

To know more about the flags, run `rubixgoplatform tx smart-contract [command] --help`

<a name="tx-nft"></a>**`tx nft` Commands**

It consists of subcommands associated with NFTs

- `create`: Create an NFT
- `list`: List NFTs by DID

To know more about the flags, run `rubixgoplatform tx nft [command] --help`

<a name="tx-data-token"></a> **`tx data-token` Commands**

It consists of subcommands associated with Data tokens

- `commit`: Commit a Data Token
- `create`: Create a Data Token

To know more about the flags, run `rubixgoplatform tx data-token [command] --help`

### `pin-service` Command

It consists of subcommands associated with Token pinning and recovery

- `pin`: Pins a token on a pinning service provider node
- `recover`: Recovers the pinned token from the pinning service provider node

To know more about the flags, run `rubixgoplatform pin-service [command] --help`

### `upgrade` Command

It consists of subcommands associated with operations related to node version migrations

- `unpledge-pow-tokens`: Unpledge any pledge tokens which were pledged as part of PoW based pledging

To know more about the flags, run `rubixgoplatform upgrade [command] --help`

### `validate-chain` Command

This command validates token chain and smart contract chain.

To know more about the flags, run `rubixgoplatform validate-chain --help`

### `version` Command

This command will output the Rubix binary version.
Loading