Skip to content

Commit

Permalink
Add Casper 2.0.0 support (#105)
Browse files Browse the repository at this point in the history
Add Casper 2.0.0 support
  • Loading branch information
ZhmakAS authored Jul 18, 2024
1 parent cf263a3 commit f75d256
Show file tree
Hide file tree
Showing 115 changed files with 10,009 additions and 508 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/quality-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: |
go mod vendor
go install -v github.com/incu6us/goimports-reviser/[email protected]
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1
- name: Format
run: go fmt ./...
Expand Down
20 changes: 12 additions & 8 deletions casper/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@ type (
AuctionState = types.AuctionState
Args = types.Args
ValidatorBid = types.ValidatorBid
AuctionBid = types.AuctionBid
Block = types.Block
BlockHeader = types.BlockHeader
BlockBody = types.BlockBody
Bid = types.Bid
BlockV1 = types.BlockV1
BlockHeaderV1 = types.BlockHeaderV1
BlockBodyV1 = types.BlockBodyV1
BlockV2 = types.BlockV2
BlockHeaderV2 = types.BlockHeaderV2
BlockBodyV2 = types.BlockBodyV2
ContractPackage = types.ContractPackage
ContractVersion = types.ContractVersion
Contract = types.Contract
Deploy = types.Deploy
DeployHeader = types.DeployHeader
DeployApproval = types.Approval
Entrypoint = types.EntryPoint
ExecutionResult = types.ExecutionResultStatus
EntryPointV1 = types.EntryPointV1
EntryPointV2 = types.EntryPointV2
ExecutionResult = types.ExecutionResult
NamedKeys = types.NamedKeys
NamedKey = types.NamedKey
TransformKey = types.TransformKey
Transform = types.Transform
Argument = types.Argument
Account = types.Account
Reward = types.Reward
Reward = types.EraReward
WriteTransfer = types.WriteTransfer
UnbondingPurse = types.UnbondingPurse
)
Expand All @@ -39,7 +43,7 @@ type (
)

var (
DefaultHeader = types.DefaultHeader
DefaultHeader = types.DefaultDeployHeader
MakeDeploy = types.MakeDeploy
StandardPayment = types.StandardPayment
)
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
module github.com/make-software/casper-go-sdk

go 1.19
go 1.21

require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1
github.com/shopspring/decimal v1.3.1
github.com/stretchr/testify v1.8.2
golang.org/x/crypto v0.18.0
golang.org/x/crypto v0.23.0
golang.org/x/sync v0.6.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/sys v0.20.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
14 changes: 4 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
80 changes: 67 additions & 13 deletions rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
// They return information related to auctions, bids and validators.
// This information is necessary for users involved with node operations and validation.
type ClientPOS interface {
// GetAuctionInfoLatest returns the types.ValidatorBid and types.EraValidators from the most recent Block.
GetAuctionInfoLatest(ctx context.Context) (StateGetAuctionInfoResult, error)
// GetLatestAuctionInfo returns the types.ValidatorBid and types.EraValidators from the most recent Block.
GetLatestAuctionInfo(ctx context.Context) (StateGetAuctionInfoResult, error)
// GetAuctionInfoByHash returns the types.ValidatorBid and types.EraValidators of either a specific Block by hash
GetAuctionInfoByHash(ctx context.Context, blockHash string) (StateGetAuctionInfoResult, error)
// GetAuctionInfoByHeight returns the types.ValidatorBid and types.EraValidators of either a specific Block by height
Expand Down Expand Up @@ -45,14 +45,24 @@ type ClientPOS interface {
// The response should be identical, regardless of the node queried,
// as the information in question is objective and common to all nodes within a network.
type ClientInformational interface {
// GetAccountBalance returns a purse's balance from a network.
// GetLatestBalance returns a purse's balance from a network.
// The request takes in the formatted representation of a purse URef as a parameter.
// If the param stateRootHash is nil, the client will make an additional RPC call to retrieve the latest stateRootHash.
GetAccountBalance(ctx context.Context, stateRootHash *string, purseURef string) (StateGetBalanceResult, error)
// The client will make an additional RPC call to retrieve the latest stateRootHash.
GetLatestBalance(ctx context.Context, purseURef string) (StateGetBalanceResult, error)
// GetBalanceByStateRootHash returns a purse's balance and state root hash from a network.
GetBalanceByStateRootHash(ctx context.Context, purseURef string, stateRootHash 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)
// GetTransactionByTransactionHash returns a Transaction from the network
GetTransactionByTransactionHash(ctx context.Context, transactionHash string) (InfoGetTransactionResult, error)
// GetTransactionByDeployHash returns a Deploy as Transaction from the network
GetTransactionByDeployHash(ctx context.Context, deployHash string) (InfoGetTransactionResult, error)
// GetTransactionFinalizedApprovalByTransactionHash return the Transaction with the finalized approvals substituted.
GetTransactionFinalizedApprovalByTransactionHash(ctx context.Context, transactionHash string) (InfoGetTransactionResult, error)
// GetTransactionFinalizedApprovalByDeployHash return the Deploy as Transaction with the finalized approvals substituted.
GetTransactionFinalizedApprovalByDeployHash(ctx context.Context, deployHash string) (InfoGetTransactionResult, error)
// GetDictionaryItem returns an item from a Dictionary.
// The address of a stored value is the blake2b hash of the seed URef and the byte representation of the dictionary key.
// If the param stateRootHash is nil, the client will make an additional RPC call to retrieve the latest stateRootHash.
Expand All @@ -65,6 +75,8 @@ type ClientInformational interface {
// Deprecated: use QueryGlobalStateByStateHash instead
GetStateItem(ctx context.Context, stateRootHash *string, key string, path []string) (StateGetItemResult, error)

// QueryLatestGlobalState allows for you to query for the latest value stored under certain keys in global state.
QueryLatestGlobalState(ctx context.Context, key string, path []string) (QueryGlobalStateResult, error)
// 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.
Expand All @@ -83,15 +95,22 @@ type ClientInformational interface {
// This is the most generic interface.
GetAccountInfo(ctx context.Context, blockIdentifier *ParamBlockIdentifier, accountIdentifier AccountIdentifier) (StateGetAccountInfo, error)

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

// GetLatestBlock returns the latest types.Block from the network.
GetLatestBlock(ctx context.Context) (ChainGetBlockResult, error)
// GetBlockByHash returns the types.Block from the network the requested block hash.
GetBlockByHash(ctx context.Context, hash string) (ChainGetBlockResult, error)
// GetBlockByHeight returns the types.Block from the network the requested block height.
GetBlockByHeight(ctx context.Context, height uint64) (ChainGetBlockResult, error)

// GetBlockTransfersLatest returns all native transfers within a lasted Block from a network.
GetBlockTransfersLatest(ctx context.Context) (ChainGetBlockTransfersResult, error)
// GetLatestBlockTransfers returns all native transfers within a lasted Block from a network.
GetLatestBlockTransfers(ctx context.Context) (ChainGetBlockTransfersResult, error)
// GetBlockTransfersByHash returns all native transfers within a given Block from a network the requested block hash.
GetBlockTransfersByHash(ctx context.Context, blockHash string) (ChainGetBlockTransfersResult, error)
// GetBlockTransfersByHeight returns all native transfers within a given Block from a network the requested block height.
Expand All @@ -117,16 +136,51 @@ 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)

// QueryLatestBalance queries for balances under a given PurseIdentifier
QueryLatestBalance(ctx context.Context, identifier PurseIdentifier) (QueryBalanceResult, error)
// QueryBalanceByBlockHeight query for balance information using a purse identifier and block height
QueryBalanceByBlockHeight(ctx context.Context, purseIdentifier PurseIdentifier, height uint64) (QueryBalanceResult, error)
// QueryBalanceByBlockHash query for balance information using a purse identifier and block hash
QueryBalanceByBlockHash(ctx context.Context, purseIdentifier PurseIdentifier, blockHash string) (QueryBalanceResult, error)
// QueryBalanceByStateRootHash query for full balance information using a purse identifier and state root hash
QueryBalanceByStateRootHash(ctx context.Context, purseIdentifier PurseIdentifier, stateRootHash string) (QueryBalanceResult, error)

// QueryLatestBalanceDetails query for full balance information using a purse identifier
QueryLatestBalanceDetails(ctx context.Context, purseIdentifier PurseIdentifier) (QueryBalanceDetailsResult, error)
// QueryBalanceDetailsByBlockHeight query for full balance information using a purse identifier and block height
QueryBalanceDetailsByBlockHeight(ctx context.Context, purseIdentifier PurseIdentifier, height uint64) (QueryBalanceDetailsResult, error)
// QueryBalanceDetailsByBlockHash query for full balance information using a purse identifier and block hash
QueryBalanceDetailsByBlockHash(ctx context.Context, purseIdentifier PurseIdentifier, blockHash string) (QueryBalanceDetailsResult, error)
// QueryBalanceDetailsByStateRootHash query for full balance information using a purse identifier and state root hash
QueryBalanceDetailsByStateRootHash(ctx context.Context, purseIdentifier PurseIdentifier, stateRootHash string) (QueryBalanceDetailsResult, 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)

// GetLatestValidatorReward returns the latest reward for a given validator
GetLatestValidatorReward(ctx context.Context, validator keypair.PublicKey) (InfoGetRewardResult, error)
// GetValidatorRewardByEraID returns the reward for a given era and a validator
GetValidatorRewardByEraID(ctx context.Context, validator keypair.PublicKey, eraID uint64) (InfoGetRewardResult, error)
// GetValidatorRewardByBlockHash returns the reward for a given block hash and a validator
GetValidatorRewardByBlockHash(ctx context.Context, validator keypair.PublicKey, blockHash string) (InfoGetRewardResult, error)
// GetValidatorRewardByBlockHeight returns the reward for a given block height and a validator
GetValidatorRewardByBlockHeight(ctx context.Context, validator keypair.PublicKey, height uint64) (InfoGetRewardResult, error)
// GetLatestDelegatorReward returns the latest delegator reward for a given validator
GetLatestDelegatorReward(ctx context.Context, validator, delegator keypair.PublicKey) (InfoGetRewardResult, error)
// GetDelegatorRewardByEraID returns the delegator reward for a given era and a validator
GetDelegatorRewardByEraID(ctx context.Context, validator, delegator keypair.PublicKey, eraID uint64) (InfoGetRewardResult, error)
// GetDelegatorRewardByBlockHash returns the delegator reward for a given block hash and a validator
GetDelegatorRewardByBlockHash(ctx context.Context, validator, delegator keypair.PublicKey, blockHash string) (InfoGetRewardResult, error)
// GetDelegatorRewardByBlockHeight returns the delegator reward for a given block height and a validator
GetDelegatorRewardByBlockHeight(ctx context.Context, validator, delegator keypair.PublicKey, height uint64) (InfoGetRewardResult, error)
}

// ClientTransactional contains the description of account_put_deploy,
// the only means by which users can send their compiled Wasm (as part of a Deploy) to a node on a Casper network.
// ClientTransactional contains the description of account_put_deploy, account_put_transaction
// the only means by which users can send their compiled Wasm (as part of a Deploy or TransactionV1) to a node on a Casper network.
type ClientTransactional interface {
PutDeploy(ctx context.Context, deploy types.Deploy) (PutDeployResult, error)
PutTransactionV1(ctx context.Context, transaction types.TransactionV1) (PutTransactionResult, error)
}

// Client interface represent full RPC client that includes all possible queries.
Expand Down
Loading

0 comments on commit f75d256

Please sign in to comment.