Skip to content

Commit

Permalink
Merge pull request #41 from make-software/release/v1.2.0
Browse files Browse the repository at this point in the history
Release/v1.2.0
  • Loading branch information
koltsov-iv authored Jul 18, 2023
2 parents ac39e60 + 6a8b30e commit 9626f1f
Show file tree
Hide file tree
Showing 25 changed files with 1,070 additions and 1,064 deletions.
8 changes: 8 additions & 0 deletions rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type ClientInformational interface {
GetAccountBalance(ctx context.Context, stateRootHash *string, purseURef string) (StateGetBalanceResult, error)
// GetDeploy retrieves a Deploy from a network. It requires a deploy_hash to query the Deploy.
GetDeploy(ctx context.Context, hash string) (InfoGetDeployResult, error)
// GetDeployFinalizedApproval returns Deploy with the finalized approvals substituted.
GetDeployFinalizedApproval(ctx context.Context, hash string) (InfoGetDeployResult, error)
// GetDictionaryItem returns an item from a Dictionary.
// Every dictionary has a seed URef, findable by using a dictionary_identifier.
// The address of a stored value is the blake2b hash of the seed URef and the byte representation of the dictionary key.
Expand All @@ -63,6 +65,8 @@ type ClientInformational interface {

// QueryGlobalStateByBlockHash allows for you to query for a value stored under certain keys in global state.
QueryGlobalStateByBlockHash(ctx context.Context, blockHash, key string, path []string) (QueryGlobalStateResult, error)
// QueryGlobalStateByBlockHeight allows for you to query for a value stored under certain keys in global state.
QueryGlobalStateByBlockHeight(ctx context.Context, blockHeight uint64, key string, path []string) (QueryGlobalStateResult, error)
// QueryGlobalStateByStateHash allows for you to query for a value stored under certain keys in global state.
// If the param stateRootHash is nil, the client will make an additional RPC call to retrieve the latest stateRootHash.
QueryGlobalStateByStateHash(ctx context.Context, stateRootHash *string, key string, path []string) (QueryGlobalStateResult, error)
Expand Down Expand Up @@ -108,6 +112,10 @@ type ClientInformational interface {
// GetPeers return a list of peers connected to the node on a Casper network.
// The responses return information specific to the queried node, and as such, will vary.
GetPeers(ctx context.Context) (InfoGetPeerResult, error)
// QueryBalance queries for balances under a given PurseIdentifier
QueryBalance(ctx context.Context, identifier PurseIdentifier) (QueryBalanceResult, error)
// GetChainspec returns the raw bytes of the chainspec.toml, accounts.toml and global_state.toml files as read at node startup.
GetChainspec(ctx context.Context) (InfoGetChainspecResult, error)
}

// ClientTransactional contains the description of account_put_deploy,
Expand Down
3 changes: 2 additions & 1 deletion rpc/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
type RpcError struct {
Code int `json:"code"`
Message string `json:"message"`
Data string `json:"data,omitempty"`
}

func (h *RpcError) Error() string {
return h.Message
return fmt.Sprintf("key: %s, data: %s", h.Message, h.Data)
}

type HttpError struct {
Expand Down
19 changes: 19 additions & 0 deletions rpc/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const (
MethodGetStatus Method = "info_get_status"
MethodGetPeers Method = "info_get_peers"
MethodPutDeploy Method = "account_put_deploy"
MethodSpeculativeExec Method = "speculative_exec"
MethodQueryBalance Method = "query_balance"
MethodInfoGetChainspec Method = "info_get_chainspec"
)

// RpcRequest is a wrapper struct for an RPC call method that can be serialized to JSON.
Expand Down Expand Up @@ -81,6 +84,7 @@ type ParamQueryGlobalState struct {
type ParamQueryGlobalStateID struct {
StateRootHash string `json:"StateRootHash,omitempty"`
BlockHash string `json:"BlockHash,omitempty"`
BlockHeight uint64 `json:"BlockHeight,omitempty"`
}

func NewQueryGlobalStateParam(key string, path []string, id ParamQueryGlobalStateID) ParamQueryGlobalState {
Expand Down Expand Up @@ -124,3 +128,18 @@ func NewParamStateDictionaryItem(stateRootHash, uref, key string) map[string]int
},
}
}

type SpeculativeExecParams struct {
Deploy types.Deploy `json:"deploy"`
BlockIdentifier *BlockIdentifier `json:"block_identifier,omitempty"`
}

type PurseIdentifier struct {
MainPurseUnderPublicKey *keypair.PublicKey `json:"main_purse_under_public_key,omitempty"`
MainPurseUnderAccountHash *string `json:"main_purse_under_account_hash,omitempty"`
PurseUref *string `json:"purse_uref,omitempty"`
}

type QueryBalanceRequest struct {
PurseIdentifier PurseIdentifier `json:"purse_identifier"`
}
46 changes: 38 additions & 8 deletions rpc/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package rpc

import (
"encoding/json"
"time"

"github.com/make-software/casper-go-sdk/types"
"github.com/make-software/casper-go-sdk/types/clvalue"
"github.com/make-software/casper-go-sdk/types/key"
"github.com/make-software/casper-go-sdk/types/keypair"
)
Expand Down Expand Up @@ -53,6 +53,8 @@ type InfoGetDeployResult struct {
ApiVersion string `json:"api_version"`
Deploy types.Deploy `json:"deploy"`
ExecutionResults []types.DeployExecutionResult `json:"execution_results"`
BlockHash *key.Hash `json:"block_hash,omitempty"`
BlockHeight *uint64 `json:"block_height,omitempty"`
}

type ChainGetEraInfoResult struct {
Expand Down Expand Up @@ -147,23 +149,51 @@ type InfoGetStatusResult struct {
StartingStateRootHash string `json:"starting_state_root_hash"`
// Time that passed since the node has started. format "2months 20days 22h 3m 21s 512ms"
Uptime string `json:"uptime"`
// Indicating the node's current operating mode
ReactorState string `json:"reactor_state"`
// Indicating the time the node last made progress
LastProgress types.Timestamp `json:"last_progress"`
// Indicating the highest contiguous sequence of the block chain for which the node has complete data
AvailableBlockRange struct {
Low uint64 `json:"low"`
High uint64 `json:"high"`
} `json:"available_block_range"`
// Indicating the state of the block synchronizer component
BlockSync struct {
Historical string `json:"historical,omitempty"`
Forward string `json:"forward,omitempty"`
} `json:"block_sync"`
}

// NodeNextUpgrade contains the information about the next protocol upgrade.
type NodeNextUpgrade struct {
//The first era to which the associated protocol version applies.
ActivationPoint ActivationPoint `json:"activation_point"`
ActivationPoint uint64 `json:"activation_point"`
// The protocol version of the next upgrade
ProtocolVersion string `json:"protocol_version"`
}

// ActivationPoint is the first era to which the associated protocol version applies.
type ActivationPoint struct {
EraID uint32 `json:"era_id"`
Timestamp time.Time `json:"timestamp"`
}

type PutDeployResult struct {
ApiVersion string `json:"api_version"`
DeployHash key.Hash `json:"deploy_hash"`
}

type SpeculativeExecResult struct {
ApiVersion string `json:"api_version"`
DeployHash key.Hash `json:"deploy_hash"`
ExecutionResult types.ExecutionResultStatus `json:"execution_result"`
}

type QueryBalanceResult struct {
ApiVersion string `json:"api_version"`
Balance clvalue.UInt512 `json:"balance"`
}

type InfoGetChainspecResult struct {
ApiVersion string `json:"api_version"`
ChainspecBytes struct {
ChainspecBytes string `json:"chainspec_bytes,omitempty"`
MaybeGenesisAccountsBytes string `json:"maybe_genesis_accounts_bytes,omitempty"`
MaybeGlobalStateBytes string `json:"maybe_global_state_bytes,omitempty"`
} `json:"chainspec_bytes"`
}
25 changes: 25 additions & 0 deletions rpc/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ func (c *client) GetDeploy(ctx context.Context, hash string) (InfoGetDeployResul
}, &result)
}

func (c *client) GetDeployFinalizedApproval(ctx context.Context, hash string) (InfoGetDeployResult, error) {
var result InfoGetDeployResult
return result, c.processRequest(ctx, MethodGetDeploy, map[string]interface{}{
"deploy_hash": hash,
"finalized_approvals": true,
}, &result)
}

func (c *client) GetStateItem(ctx context.Context, stateRootHash *string, key string, path []string) (StateGetItemResult, error) {
if stateRootHash == nil {
latestHashResult, err := c.GetStateRootHashLatest(ctx)
Expand All @@ -57,6 +65,13 @@ func (c *client) QueryGlobalStateByBlockHash(ctx context.Context, blockHash, key
}), &result)
}

func (c *client) QueryGlobalStateByBlockHeight(ctx context.Context, blockHeight uint64, key string, path []string) (QueryGlobalStateResult, error) {
var result QueryGlobalStateResult
return result, c.processRequest(ctx, MethodQueryGlobalState, NewQueryGlobalStateParam(key, path, ParamQueryGlobalStateID{
BlockHeight: blockHeight,
}), &result)
}

func (c *client) QueryGlobalStateByStateHash(ctx context.Context, stateRootHash *string, key string, path []string) (QueryGlobalStateResult, error) {
if stateRootHash == nil {
latestHashResult, err := c.GetStateRootHashLatest(ctx)
Expand Down Expand Up @@ -221,6 +236,16 @@ func (c *client) PutDeploy(ctx context.Context, deploy types.Deploy) (PutDeployR
return result, c.processRequest(ctx, MethodPutDeploy, PutDeployRequest{Deploy: deploy}, &result)
}

func (c *client) QueryBalance(ctx context.Context, identifier PurseIdentifier) (QueryBalanceResult, error) {
var result QueryBalanceResult
return result, c.processRequest(ctx, MethodQueryBalance, QueryBalanceRequest{identifier}, &result)
}

func (c *client) GetChainspec(ctx context.Context) (InfoGetChainspecResult, error) {
var result InfoGetChainspecResult
return result, c.processRequest(ctx, MethodInfoGetChainspec, nil, &result)
}

func (c *client) processRequest(ctx context.Context, method Method, params interface{}, result any) error {
request := DefaultRpcRequest(method, params)
if reqID := GetReqIdCtx(ctx); reqID != "0" {
Expand Down
43 changes: 43 additions & 0 deletions rpc/speculative_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package rpc

import (
"context"
"encoding/json"
"fmt"

"github.com/make-software/casper-go-sdk/types"
)

type SpeculativeClient struct {
handler Handler
}

func NewSpeculativeClient(handler Handler) *SpeculativeClient {
return &SpeculativeClient{handler: handler}
}

func (c SpeculativeClient) SpeculativeExec(ctx context.Context, deploy types.Deploy, identifier *BlockIdentifier) (SpeculativeExecResult, error) {
var result SpeculativeExecResult
request := DefaultRpcRequest(MethodSpeculativeExec, SpeculativeExecParams{
Deploy: deploy,
BlockIdentifier: identifier,
})
if reqID := GetReqIdCtx(ctx); reqID != "0" {
request.ID = reqID
}
resp, err := c.handler.ProcessCall(ctx, request)
if err != nil {
return SpeculativeExecResult{}, err
}

if resp.Error != nil {
return SpeculativeExecResult{}, fmt.Errorf("rpc call failed, details: %w", resp.Error)
}

err = json.Unmarshal(resp.Result, &result)
if err != nil {
return SpeculativeExecResult{}, fmt.Errorf("%w, details: %s", ErrResultUnmarshal, err.Error())
}

return result, nil
}
82 changes: 82 additions & 0 deletions tests/data/block/block_switch_system_proposer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"hash": "b287dd3ae44e57e944bf357d50f8c09fa6a58cb3cdccebb94febf2733d243d92",
"header": {
"parent_hash": "3702837e19058988f12260689dc6cf6adf3f31d06d4b34109a4a4fda44c23e08",
"state_root_hash": "05294c6b79095e72c24544852b1d678350554e16bbd430adab4dd0b5be0bccfe",
"body_hash": "5187b7a8021bf4f2c004ea3a54cfece1754f11c7624d2363c7f4cf4fddd1441e",
"random_bit": false,
"accumulated_seed": "abd4677d96e41ffc598761b58e93ebd5ab91affcc1b7d09e4b3bc63044fcced0",
"era_end": {
"era_report": {
"equivocators": [],
"rewards": [],
"inactive_validators": []
},
"next_era_validator_weights": [
{
"validator": "0115c9b40c06ff99b0cbadf1140b061b5dbf92103e66a6330fbcc7768f5219c1ce",
"weight": "295643652543863089"
},
{
"validator": "011b19ef983c039a2a335f2f35199bf8cad5ba2c583bd709748feb76f24ffb1bab",
"weight": "294564238999375236"
},
{
"validator": "011d86fcc3e438fcb47d4d9af77e9db97ca1c322c3e87d5a4ea6f3386b9ddcd6ed",
"weight": "294159738231573499"
},
{
"validator": "017234b285929170324e1051ccd887dc08adf049650ecf5d383985b0b0048ab39b",
"weight": "284471020019645189"
},
{
"validator": "017fec504c642f2b321b8591f1c3008348c57a81acafceb5a392cf8416a5fb4a3c",
"weight": "294691173297447085"
},
{
"validator": "019e7b8bdec03ba83be4f5443d9f7f9111c77fec984ce9bb5bb7eb3da1e689c02d",
"weight": "294679465132340585"
},
{
"validator": "01cb8e121682e087058610828a6f75e8ca504321508243c7518a4047d3284f2f3c",
"weight": "292948235437478173"
}
]
},
"timestamp": "2023-05-11T18:24:49.664Z",
"era_id": 9128,
"height": 1749608,
"protocol_version": "1.5.0"
},
"body": {
"proposer": "00",
"deploy_hashes": [],
"transfer_hashes": []
},
"proofs": [
{
"public_key": "011b19ef983c039a2a335f2f35199bf8cad5ba2c583bd709748feb76f24ffb1bab",
"signature": "01f6bfd939b7797f1be4f16e597a115f38687745ad32dcd3402ef38c750b6abfb50c0918cb1e57ea25b174fa632a1f62000cc727aff703eb17c3b5f976ca17f304"
},
{
"public_key": "011d86fcc3e438fcb47d4d9af77e9db97ca1c322c3e87d5a4ea6f3386b9ddcd6ed",
"signature": "019a011ea3f5d5d5446748ae58c40f5d6f0f255dfd1a75161d84b2c280f79a523756fee665401617e765651c32dd4a10598a15e71ae08ee3b48479033db4d2f30c"
},
{
"public_key": "017234b285929170324e1051ccd887dc08adf049650ecf5d383985b0b0048ab39b",
"signature": "017664b8c0b2cdba2261ae1af6f213ad0f8812799e2fbd840b668799221c4f0a5951aa7f9e1828bbbe16fc51e1e94e5c1a935f31c3781feef7a36500c660774601"
},
{
"public_key": "017fec504c642f2b321b8591f1c3008348c57a81acafceb5a392cf8416a5fb4a3c",
"signature": "01e921e323ce23a1e7cf9453e0efdc23c0ee9001d28eb8124da73e85f0fc5fe3f6cd22008aa7053cf5c8c20813230f414238b95032f98c0ce6e09e643dfc011009"
},
{
"public_key": "019e7b8bdec03ba83be4f5443d9f7f9111c77fec984ce9bb5bb7eb3da1e689c02d",
"signature": "01fcdf5f457fbe2868e03a15bee5af2c15fa4d8fce05888fde0c7b080ffda418511c380a71c500097ff840e0e68ff0976e4c0ec74fd318554e8557a4d5b6042c06"
},
{
"public_key": "01cb8e121682e087058610828a6f75e8ca504321508243c7518a4047d3284f2f3c",
"signature": "014bee8a716df01a593a535ebf2dee20da400a99dffe1d56e07f2dfa5f947d4d5003e4ee51289e389998e4c9b45efe00a1193d7db79a67dd824d489ddf16ad820e"
}
]
}
3 changes: 2 additions & 1 deletion tests/data/contract/contract_package_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"group": "constructor",
"keys": []
}
]
],
"lock_status": "Unlocked"
}
Loading

0 comments on commit 9626f1f

Please sign in to comment.