diff --git a/Cargo.lock b/Cargo.lock index 4aeef3dd..f7c10097 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -467,7 +467,7 @@ dependencies = [ [[package]] name = "casper-binary-port" version = "1.0.0" -source = "git+https://github.com/jacek-casper/casper-node?branch=items-by-prefix-query#835523fb6ac996335fe5d3c445fcb9b32682c187" +source = "git+https://github.com/jacek-casper/casper-node?branch=items-by-prefix-query#faac2cc2e4e94a301013c82f2daa61fe0772f1cc" dependencies = [ "bincode", "bytes", @@ -666,7 +666,7 @@ dependencies = [ [[package]] name = "casper-types" version = "5.0.0" -source = "git+https://github.com/jacek-casper/casper-node?branch=items-by-prefix-query#835523fb6ac996335fe5d3c445fcb9b32682c187" +source = "git+https://github.com/jacek-casper/casper-node?branch=items-by-prefix-query#faac2cc2e4e94a301013c82f2daa61fe0772f1cc" dependencies = [ "base16", "base64 0.13.1", diff --git a/resources/test/rpc_schema.json b/resources/test/rpc_schema.json index a8c7a29d..d33e9f3d 100644 --- a/resources/test/rpc_schema.json +++ b/resources/test/rpc_schema.json @@ -808,18 +808,6 @@ "package_hash": "package-0000000000000000000000000000000000000000000000000000000000000000", "byte_code_hash": "byte-code-0000000000000000000000000000000000000000000000000000000000000000", "main_purse": "uref-09480c3248ef76b603d386f3f4f8a5f87f597d4eaffd475433f861af187ab5db-007", - "entry_points": [ - { - "name": "call", - "entry_point": { - "name": "call", - "args": [], - "ret": "Unit", - "access": "Public", - "entry_point_type": "Caller" - } - } - ], "associated_keys": [ { "account_hash": "account-hash-e94daaff79c2ab8d9c31d9c3058d7d0a0dd31204a5638dc1451fa67b2e3fb88c", @@ -3462,6 +3450,13 @@ "enum": [ "VmCasperV1" ] + }, + { + "description": "The Casper Version 2 Virtual Machine.", + "type": "string", + "enum": [ + "VmCasperV2" + ] } ] }, @@ -3562,6 +3557,13 @@ "enum": [ "ActivateBid" ] + }, + { + "description": "The `change_bid_public_key` native entry point, used to change a bid's public key.", + "type": "string", + "enum": [ + "ChangeBidPublicKey" + ] } ] }, @@ -4802,6 +4804,19 @@ } }, "additionalProperties": false + }, + { + "description": "A bridge record pointing to a new `ValidatorBid` after the public key was changed.", + "type": "object", + "required": [ + "Bridge" + ], + "properties": { + "Bridge": { + "$ref": "#/components/schemas/Bridge" + } + }, + "additionalProperties": false } ] }, @@ -4864,6 +4879,42 @@ }, "additionalProperties": false }, + "Bridge": { + "description": "A bridge record pointing to a new `ValidatorBid` after the public key was changed.", + "type": "object", + "required": [ + "era_id", + "new_validator_public_key", + "old_validator_public_key" + ], + "properties": { + "old_validator_public_key": { + "description": "Previous validator public key associated with the bid.", + "allOf": [ + { + "$ref": "#/components/schemas/PublicKey" + } + ] + }, + "new_validator_public_key": { + "description": "New validator public key associated with the bid.", + "allOf": [ + { + "$ref": "#/components/schemas/PublicKey" + } + ] + }, + "era_id": { + "description": "Era when bridge record was created.", + "allOf": [ + { + "$ref": "#/components/schemas/EraId" + } + ] + } + }, + "additionalProperties": false + }, "ExecutionResultV2": { "description": "The result of executing a single transaction.", "type": "object", @@ -5498,6 +5549,19 @@ } }, "additionalProperties": false + }, + { + "description": "An entrypoint record.", + "type": "object", + "required": [ + "EntryPoint" + ], + "properties": { + "EntryPoint": { + "$ref": "#/components/schemas/EntryPointValue" + } + }, + "additionalProperties": false } ] }, @@ -5951,7 +6015,6 @@ "associated_keys", "byte_code_hash", "entity_kind", - "entry_points", "main_purse", "message_topics", "package_hash", @@ -5973,9 +6036,6 @@ "main_purse": { "$ref": "#/components/schemas/URef" }, - "entry_points": { - "$ref": "#/components/schemas/Array_of_NamedEntryPoint" - }, "associated_keys": { "$ref": "#/components/schemas/EntityAssociatedKeys" }, @@ -6018,10 +6078,16 @@ }, { "description": "Packages associated with Wasm stored on chain.", - "type": "string", - "enum": [ + "type": "object", + "required": [ "SmartContract" - ] + ], + "properties": { + "SmartContract": { + "$ref": "#/components/schemas/TransactionRuntime" + } + }, + "additionalProperties": false } ] }, @@ -6371,6 +6437,120 @@ } } }, + "EntryPointValue": { + "description": "The encaspulated representation of entrypoints.", + "oneOf": [ + { + "description": "Entrypoints to be executed against the V1 Casper VM.", + "type": "object", + "required": [ + "V1CasperVm" + ], + "properties": { + "V1CasperVm": { + "$ref": "#/components/schemas/EntryPoint2" + } + }, + "additionalProperties": false + }, + { + "description": "Entrypoints to be executed against the V2 Casper VM.", + "type": "object", + "required": [ + "V2CasperVm" + ], + "properties": { + "V2CasperVm": { + "$ref": "#/components/schemas/EntryPointV2" + } + }, + "additionalProperties": false + } + ] + }, + "EntryPoint2": { + "description": "Type signature of a method. Order of arguments matter since can be referenced by index as well as name.", + "type": "object", + "required": [ + "access", + "args", + "entry_point_payment", + "entry_point_type", + "name", + "ret" + ], + "properties": { + "name": { + "type": "string" + }, + "args": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Parameter" + } + }, + "ret": { + "$ref": "#/components/schemas/CLType" + }, + "access": { + "$ref": "#/components/schemas/EntryPointAccess" + }, + "entry_point_type": { + "$ref": "#/components/schemas/EntryPointType" + }, + "entry_point_payment": { + "$ref": "#/components/schemas/EntryPointPayment" + } + } + }, + "EntryPointPayment": { + "description": "An enum specifying who pays for the invocation and execution of the entrypoint.", + "oneOf": [ + { + "description": "The caller must cover cost", + "type": "string", + "enum": [ + "Caller" + ] + }, + { + "description": "Will cover cost to execute self but not cost of any subsequent invoked contracts", + "type": "string", + "enum": [ + "SelfOnly" + ] + }, + { + "description": "will cover cost to execute self and the cost of any subsequent invoked contracts", + "type": "string", + "enum": [ + "SelfOnward" + ] + } + ] + }, + "EntryPointV2": { + "description": "The entry point for the V2 Casper VM.", + "type": "object", + "required": [ + "flags", + "function_index" + ], + "properties": { + "function_index": { + "description": "The selector.", + "type": "integer", + "format": "uint32", + "minimum": 0.0 + }, + "flags": { + "description": "The flags.", + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + } + }, "TransformError": { "description": "Error type for applying and combining transforms.\n\nA `TypeMismatch` occurs when a transform cannot be applied because the types are not compatible (e.g. trying to add a number to a string).", "oneOf": [ diff --git a/resources/test/speculative_rpc_schema.json b/resources/test/speculative_rpc_schema.json index 522beeb6..d2f01418 100644 --- a/resources/test/speculative_rpc_schema.json +++ b/resources/test/speculative_rpc_schema.json @@ -1726,6 +1726,19 @@ } }, "additionalProperties": false + }, + { + "description": "An entrypoint record.", + "type": "object", + "required": [ + "EntryPoint" + ], + "properties": { + "EntryPoint": { + "$ref": "#/components/schemas/EntryPointValue" + } + }, + "additionalProperties": false } ] }, @@ -2646,7 +2659,6 @@ "associated_keys", "byte_code_hash", "entity_kind", - "entry_points", "main_purse", "message_topics", "package_hash", @@ -2668,9 +2680,6 @@ "main_purse": { "$ref": "#/components/schemas/URef" }, - "entry_points": { - "$ref": "#/components/schemas/Array_of_NamedEntryPoint" - }, "associated_keys": { "$ref": "#/components/schemas/EntityAssociatedKeys" }, @@ -2713,10 +2722,16 @@ }, { "description": "Packages associated with Wasm stored on chain.", - "type": "string", - "enum": [ + "type": "object", + "required": [ "SmartContract" - ] + ], + "properties": { + "SmartContract": { + "$ref": "#/components/schemas/TransactionRuntime" + } + }, + "additionalProperties": false } ] }, @@ -2753,6 +2768,25 @@ } ] }, + "TransactionRuntime": { + "description": "Runtime used to execute a Transaction.", + "oneOf": [ + { + "description": "The Casper Version 1 Virtual Machine.", + "type": "string", + "enum": [ + "VmCasperV1" + ] + }, + { + "description": "The Casper Version 2 Virtual Machine.", + "type": "string", + "enum": [ + "VmCasperV2" + ] + } + ] + }, "ByteCodeHash": { "description": "The hash address of the contract wasm", "type": "string" @@ -2876,6 +2910,19 @@ } }, "additionalProperties": false + }, + { + "description": "A bridge record pointing to a new `ValidatorBid` after the public key was changed.", + "type": "object", + "required": [ + "Bridge" + ], + "properties": { + "Bridge": { + "$ref": "#/components/schemas/Bridge" + } + }, + "additionalProperties": false } ] }, @@ -2938,6 +2985,42 @@ }, "additionalProperties": false }, + "Bridge": { + "description": "A bridge record pointing to a new `ValidatorBid` after the public key was changed.", + "type": "object", + "required": [ + "era_id", + "new_validator_public_key", + "old_validator_public_key" + ], + "properties": { + "old_validator_public_key": { + "description": "Previous validator public key associated with the bid.", + "allOf": [ + { + "$ref": "#/components/schemas/PublicKey" + } + ] + }, + "new_validator_public_key": { + "description": "New validator public key associated with the bid.", + "allOf": [ + { + "$ref": "#/components/schemas/PublicKey" + } + ] + }, + "era_id": { + "description": "Era when bridge record was created.", + "allOf": [ + { + "$ref": "#/components/schemas/EraId" + } + ] + } + }, + "additionalProperties": false + }, "Package": { "description": "Entity definition, metadata, and security container.", "type": "object", @@ -3169,6 +3252,120 @@ } } }, + "EntryPointValue": { + "description": "The encaspulated representation of entrypoints.", + "oneOf": [ + { + "description": "Entrypoints to be executed against the V1 Casper VM.", + "type": "object", + "required": [ + "V1CasperVm" + ], + "properties": { + "V1CasperVm": { + "$ref": "#/components/schemas/EntryPoint2" + } + }, + "additionalProperties": false + }, + { + "description": "Entrypoints to be executed against the V2 Casper VM.", + "type": "object", + "required": [ + "V2CasperVm" + ], + "properties": { + "V2CasperVm": { + "$ref": "#/components/schemas/EntryPointV2" + } + }, + "additionalProperties": false + } + ] + }, + "EntryPoint2": { + "description": "Type signature of a method. Order of arguments matter since can be referenced by index as well as name.", + "type": "object", + "required": [ + "access", + "args", + "entry_point_payment", + "entry_point_type", + "name", + "ret" + ], + "properties": { + "name": { + "type": "string" + }, + "args": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Parameter" + } + }, + "ret": { + "$ref": "#/components/schemas/CLType" + }, + "access": { + "$ref": "#/components/schemas/EntryPointAccess" + }, + "entry_point_type": { + "$ref": "#/components/schemas/EntryPointType" + }, + "entry_point_payment": { + "$ref": "#/components/schemas/EntryPointPayment" + } + } + }, + "EntryPointPayment": { + "description": "An enum specifying who pays for the invocation and execution of the entrypoint.", + "oneOf": [ + { + "description": "The caller must cover cost", + "type": "string", + "enum": [ + "Caller" + ] + }, + { + "description": "Will cover cost to execute self but not cost of any subsequent invoked contracts", + "type": "string", + "enum": [ + "SelfOnly" + ] + }, + { + "description": "will cover cost to execute self and the cost of any subsequent invoked contracts", + "type": "string", + "enum": [ + "SelfOnward" + ] + } + ] + }, + "EntryPointV2": { + "description": "The entry point for the V2 Casper VM.", + "type": "object", + "required": [ + "flags", + "function_index" + ], + "properties": { + "function_index": { + "description": "The selector.", + "type": "integer", + "format": "uint32", + "minimum": 0.0 + }, + "flags": { + "description": "The flags.", + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + } + }, "U128": { "description": "Decimal representation of a 128-bit integer.", "type": "string" @@ -3782,18 +3979,6 @@ } ] }, - "TransactionRuntime": { - "description": "Runtime used to execute a Transaction.", - "oneOf": [ - { - "description": "The Casper Version 1 Virtual Machine.", - "type": "string", - "enum": [ - "VmCasperV1" - ] - } - ] - }, "TransactionSessionKind": { "description": "Session kind of a Transaction.", "oneOf": [ @@ -3891,6 +4076,13 @@ "enum": [ "ActivateBid" ] + }, + { + "description": "The `change_bid_public_key` native entry point, used to change a bid's public key.", + "type": "string", + "enum": [ + "ChangeBidPublicKey" + ] } ] }, diff --git a/rpc_sidecar/src/node_client.rs b/rpc_sidecar/src/node_client.rs index 89e84d13..5ddaea10 100644 --- a/rpc_sidecar/src/node_client.rs +++ b/rpc_sidecar/src/node_client.rs @@ -102,7 +102,7 @@ pub trait NodeClient: Send + Sync { parse_response::>(&resp.into())?.ok_or(Error::EmptyEnvelope) } - async fn get_balance( + async fn read_balance( &self, state_identifier: Option, purse_identifier: PurseIdentifier, diff --git a/rpc_sidecar/src/rpcs/state.rs b/rpc_sidecar/src/rpcs/state.rs index 53078c6e..dca253f4 100644 --- a/rpc_sidecar/src/rpcs/state.rs +++ b/rpc_sidecar/src/rpcs/state.rs @@ -284,7 +284,7 @@ impl RpcWithParams for GetBalance { let state_id = GlobalStateIdentifier::StateRootHash(params.state_root_hash); let purse_id = PortPurseIdentifier::Purse(purse_uref); let balance = node_client - .get_balance(Some(state_id), purse_id) + .read_balance(Some(state_id), purse_id) .await .map_err(|err| Error::NodeRequest("balance", err))?; @@ -947,9 +947,9 @@ impl RpcWithParams for QueryBalance { ) -> Result { let purse_id = params.purse_identifier.into_port_purse_identifier(); let balance = node_client - .get_balance(params.state_identifier, purse_id) + .read_balance(params.state_identifier, purse_id) .await - .map_err(|err| Error::NodeRequest("balance by state root", err))?; + .map_err(|err| Error::NodeRequest("balance", err))?; Ok(Self::ResponseResult { api_version: CURRENT_API_VERSION, balance: balance.available_balance, @@ -1020,9 +1020,9 @@ impl RpcWithParams for QueryBalanceDetails { ) -> Result { let purse_id = params.purse_identifier.into_port_purse_identifier(); let balance = node_client - .get_balance(params.state_identifier, purse_id) + .read_balance(params.state_identifier, purse_id) .await - .map_err(|err| Error::NodeRequest("balance by state root", err))?; + .map_err(|err| Error::NodeRequest("balance", err))?; let holds = balance .balance_holds @@ -1134,15 +1134,15 @@ mod tests { use casper_binary_port::{ BalanceResponse, BinaryRequest, BinaryResponse, BinaryResponseAndRequest, DictionaryQueryResult, GetRequest, GlobalStateQueryResult, GlobalStateRequest, - InformationRequestTag, + InformationRequestTag, KeyPrefix, }; use casper_types::{ addressable_entity::{MessageTopics, NamedKeyValue, NamedKeys}, global_state::{TrieMerkleProof, TrieMerkleProofStep}, system::auction::{Bid, BidKind, ValidatorBid}, testing::TestRng, - AccessRights, AddressableEntity, Block, ByteCodeHash, EntityKind, EntryPoints, KeyPrefix, - PackageHash, ProtocolVersion, TestBlockBuilder, + AccessRights, AddressableEntity, Block, ByteCodeHash, EntityKind, PackageHash, + ProtocolVersion, TestBlockBuilder, TransactionRuntime, }; use pretty_assertions::assert_eq; use rand::Rng; @@ -1458,13 +1458,12 @@ mod tests { let entity = AddressableEntity::new( PackageHash::new(rng.gen()), ByteCodeHash::new(rng.gen()), - EntryPoints::default(), ProtocolVersion::V1_0_0, rng.gen(), AssociatedKeys::default(), ActionThresholds::default(), MessageTopics::default(), - EntityKind::SmartContract, + EntityKind::SmartContract(TransactionRuntime::VmCasperV2), ); let entity_hash: AddressableEntityHash = rng.gen(); @@ -2073,11 +2072,7 @@ mod tests { ) -> Result { match req { BinaryRequest::Get(GetRequest::State(req)) - if matches!( - &*req, - GlobalStateRequest::BalanceByBlock { .. } - | GlobalStateRequest::BalanceByStateRoot { .. } - ) => + if matches!(&*req, GlobalStateRequest::Balance { .. }) => { Ok(BinaryResponseAndRequest::new( BinaryResponse::from_value(self.0.clone(), SUPPORTED_PROTOCOL_VERSION),