Skip to content

Commit

Permalink
update/added_types_to_casper_namespace (#115)
Browse files Browse the repository at this point in the history
Added new types under casper namespace
  • Loading branch information
ZhmakAS authored Sep 4, 2024
1 parent 5a338e7 commit 86cfd73
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
2 changes: 2 additions & 0 deletions casper/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ type (
RpcHandler = rpc.Handler
RpcInformationalClient = rpc.ClientInformational
InfoGetDeployResult = rpc.InfoGetDeployResult
InfoGetTransactionResult = rpc.InfoGetTransactionResult
ChainGetBlockResult = rpc.ChainGetBlockResult
ChainGetEraInfoResult = rpc.ChainGetEraInfoResult
StateGetEntity = rpc.StateGetEntityResult
StateGetAuctionInfoResult = rpc.StateGetAuctionInfoResult
StateGetItemResult = rpc.StateGetItemResult
InfoGetStatusResult = rpc.InfoGetStatusResult
Expand Down
6 changes: 3 additions & 3 deletions rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ type ClientInformational interface {
GetAccountInfo(ctx context.Context, blockIdentifier *ParamBlockIdentifier, accountIdentifier AccountIdentifier) (StateGetAccountInfo, error)

// GetLatestEntity returns latest AddressableEntity from the network.
GetLatestEntity(ctx context.Context, entityIdentifier EntityIdentifier) (StateGetEntity, error)
GetLatestEntity(ctx context.Context, entityIdentifier EntityIdentifier) (StateGetEntityResult, error)
// GetEntityByBlockHash returns an AddressableEntity by block hash from the network.
GetEntityByBlockHash(ctx context.Context, entityIdentifier EntityIdentifier, hash string) (StateGetEntity, error)
GetEntityByBlockHash(ctx context.Context, entityIdentifier EntityIdentifier, hash string) (StateGetEntityResult, error)
// GetEntityByBlockHeight returns an AddressableEntity by block height from the network.
GetEntityByBlockHeight(ctx context.Context, entityIdentifier EntityIdentifier, height uint64) (StateGetEntity, error)
GetEntityByBlockHeight(ctx context.Context, entityIdentifier EntityIdentifier, height uint64) (StateGetEntityResult, error)

// GetLatestBlock returns the latest types.Block from the network.
GetLatestBlock(ctx context.Context) (ChainGetBlockResult, error)
Expand Down
15 changes: 14 additions & 1 deletion rpc/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type AddressableEntity struct {
EntryPoints []types.EntryPointValue `json:"entry_points,omitempty"`
}

type StateGetEntity struct {
type StateGetEntityResult struct {
ApiVersion string `json:"api_version"`
// The addressable entity or a legacy account.
Entity EntityOrAccount `json:"entity"`
Expand Down Expand Up @@ -217,6 +217,19 @@ type InfoGetTransactionResult struct {
rawJSON json.RawMessage
}

func NewInfoGetTransactionResult(
apiVersion string,
transaction types.Transaction,
executionInfo *types.ExecutionInfo,
rawJSON json.RawMessage) InfoGetTransactionResult {
return InfoGetTransactionResult{
APIVersion: apiVersion,
Transaction: transaction,
ExecutionInfo: executionInfo,
rawJSON: rawJSON,
}
}

func (b InfoGetTransactionResult) GetRawJSON() json.RawMessage {
return b.rawJSON
}
Expand Down
18 changes: 9 additions & 9 deletions rpc/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,36 +217,36 @@ func (c *client) QueryGlobalStateByStateHash(ctx context.Context, stateRootHash
return result, nil
}

func (c *client) GetLatestEntity(ctx context.Context, entityIdentifier EntityIdentifier) (StateGetEntity, error) {
var result StateGetEntity
func (c *client) GetLatestEntity(ctx context.Context, entityIdentifier EntityIdentifier) (StateGetEntityResult, error) {
var result StateGetEntityResult

resp, err := c.processRequest(ctx, MethodGetStateEntity, ParamGetStateEntity{EntityIdentifier: entityIdentifier}, &result)
if err != nil {
return StateGetEntity{}, err
return StateGetEntityResult{}, err
}

result.rawJSON = resp.Result
return result, nil
}

func (c *client) GetEntityByBlockHash(ctx context.Context, entityIdentifier EntityIdentifier, hash string) (StateGetEntity, error) {
var result StateGetEntity
func (c *client) GetEntityByBlockHash(ctx context.Context, entityIdentifier EntityIdentifier, hash string) (StateGetEntityResult, error) {
var result StateGetEntityResult

resp, err := c.processRequest(ctx, MethodGetStateEntity, ParamGetStateEntity{EntityIdentifier: entityIdentifier, BlockIdentifier: &BlockIdentifier{Hash: &hash}}, &result)
if err != nil {
return StateGetEntity{}, err
return StateGetEntityResult{}, err
}

result.rawJSON = resp.Result
return result, nil
}

func (c *client) GetEntityByBlockHeight(ctx context.Context, entityIdentifier EntityIdentifier, height uint64) (StateGetEntity, error) {
var result StateGetEntity
func (c *client) GetEntityByBlockHeight(ctx context.Context, entityIdentifier EntityIdentifier, height uint64) (StateGetEntityResult, error) {
var result StateGetEntityResult

resp, err := c.processRequest(ctx, MethodGetStateEntity, ParamGetStateEntity{EntityIdentifier: entityIdentifier, BlockIdentifier: &BlockIdentifier{Height: &height}}, &result)
if err != nil {
return StateGetEntity{}, err
return StateGetEntityResult{}, err
}

result.rawJSON = resp.Result
Expand Down

0 comments on commit 86cfd73

Please sign in to comment.