diff --git a/Cargo.lock b/Cargo.lock index f6fff116..4505ea97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -471,7 +471,7 @@ dependencies = [ [[package]] name = "casper-binary-port" version = "1.0.0" -source = "git+https://github.com/casper-network/casper-node.git?branch=feat-2.0#e6456b709ec1da1c6b703db2a04beeba960651c5" +source = "git+https://github.com/casper-network/casper-node.git?branch=feat-2.0#79714924f7a83d98e0d3037fef60fcb66ce4ef54" dependencies = [ "bincode", "bytes", @@ -673,7 +673,7 @@ dependencies = [ [[package]] name = "casper-types" version = "5.0.0" -source = "git+https://github.com/casper-network/casper-node.git?branch=feat-2.0#e6456b709ec1da1c6b703db2a04beeba960651c5" +source = "git+https://github.com/casper-network/casper-node.git?branch=feat-2.0#79714924f7a83d98e0d3037fef60fcb66ce4ef54" dependencies = [ "base16", "base64 0.13.1", @@ -2864,13 +2864,13 @@ checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] name = "num-derive" -version = "0.3.3" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 1.0.109", + "syn 2.0.77", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 0c64330a..2888a3e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ members = [ anyhow = "1" async-stream = "0.3.4" async-trait = "0.1.77" -casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" } +casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0", features = ["json-schema"]} casper-binary-port = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" } casper-event-sidecar = { path = "./event_sidecar", version = "1.0.0" } casper-event-types = { path = "./types", version = "1.0.0" } diff --git a/listener/src/connection_manager.rs b/listener/src/connection_manager.rs index 8b63a2cd..24c01135 100644 --- a/listener/src/connection_manager.rs +++ b/listener/src/connection_manager.rs @@ -460,7 +460,7 @@ pub mod tests { if let Ok(Err(ConnectionManagerError::NonRecoverableError { error })) = res { assert_eq!( error.to_string(), - "Serde Error: Couldn't deserialize Serde Error: expected value at line 1 column 1" + "Serde Error: Couldn't deserialize Error when deserializing SSE event from node: expected value at line 1 column 1" ) } else { unreachable!(); diff --git a/resources/test/rpc_schema.json b/resources/test/rpc_schema.json index 09e16e1a..ad0d5102 100644 --- a/resources/test/rpc_schema.json +++ b/resources/test/rpc_schema.json @@ -166,70 +166,31 @@ "name": "transaction", "value": { "Version1": { - "serialization_version": 1, - "hash": "df4f6e95afd24c3bdac68862cfd888fea65912f0f3e3de9c42b24cee79b7a581", - "header": { - "chain_name": "casper-example", + "hash": "ee6b9196dda4cd446d7ac2cfe8d3b76f3d66757f107ac578f878921df7024c26", + "payload": { + "initiator_addr": { + "PublicKey": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c" + }, "timestamp": "2020-11-17T00:39:24.072Z", "ttl": "1h", - "body_hash": "7bf1a4f736a9cbb2b692b74522d981213c3a5463d0095ded40d1454cf1b779e1", + "chain_name": "casper-example", "pricing_mode": { "Fixed": { + "additional_computation_factor": 0, "gas_price_tolerance": 5 } }, - "initiator_addr": { - "PublicKey": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c" + "fields": { + "0": "0400000006000000736f7572636522000000010a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a070d0c06000000746172676574210000001b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b000c06000000616d6f756e74060000000500ac23fc06080200000069640900000001e7030000000000000d05", + "1": "010000000000000000000100000000", + "2": "010000000000000000000100000002", + "3": "010000000000000000000100000000" } }, - "body": { - "args": [ - [ - "source", - { - "cl_type": { - "Option": "URef" - }, - "bytes": "010a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a07", - "parsed": "uref-0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a-007" - } - ], - [ - "target", - { - "cl_type": "URef", - "bytes": "1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b00", - "parsed": "uref-1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b-000" - } - ], - [ - "amount", - { - "cl_type": "U512", - "bytes": "0500ac23fc06", - "parsed": "30000000000" - } - ], - [ - "id", - { - "cl_type": { - "Option": "U64" - }, - "bytes": "01e703000000000000", - "parsed": 999 - } - ] - ], - "target": "Native", - "entry_point": "Transfer", - "transaction_category": 0, - "scheduling": "Standard" - }, "approvals": [ { "signer": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c", - "signature": "015b407723d54bdfd376d43776d9b92ea465d7ec2e0d41e28b5f646fc17400193bc4e075cab4e8943de09935e3aa96d0bbe456382c2274689b6847a35a94d07309" + "signature": "0167407d6fd18f67fe8f46407c2c5148a39f01905fe00040c477717e10d5fa3fefada76fe2f35e711a1d0a3e7b5bf322a6eddf5ae6227efdc730706860b6f4820a" } ] } @@ -241,7 +202,7 @@ "value": { "api_version": "2.0.0", "transaction_hash": { - "Version1": "df4f6e95afd24c3bdac68862cfd888fea65912f0f3e3de9c42b24cee79b7a581" + "Version1": "ee6b9196dda4cd446d7ac2cfe8d3b76f3d66757f107ac578f878921df7024c26" } } } @@ -371,7 +332,7 @@ ] }, "execution_info": { - "block_hash": "0744fcb72af43c5cc372039bc5a8bfee48808a9ce414acc0d6338a628c20eb42", + "block_hash": "1f8187a82bd4b28948add6f8c0ea15a8aac6160088dbc281499fdcf2f0d95a79", "block_height": 10, "execution_result": { "Version2": { @@ -488,7 +449,7 @@ { "name": "transaction_hash", "value": { - "Version1": "df4f6e95afd24c3bdac68862cfd888fea65912f0f3e3de9c42b24cee79b7a581" + "Version1": "ee6b9196dda4cd446d7ac2cfe8d3b76f3d66757f107ac578f878921df7024c26" } }, { @@ -502,76 +463,37 @@ "api_version": "2.0.0", "transaction": { "Version1": { - "serialization_version": 1, - "hash": "df4f6e95afd24c3bdac68862cfd888fea65912f0f3e3de9c42b24cee79b7a581", - "header": { - "chain_name": "casper-example", + "hash": "ee6b9196dda4cd446d7ac2cfe8d3b76f3d66757f107ac578f878921df7024c26", + "payload": { + "initiator_addr": { + "PublicKey": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c" + }, "timestamp": "2020-11-17T00:39:24.072Z", "ttl": "1h", - "body_hash": "7bf1a4f736a9cbb2b692b74522d981213c3a5463d0095ded40d1454cf1b779e1", + "chain_name": "casper-example", "pricing_mode": { "Fixed": { + "additional_computation_factor": 0, "gas_price_tolerance": 5 } }, - "initiator_addr": { - "PublicKey": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c" + "fields": { + "0": "0400000006000000736f7572636522000000010a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a070d0c06000000746172676574210000001b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b000c06000000616d6f756e74060000000500ac23fc06080200000069640900000001e7030000000000000d05", + "1": "010000000000000000000100000000", + "2": "010000000000000000000100000002", + "3": "010000000000000000000100000000" } }, - "body": { - "args": [ - [ - "source", - { - "cl_type": { - "Option": "URef" - }, - "bytes": "010a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a07", - "parsed": "uref-0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a-007" - } - ], - [ - "target", - { - "cl_type": "URef", - "bytes": "1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b00", - "parsed": "uref-1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b-000" - } - ], - [ - "amount", - { - "cl_type": "U512", - "bytes": "0500ac23fc06", - "parsed": "30000000000" - } - ], - [ - "id", - { - "cl_type": { - "Option": "U64" - }, - "bytes": "01e703000000000000", - "parsed": 999 - } - ] - ], - "target": "Native", - "entry_point": "Transfer", - "transaction_category": 0, - "scheduling": "Standard" - }, "approvals": [ { "signer": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c", - "signature": "015b407723d54bdfd376d43776d9b92ea465d7ec2e0d41e28b5f646fc17400193bc4e075cab4e8943de09935e3aa96d0bbe456382c2274689b6847a35a94d07309" + "signature": "0167407d6fd18f67fe8f46407c2c5148a39f01905fe00040c477717e10d5fa3fefada76fe2f35e711a1d0a3e7b5bf322a6eddf5ae6227efdc730706860b6f4820a" } ] } }, "execution_info": { - "block_hash": "0744fcb72af43c5cc372039bc5a8bfee48808a9ce414acc0d6338a628c20eb42", + "block_hash": "1f8187a82bd4b28948add6f8c0ea15a8aac6160088dbc281499fdcf2f0d95a79", "block_height": 10, "execution_result": { "Version2": { @@ -1136,7 +1058,7 @@ { "name": "state_identifier", "value": { - "BlockHash": "0744fcb72af43c5cc372039bc5a8bfee48808a9ce414acc0d6338a628c20eb42" + "BlockHash": "1f8187a82bd4b28948add6f8c0ea15a8aac6160088dbc281499fdcf2f0d95a79" } }, { @@ -1589,7 +1511,7 @@ "chainspec_name": "casper-example", "starting_state_root_hash": "0000000000000000000000000000000000000000000000000000000000000000", "last_added_block_info": { - "hash": "0744fcb72af43c5cc372039bc5a8bfee48808a9ce414acc0d6338a628c20eb42", + "hash": "1f8187a82bd4b28948add6f8c0ea15a8aac6160088dbc281499fdcf2f0d95a79", "timestamp": "2020-11-17T00:39:24.072Z", "era_id": 1, "height": 10, @@ -1885,7 +1807,7 @@ { "name": "block_identifier", "value": { - "Hash": "0744fcb72af43c5cc372039bc5a8bfee48808a9ce414acc0d6338a628c20eb42" + "Hash": "1f8187a82bd4b28948add6f8c0ea15a8aac6160088dbc281499fdcf2f0d95a79" } } ], @@ -1896,11 +1818,11 @@ "block_with_signatures": { "block": { "Version2": { - "hash": "0744fcb72af43c5cc372039bc5a8bfee48808a9ce414acc0d6338a628c20eb42", + "hash": "1f8187a82bd4b28948add6f8c0ea15a8aac6160088dbc281499fdcf2f0d95a79", "header": { "parent_hash": "0707070707070707070707070707070707070707070707070707070707070707", "state_root_hash": "0808080808080808080808080808080808080808080808080808080808080808", - "body_hash": "48859fb4865d8637d6a35cb224e222cd0e1b1c2dd72928932c1e35ac0550818b", + "body_hash": "a5fe75ebf2edca0b9156bb968b66936325c7b59ae96d34027c132fd09555af8b", "random_bit": true, "accumulated_seed": "ac979f51525cfd979b14aa7dc0737c5154eabe0db9280eceaa8dc8d2905b20d5", "era_end": { @@ -1951,11 +1873,6 @@ { "Version1": "1616161616161616161616161616161616161616161616161616161616161616" } - ], - "3": [ - { - "Version1": "1717171717171717171717171717171717171717171717171717171717171717" - } ] }, "rewarded_signatures": [] @@ -1965,7 +1882,7 @@ "proofs": [ { "public_key": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c", - "signature": "01e18ca03d2ef0238a6a2460a222e0b818406bda99d4c05502c80232013559b926d1c8bca6bf65386f54a847d7850cb76c0c5fd5e633c34c749b8b9958a638d806" + "signature": "01cf38841e5eebba855671fcf9ea88524cb289c67bd63b14ddc97366554f95580b59ae2f4b9bcba449bed91a1502429ca0dca8a74d37b9d32e8070b00a21b00d0e" } ] } @@ -2342,7 +2259,7 @@ { "name": "block_identifier", "value": { - "Hash": "0744fcb72af43c5cc372039bc5a8bfee48808a9ce414acc0d6338a628c20eb42" + "Hash": "1f8187a82bd4b28948add6f8c0ea15a8aac6160088dbc281499fdcf2f0d95a79" } } ], @@ -2351,7 +2268,7 @@ "value": { "api_version": "2.0.0", "era_summary": { - "block_hash": "0744fcb72af43c5cc372039bc5a8bfee48808a9ce414acc0d6338a628c20eb42", + "block_hash": "1f8187a82bd4b28948add6f8c0ea15a8aac6160088dbc281499fdcf2f0d95a79", "era_id": 42, "stored_value": { "EraInfo": { @@ -2517,7 +2434,7 @@ { "name": "block_identifier", "value": { - "Hash": "0744fcb72af43c5cc372039bc5a8bfee48808a9ce414acc0d6338a628c20eb42" + "Hash": "1f8187a82bd4b28948add6f8c0ea15a8aac6160088dbc281499fdcf2f0d95a79" } } ], @@ -2526,7 +2443,7 @@ "value": { "api_version": "2.0.0", "era_summary": { - "block_hash": "0744fcb72af43c5cc372039bc5a8bfee48808a9ce414acc0d6338a628c20eb42", + "block_hash": "1f8187a82bd4b28948add6f8c0ea15a8aac6160088dbc281499fdcf2f0d95a79", "era_id": 42, "stored_value": { "EraInfo": { @@ -3281,25 +3198,15 @@ "type": "object", "required": [ "approvals", - "body", "hash", - "header", - "serialization_version" + "payload" ], "properties": { - "serialization_version": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - }, "hash": { "$ref": "#/components/schemas/TransactionV1Hash" }, - "header": { - "$ref": "#/components/schemas/TransactionV1Header" - }, - "body": { - "$ref": "#/components/schemas/TransactionV1Body" + "payload": { + "$ref": "#/components/schemas/TransactionV1Payload" }, "approvals": { "type": "array", @@ -3319,20 +3226,20 @@ } ] }, - "TransactionV1Header": { - "description": "The header portion of a TransactionV1.", + "TransactionV1Payload": { + "description": "A unit of work sent by a client to the network, which when executed can cause global state to be altered.", "type": "object", "required": [ - "body_hash", "chain_name", + "fields", "initiator_addr", "pricing_mode", "timestamp", "ttl" ], "properties": { - "chain_name": { - "type": "string" + "initiator_addr": { + "$ref": "#/components/schemas/InitiatorAddr" }, "timestamp": { "$ref": "#/components/schemas/Timestamp" @@ -3340,18 +3247,56 @@ "ttl": { "$ref": "#/components/schemas/TimeDiff" }, - "body_hash": { - "$ref": "#/components/schemas/Digest" + "chain_name": { + "type": "string" }, "pricing_mode": { "$ref": "#/components/schemas/PricingMode" }, - "initiator_addr": { - "$ref": "#/components/schemas/InitiatorAddr" + "fields": { + "type": "object", + "additionalProperties": { + "$ref": "#/components/schemas/Bytes" + } } }, "additionalProperties": false }, + "InitiatorAddr": { + "description": "The address of the initiator of a TransactionV1.", + "oneOf": [ + { + "description": "The public key of the initiator.", + "type": "object", + "required": [ + "PublicKey" + ], + "properties": { + "PublicKey": { + "$ref": "#/components/schemas/PublicKey" + } + }, + "additionalProperties": false + }, + { + "description": "The account hash derived from the public key of the initiator.", + "type": "object", + "required": [ + "AccountHash" + ], + "properties": { + "AccountHash": { + "$ref": "#/components/schemas/AccountHash" + } + }, + "additionalProperties": false + } + ] + }, + "AccountHash": { + "description": "Account hash as a formatted string.", + "type": "string" + }, "PricingMode": { "description": "Pricing mode of a Transaction.", "oneOf": [ @@ -3402,9 +3347,16 @@ "Fixed": { "type": "object", "required": [ + "additional_computation_factor", "gas_price_tolerance" ], "properties": { + "additional_computation_factor": { + "description": "User-specified additional computation factor (minimum 0). If \"0\" is provided, no additional logic is applied to the computation limit. Each value above \"0\" tells the node that it needs to treat the transaction as if it uses more gas than it's serialized size indicates. Each \"1\" will increase the \"wasm lane\" size bucket for this transaction by 1. So if the size of the transaction indicates bucket \"0\" and \"additional_computation_factor = 2\", the transaction will be treated as a \"2\".", + "type": "integer", + "format": "uint8", + "minimum": 0.0 + }, "gas_price_tolerance": { "description": "User-specified gas_price tolerance (minimum 1). This is interpreted to mean \"do not include this transaction in a block if the current gas price is greater than this number\"", "type": "integer", @@ -3446,409 +3398,6 @@ } ] }, - "InitiatorAddr": { - "description": "The address of the initiator of a TransactionV1.", - "oneOf": [ - { - "description": "The public key of the initiator.", - "type": "object", - "required": [ - "PublicKey" - ], - "properties": { - "PublicKey": { - "$ref": "#/components/schemas/PublicKey" - } - }, - "additionalProperties": false - }, - { - "description": "The account hash derived from the public key of the initiator.", - "type": "object", - "required": [ - "AccountHash" - ], - "properties": { - "AccountHash": { - "$ref": "#/components/schemas/AccountHash" - } - }, - "additionalProperties": false - } - ] - }, - "AccountHash": { - "description": "Account hash as a formatted string.", - "type": "string" - }, - "TransactionV1Body": { - "description": "Body of a `TransactionV1`.", - "type": "object", - "required": [ - "args", - "entry_point", - "scheduling", - "target", - "transaction_category" - ], - "properties": { - "args": { - "$ref": "#/components/schemas/RuntimeArgs" - }, - "target": { - "$ref": "#/components/schemas/TransactionTarget" - }, - "entry_point": { - "$ref": "#/components/schemas/TransactionEntryPoint" - }, - "transaction_category": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - }, - "scheduling": { - "$ref": "#/components/schemas/TransactionScheduling" - } - }, - "additionalProperties": false - }, - "TransactionTarget": { - "description": "Execution target of a Transaction.", - "oneOf": [ - { - "description": "The execution target is a native operation (e.g. a transfer).", - "type": "string", - "enum": [ - "Native" - ] - }, - { - "description": "The execution target is a stored entity or package.", - "type": "object", - "required": [ - "Stored" - ], - "properties": { - "Stored": { - "type": "object", - "required": [ - "id", - "runtime" - ], - "properties": { - "id": { - "description": "The identifier of the stored execution target.", - "allOf": [ - { - "$ref": "#/components/schemas/TransactionInvocationTarget" - } - ] - }, - "runtime": { - "description": "The execution runtime to use.", - "allOf": [ - { - "$ref": "#/components/schemas/TransactionRuntime" - } - ] - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "The execution target is the included module bytes, i.e. compiled Wasm.", - "type": "object", - "required": [ - "Session" - ], - "properties": { - "Session": { - "type": "object", - "required": [ - "module_bytes", - "runtime" - ], - "properties": { - "module_bytes": { - "description": "The compiled Wasm.", - "allOf": [ - { - "$ref": "#/components/schemas/Bytes" - } - ] - }, - "runtime": { - "description": "The execution runtime to use.", - "allOf": [ - { - "$ref": "#/components/schemas/TransactionRuntime" - } - ] - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "TransactionInvocationTarget": { - "description": "Identifier of a `Stored` transaction target.", - "oneOf": [ - { - "description": "Hex-encoded entity address identifying the invocable entity.", - "type": "object", - "required": [ - "ByHash" - ], - "properties": { - "ByHash": { - "type": "string" - } - }, - "additionalProperties": false - }, - { - "description": "The alias identifying the invocable entity.", - "type": "object", - "required": [ - "ByName" - ], - "properties": { - "ByName": { - "type": "string" - } - }, - "additionalProperties": false - }, - { - "description": "The address and optional version identifying the package.", - "type": "object", - "required": [ - "ByPackageHash" - ], - "properties": { - "ByPackageHash": { - "type": "object", - "required": [ - "addr" - ], - "properties": { - "addr": { - "description": "Hex-encoded address of the package.", - "type": "string" - }, - "version": { - "description": "The package version.\n\nIf `None`, the latest enabled version is implied.", - "type": [ - "integer", - "null" - ], - "format": "uint32", - "minimum": 0.0 - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "The alias and optional version identifying the package.", - "type": "object", - "required": [ - "ByPackageName" - ], - "properties": { - "ByPackageName": { - "type": "object", - "required": [ - "name" - ], - "properties": { - "name": { - "description": "The package name.", - "type": "string" - }, - "version": { - "description": "The package version.\n\nIf `None`, the latest enabled version is implied.", - "type": [ - "integer", - "null" - ], - "format": "uint32", - "minimum": 0.0 - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "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" - ] - } - ] - }, - "TransactionEntryPoint": { - "description": "Entry point of a Transaction.", - "oneOf": [ - { - "description": "The standard `call` entry point used in session code.", - "type": "string", - "enum": [ - "Call" - ] - }, - { - "description": "A non-native, arbitrary entry point.", - "type": "object", - "required": [ - "Custom" - ], - "properties": { - "Custom": { - "type": "string" - } - }, - "additionalProperties": false - }, - { - "description": "The `transfer` native entry point, used to transfer `Motes` from a source purse to a target purse.", - "type": "string", - "enum": [ - "Transfer" - ] - }, - { - "description": "The `add_bid` native entry point, used to create or top off a bid purse.", - "type": "string", - "enum": [ - "AddBid" - ] - }, - { - "description": "The `withdraw_bid` native entry point, used to decrease a stake.", - "type": "string", - "enum": [ - "WithdrawBid" - ] - }, - { - "description": "The `delegate` native entry point, used to add a new delegator or increase an existing delegator's stake.", - "type": "string", - "enum": [ - "Delegate" - ] - }, - { - "description": "The `undelegate` native entry point, used to reduce a delegator's stake or remove the delegator if the remaining stake is 0.", - "type": "string", - "enum": [ - "Undelegate" - ] - }, - { - "description": "The `redelegate` native entry point, used to reduce a delegator's stake or remove the delegator if the remaining stake is 0, and after the unbonding delay, automatically delegate to a new validator.", - "type": "string", - "enum": [ - "Redelegate" - ] - }, - { - "description": "The `activate_bid` native entry point, used to used to reactivate an inactive bid.", - "type": "string", - "enum": [ - "ActivateBid" - ] - }, - { - "description": "The `change_bid_public_key` native entry point, used to change a bid's public key.", - "type": "string", - "enum": [ - "ChangeBidPublicKey" - ] - }, - { - "description": "The `add_reservations` native entry point, used to add delegator to validator's reserve list", - "type": "string", - "enum": [ - "AddReservations" - ] - }, - { - "description": "The `cancel_reservations` native entry point, used to remove delegator from validator's reserve list", - "type": "string", - "enum": [ - "CancelReservations" - ] - } - ] - }, - "TransactionScheduling": { - "description": "Scheduling mode of a Transaction.", - "oneOf": [ - { - "description": "No special scheduling applied.", - "type": "string", - "enum": [ - "Standard" - ] - }, - { - "description": "Execution should be scheduled for the specified era.", - "type": "object", - "required": [ - "FutureEra" - ], - "properties": { - "FutureEra": { - "$ref": "#/components/schemas/EraId" - } - }, - "additionalProperties": false - }, - { - "description": "Execution should be scheduled for the specified timestamp or later.", - "type": "object", - "required": [ - "FutureTimestamp" - ], - "properties": { - "FutureTimestamp": { - "$ref": "#/components/schemas/Timestamp" - } - }, - "additionalProperties": false - } - ] - }, - "EraId": { - "description": "Era ID newtype.", - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, "TransactionHash": { "description": "A versioned wrapper for a transaction hash or deploy hash.", "oneOf": [ @@ -4901,6 +4450,12 @@ }, "additionalProperties": false }, + "EraId": { + "description": "Era ID newtype.", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, "U128": { "description": "Decimal representation of a 128-bit integer.", "type": "string" @@ -6479,6 +6034,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" diff --git a/resources/test/speculative_rpc_schema.json b/resources/test/speculative_rpc_schema.json index 35118280..23a55bd8 100644 --- a/resources/test/speculative_rpc_schema.json +++ b/resources/test/speculative_rpc_schema.json @@ -174,70 +174,31 @@ "name": "transaction", "value": { "Version1": { - "serialization_version": 1, - "hash": "df4f6e95afd24c3bdac68862cfd888fea65912f0f3e3de9c42b24cee79b7a581", - "header": { - "chain_name": "casper-example", + "hash": "ee6b9196dda4cd446d7ac2cfe8d3b76f3d66757f107ac578f878921df7024c26", + "payload": { + "initiator_addr": { + "PublicKey": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c" + }, "timestamp": "2020-11-17T00:39:24.072Z", "ttl": "1h", - "body_hash": "7bf1a4f736a9cbb2b692b74522d981213c3a5463d0095ded40d1454cf1b779e1", + "chain_name": "casper-example", "pricing_mode": { "Fixed": { + "additional_computation_factor": 0, "gas_price_tolerance": 5 } }, - "initiator_addr": { - "PublicKey": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c" + "fields": { + "0": "0400000006000000736f7572636522000000010a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a070d0c06000000746172676574210000001b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b000c06000000616d6f756e74060000000500ac23fc06080200000069640900000001e7030000000000000d05", + "1": "010000000000000000000100000000", + "2": "010000000000000000000100000002", + "3": "010000000000000000000100000000" } }, - "body": { - "args": [ - [ - "source", - { - "cl_type": { - "Option": "URef" - }, - "bytes": "010a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a07", - "parsed": "uref-0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a-007" - } - ], - [ - "target", - { - "cl_type": "URef", - "bytes": "1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b00", - "parsed": "uref-1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b-000" - } - ], - [ - "amount", - { - "cl_type": "U512", - "bytes": "0500ac23fc06", - "parsed": "30000000000" - } - ], - [ - "id", - { - "cl_type": { - "Option": "U64" - }, - "bytes": "01e703000000000000", - "parsed": 999 - } - ] - ], - "target": "Native", - "entry_point": "Transfer", - "transaction_category": 0, - "scheduling": "Standard" - }, "approvals": [ { "signer": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c", - "signature": "015b407723d54bdfd376d43776d9b92ea465d7ec2e0d41e28b5f646fc17400193bc4e075cab4e8943de09935e3aa96d0bbe456382c2274689b6847a35a94d07309" + "signature": "0167407d6fd18f67fe8f46407c2c5148a39f01905fe00040c477717e10d5fa3fefada76fe2f35e711a1d0a3e7b5bf322a6eddf5ae6227efdc730706860b6f4820a" } ] } @@ -3734,25 +3695,15 @@ "type": "object", "required": [ "approvals", - "body", "hash", - "header", - "serialization_version" + "payload" ], "properties": { - "serialization_version": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - }, "hash": { "$ref": "#/components/schemas/TransactionV1Hash" }, - "header": { - "$ref": "#/components/schemas/TransactionV1Header" - }, - "body": { - "$ref": "#/components/schemas/TransactionV1Body" + "payload": { + "$ref": "#/components/schemas/TransactionV1Payload" }, "approvals": { "type": "array", @@ -3764,20 +3715,20 @@ }, "additionalProperties": false }, - "TransactionV1Header": { - "description": "The header portion of a TransactionV1.", + "TransactionV1Payload": { + "description": "A unit of work sent by a client to the network, which when executed can cause global state to be altered.", "type": "object", "required": [ - "body_hash", "chain_name", + "fields", "initiator_addr", "pricing_mode", "timestamp", "ttl" ], "properties": { - "chain_name": { - "type": "string" + "initiator_addr": { + "$ref": "#/components/schemas/InitiatorAddr" }, "timestamp": { "$ref": "#/components/schemas/Timestamp" @@ -3785,14 +3736,17 @@ "ttl": { "$ref": "#/components/schemas/TimeDiff" }, - "body_hash": { - "$ref": "#/components/schemas/Digest" + "chain_name": { + "type": "string" }, "pricing_mode": { "$ref": "#/components/schemas/PricingMode" }, - "initiator_addr": { - "$ref": "#/components/schemas/InitiatorAddr" + "fields": { + "type": "object", + "additionalProperties": { + "$ref": "#/components/schemas/Bytes" + } } }, "additionalProperties": false @@ -3847,9 +3801,16 @@ "Fixed": { "type": "object", "required": [ + "additional_computation_factor", "gas_price_tolerance" ], "properties": { + "additional_computation_factor": { + "description": "User-specified additional computation factor (minimum 0). If \"0\" is provided, no additional logic is applied to the computation limit. Each value above \"0\" tells the node that it needs to treat the transaction as if it uses more gas than it's serialized size indicates. Each \"1\" will increase the \"wasm lane\" size bucket for this transaction by 1. So if the size of the transaction indicates bucket \"0\" and \"additional_computation_factor = 2\", the transaction will be treated as a \"2\".", + "type": "integer", + "format": "uint8", + "minimum": 0.0 + }, "gas_price_tolerance": { "description": "User-specified gas_price tolerance (minimum 1). This is interpreted to mean \"do not include this transaction in a block if the current gas price is greater than this number\"", "type": "integer", @@ -3890,349 +3851,6 @@ "additionalProperties": false } ] - }, - "TransactionV1Body": { - "description": "Body of a `TransactionV1`.", - "type": "object", - "required": [ - "args", - "entry_point", - "scheduling", - "target", - "transaction_category" - ], - "properties": { - "args": { - "$ref": "#/components/schemas/RuntimeArgs" - }, - "target": { - "$ref": "#/components/schemas/TransactionTarget" - }, - "entry_point": { - "$ref": "#/components/schemas/TransactionEntryPoint" - }, - "transaction_category": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - }, - "scheduling": { - "$ref": "#/components/schemas/TransactionScheduling" - } - }, - "additionalProperties": false - }, - "TransactionTarget": { - "description": "Execution target of a Transaction.", - "oneOf": [ - { - "description": "The execution target is a native operation (e.g. a transfer).", - "type": "string", - "enum": [ - "Native" - ] - }, - { - "description": "The execution target is a stored entity or package.", - "type": "object", - "required": [ - "Stored" - ], - "properties": { - "Stored": { - "type": "object", - "required": [ - "id", - "runtime" - ], - "properties": { - "id": { - "description": "The identifier of the stored execution target.", - "allOf": [ - { - "$ref": "#/components/schemas/TransactionInvocationTarget" - } - ] - }, - "runtime": { - "description": "The execution runtime to use.", - "allOf": [ - { - "$ref": "#/components/schemas/TransactionRuntime" - } - ] - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "The execution target is the included module bytes, i.e. compiled Wasm.", - "type": "object", - "required": [ - "Session" - ], - "properties": { - "Session": { - "type": "object", - "required": [ - "module_bytes", - "runtime" - ], - "properties": { - "module_bytes": { - "description": "The compiled Wasm.", - "allOf": [ - { - "$ref": "#/components/schemas/Bytes" - } - ] - }, - "runtime": { - "description": "The execution runtime to use.", - "allOf": [ - { - "$ref": "#/components/schemas/TransactionRuntime" - } - ] - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "TransactionInvocationTarget": { - "description": "Identifier of a `Stored` transaction target.", - "oneOf": [ - { - "description": "Hex-encoded entity address identifying the invocable entity.", - "type": "object", - "required": [ - "ByHash" - ], - "properties": { - "ByHash": { - "type": "string" - } - }, - "additionalProperties": false - }, - { - "description": "The alias identifying the invocable entity.", - "type": "object", - "required": [ - "ByName" - ], - "properties": { - "ByName": { - "type": "string" - } - }, - "additionalProperties": false - }, - { - "description": "The address and optional version identifying the package.", - "type": "object", - "required": [ - "ByPackageHash" - ], - "properties": { - "ByPackageHash": { - "type": "object", - "required": [ - "addr" - ], - "properties": { - "addr": { - "description": "Hex-encoded address of the package.", - "type": "string" - }, - "version": { - "description": "The package version.\n\nIf `None`, the latest enabled version is implied.", - "type": [ - "integer", - "null" - ], - "format": "uint32", - "minimum": 0.0 - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "description": "The alias and optional version identifying the package.", - "type": "object", - "required": [ - "ByPackageName" - ], - "properties": { - "ByPackageName": { - "type": "object", - "required": [ - "name" - ], - "properties": { - "name": { - "description": "The package name.", - "type": "string" - }, - "version": { - "description": "The package version.\n\nIf `None`, the latest enabled version is implied.", - "type": [ - "integer", - "null" - ], - "format": "uint32", - "minimum": 0.0 - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "TransactionEntryPoint": { - "description": "Entry point of a Transaction.", - "oneOf": [ - { - "description": "The standard `call` entry point used in session code.", - "type": "string", - "enum": [ - "Call" - ] - }, - { - "description": "A non-native, arbitrary entry point.", - "type": "object", - "required": [ - "Custom" - ], - "properties": { - "Custom": { - "type": "string" - } - }, - "additionalProperties": false - }, - { - "description": "The `transfer` native entry point, used to transfer `Motes` from a source purse to a target purse.", - "type": "string", - "enum": [ - "Transfer" - ] - }, - { - "description": "The `add_bid` native entry point, used to create or top off a bid purse.", - "type": "string", - "enum": [ - "AddBid" - ] - }, - { - "description": "The `withdraw_bid` native entry point, used to decrease a stake.", - "type": "string", - "enum": [ - "WithdrawBid" - ] - }, - { - "description": "The `delegate` native entry point, used to add a new delegator or increase an existing delegator's stake.", - "type": "string", - "enum": [ - "Delegate" - ] - }, - { - "description": "The `undelegate` native entry point, used to reduce a delegator's stake or remove the delegator if the remaining stake is 0.", - "type": "string", - "enum": [ - "Undelegate" - ] - }, - { - "description": "The `redelegate` native entry point, used to reduce a delegator's stake or remove the delegator if the remaining stake is 0, and after the unbonding delay, automatically delegate to a new validator.", - "type": "string", - "enum": [ - "Redelegate" - ] - }, - { - "description": "The `activate_bid` native entry point, used to used to reactivate an inactive bid.", - "type": "string", - "enum": [ - "ActivateBid" - ] - }, - { - "description": "The `change_bid_public_key` native entry point, used to change a bid's public key.", - "type": "string", - "enum": [ - "ChangeBidPublicKey" - ] - }, - { - "description": "The `add_reservations` native entry point, used to add delegator to validator's reserve list", - "type": "string", - "enum": [ - "AddReservations" - ] - }, - { - "description": "The `cancel_reservations` native entry point, used to remove delegator from validator's reserve list", - "type": "string", - "enum": [ - "CancelReservations" - ] - } - ] - }, - "TransactionScheduling": { - "description": "Scheduling mode of a Transaction.", - "oneOf": [ - { - "description": "No special scheduling applied.", - "type": "string", - "enum": [ - "Standard" - ] - }, - { - "description": "Execution should be scheduled for the specified era.", - "type": "object", - "required": [ - "FutureEra" - ], - "properties": { - "FutureEra": { - "$ref": "#/components/schemas/EraId" - } - }, - "additionalProperties": false - }, - { - "description": "Execution should be scheduled for the specified timestamp or later.", - "type": "object", - "required": [ - "FutureTimestamp" - ], - "properties": { - "FutureTimestamp": { - "$ref": "#/components/schemas/Timestamp" - } - }, - "additionalProperties": false - } - ] } } } diff --git a/rpc_sidecar/src/node_client.rs b/rpc_sidecar/src/node_client.rs index 395d4ef5..69384920 100644 --- a/rpc_sidecar/src/node_client.rs +++ b/rpc_sidecar/src/node_client.rs @@ -19,9 +19,10 @@ use casper_binary_port::{ BinaryMessageCodec, BinaryRequest, BinaryResponse, BinaryResponseAndRequest, ConsensusValidatorChanges, ContractInformation, DictionaryItemIdentifier, DictionaryQueryResult, EntityIdentifier, EraIdentifier, ErrorCode, GetRequest, - GetTrieFullResult, GlobalStateQueryResult, GlobalStateRequest, InformationRequest, KeyPrefix, - NodeStatus, PackageIdentifier, PayloadEntity, PurseIdentifier, RecordId, ResponseType, - RewardResponse, SpeculativeExecutionResult, TransactionWithExecutionInfo, ValueWithProof, + GetTrieFullResult, GlobalStateEntityQualifier, GlobalStateQueryResult, GlobalStateRequest, + InformationRequest, KeyPrefix, NodeStatus, PackageIdentifier, PayloadEntity, PurseIdentifier, + RecordId, ResponseType, RewardResponse, SpeculativeExecutionResult, + TransactionWithExecutionInfo, ValueWithProof, }; use casper_types::{ bytesrepr::{self, FromBytes, ToBytes}, @@ -73,11 +74,10 @@ pub trait NodeClient: Send + Sync { base_key: Key, path: Vec, ) -> Result, Error> { - let req = GlobalStateRequest::Item { + let req = GlobalStateRequest::new( state_identifier, - base_key, - path, - }; + GlobalStateEntityQualifier::Item { base_key, path }, + ); let resp = self .send_request(BinaryRequest::Get(GetRequest::State(Box::new(req)))) .await?; @@ -89,10 +89,10 @@ pub trait NodeClient: Send + Sync { state_identifier: Option, key_tag: KeyTag, ) -> Result, Error> { - let get = GlobalStateRequest::AllItems { + let get = GlobalStateRequest::new( state_identifier, - key_tag, - }; + GlobalStateEntityQualifier::AllItems { key_tag }, + ); let resp = self .send_request(BinaryRequest::Get(GetRequest::State(Box::new(get)))) .await?; @@ -104,10 +104,10 @@ pub trait NodeClient: Send + Sync { state_identifier: Option, key_prefix: KeyPrefix, ) -> Result, Error> { - let get = GlobalStateRequest::ItemsByPrefix { + let get = GlobalStateRequest::new( state_identifier, - key_prefix, - }; + GlobalStateEntityQualifier::ItemsByPrefix { key_prefix }, + ); let resp = self .send_request(BinaryRequest::Get(GetRequest::State(Box::new(get)))) .await?; @@ -119,10 +119,10 @@ pub trait NodeClient: Send + Sync { state_identifier: Option, purse_identifier: PurseIdentifier, ) -> Result { - let get = GlobalStateRequest::Balance { + let get = GlobalStateRequest::new( state_identifier, - purse_identifier, - }; + GlobalStateEntityQualifier::Balance { purse_identifier }, + ); let resp = self .send_request(BinaryRequest::Get(GetRequest::State(Box::new(get)))) .await?; @@ -130,9 +130,8 @@ pub trait NodeClient: Send + Sync { } async fn read_trie_bytes(&self, trie_key: Digest) -> Result>, Error> { - let req = GlobalStateRequest::Trie { trie_key }; let resp = self - .send_request(BinaryRequest::Get(GetRequest::State(Box::new(req)))) + .send_request(BinaryRequest::Get(GetRequest::Trie { trie_key })) .await?; let res = parse_response::(&resp.into())?.ok_or(Error::EmptyEnvelope)?; Ok(res.into_inner().map(>::from)) @@ -143,10 +142,10 @@ pub trait NodeClient: Send + Sync { state_identifier: Option, identifier: DictionaryItemIdentifier, ) -> Result, Error> { - let get = GlobalStateRequest::DictionaryItem { + let get = GlobalStateRequest::new( state_identifier, - identifier, - }; + GlobalStateEntityQualifier::DictionaryItem { identifier }, + ); let resp = self .send_request(BinaryRequest::Get(GetRequest::State(Box::new(get)))) .await?; @@ -684,6 +683,8 @@ pub enum Error { UnexpectedNodeError { message: String, code: u16 }, #[error("binary protocol version mismatch")] BinaryProtocolVersionMismatch, + #[error("request was throttled by the node")] + RequestThrottled, } impl Error { @@ -767,6 +768,7 @@ impl Error { | ErrorCode::InvalidTransactionUnspecified | ErrorCode::InvalidTransactionOrDeployUnspecified), ) => Self::InvalidTransaction(InvalidTransactionOrDeploy::from(err)), + Ok(ErrorCode::RequestThrottled) => Self::RequestThrottled, Ok(err @ (ErrorCode::WasmPreprocessing | ErrorCode::InvalidItemVariant)) => { Self::SpecExecutionFailed(err.to_string()) } diff --git a/rpc_sidecar/src/rpcs/chain.rs b/rpc_sidecar/src/rpcs/chain.rs index 0a7ee4bc..7aec0a03 100644 --- a/rpc_sidecar/src/rpcs/chain.rs +++ b/rpc_sidecar/src/rpcs/chain.rs @@ -405,7 +405,7 @@ mod tests { use crate::{ClientError, SUPPORTED_PROTOCOL_VERSION}; use casper_binary_port::{ BinaryRequest, BinaryResponse, BinaryResponseAndRequest, GetRequest, - GlobalStateQueryResult, GlobalStateRequest, InformationRequestTag, RecordId, + GlobalStateEntityQualifier, GlobalStateQueryResult, InformationRequestTag, RecordId, }; use casper_types::{ system::auction::EraInfo, testing::TestRng, Block, BlockSignaturesV1, BlockSignaturesV2, @@ -765,8 +765,8 @@ mod tests { } BinaryRequest::Get(GetRequest::State(req)) if matches!( - &*req, - GlobalStateRequest::Item { + req.clone().destructure().1, + GlobalStateEntityQualifier::Item { base_key: Key::EraSummary, .. } diff --git a/rpc_sidecar/src/rpcs/state.rs b/rpc_sidecar/src/rpcs/state.rs index 5f439ef4..6e690514 100644 --- a/rpc_sidecar/src/rpcs/state.rs +++ b/rpc_sidecar/src/rpcs/state.rs @@ -1325,8 +1325,8 @@ mod tests { use casper_binary_port::{ AccountInformation, AddressableEntityInformation, BalanceResponse, BinaryRequest, BinaryResponse, BinaryResponseAndRequest, ContractInformation, DictionaryQueryResult, - ErrorCode as BinaryErrorCode, GetRequest, GlobalStateQueryResult, GlobalStateRequest, - InformationRequestTag, KeyPrefix, ValueWithProof, + ErrorCode as BinaryErrorCode, GetRequest, GlobalStateEntityQualifier, + GlobalStateQueryResult, InformationRequestTag, KeyPrefix, ValueWithProof, }; use casper_types::{ addressable_entity::{MessageTopics, NamedKeyValue, NamedKeys}, @@ -1462,8 +1462,8 @@ mod tests { } BinaryRequest::Get(GetRequest::State(req)) if matches!( - &*req, - GlobalStateRequest::AllItems { + req.clone().destructure().1, + GlobalStateEntityQualifier::AllItems { key_tag: KeyTag::Bid, .. } @@ -1483,8 +1483,8 @@ mod tests { } BinaryRequest::Get(GetRequest::State(req)) if matches!( - &*req, - GlobalStateRequest::AllItems { + req.clone().destructure().1, + GlobalStateEntityQualifier::AllItems { key_tag: KeyTag::BidAddr, .. } @@ -1504,8 +1504,8 @@ mod tests { } BinaryRequest::Get(GetRequest::State(req)) if matches!( - &*req, - GlobalStateRequest::Item { + req.clone().destructure().1, + GlobalStateEntityQualifier::Item { base_key: Key::SystemEntityRegistry, .. } @@ -1526,8 +1526,8 @@ mod tests { } BinaryRequest::Get(GetRequest::State(req)) if matches!( - &*req, - GlobalStateRequest::Item { + req.clone().destructure().1, + GlobalStateEntityQualifier::Item { base_key: Key::AddressableEntity(_), .. } @@ -1612,8 +1612,8 @@ mod tests { } BinaryRequest::Get(GetRequest::State(req)) if matches!( - &*req, - GlobalStateRequest::AllItems { + req.clone().destructure().1, + GlobalStateEntityQualifier::AllItems { key_tag: KeyTag::Bid, .. } @@ -1633,8 +1633,8 @@ mod tests { } BinaryRequest::Get(GetRequest::State(req)) if matches!( - &*req, - GlobalStateRequest::AllItems { + req.clone().destructure().1, + GlobalStateEntityQualifier::AllItems { key_tag: KeyTag::BidAddr, .. } @@ -1654,13 +1654,15 @@ mod tests { } BinaryRequest::Get(GetRequest::State(req)) if matches!( - &*req, - GlobalStateRequest::Item { - base_key: Key::SystemEntityRegistry, + req.clone().destructure(), + ( // system entity registry is not present in pre-1.5 state - state_identifier: None, - .. - } + None, + GlobalStateEntityQualifier::Item { + base_key: Key::SystemEntityRegistry, + .. + } + ) ) => { let system_contracts = @@ -1678,8 +1680,8 @@ mod tests { } BinaryRequest::Get(GetRequest::State(req)) if matches!( - &*req, - GlobalStateRequest::Item { + req.clone().destructure().1, + GlobalStateEntityQualifier::Item { // we should return nothing for entity hash in pre-1.5 state base_key: Key::AddressableEntity(_), .. @@ -1694,8 +1696,8 @@ mod tests { } BinaryRequest::Get(GetRequest::State(req)) if matches!( - &*req, - GlobalStateRequest::Item { + req.clone().destructure().1, + GlobalStateEntityQualifier::Item { // we should query by contract hash in pre-1.5 state base_key: Key::Hash(_), .. @@ -1835,8 +1837,8 @@ mod tests { } BinaryRequest::Get(GetRequest::State(req)) if matches!( - &*req, - GlobalStateRequest::ItemsByPrefix { + req.clone().destructure().1, + GlobalStateEntityQualifier::ItemsByPrefix { key_prefix: KeyPrefix::NamedKeysByEntity(_), .. } @@ -1861,8 +1863,8 @@ mod tests { } BinaryRequest::Get(GetRequest::State(req)) if matches!( - &*req, - GlobalStateRequest::ItemsByPrefix { + req.clone().destructure().1, + GlobalStateEntityQualifier::ItemsByPrefix { key_prefix: KeyPrefix::EntryPointsV1ByEntity(_), .. } @@ -1883,8 +1885,8 @@ mod tests { } BinaryRequest::Get(GetRequest::State(req)) if matches!( - &*req, - GlobalStateRequest::ItemsByPrefix { + req.clone().destructure().1, + GlobalStateEntityQualifier::ItemsByPrefix { key_prefix: KeyPrefix::EntryPointsV2ByEntity(_), .. } @@ -2327,8 +2329,8 @@ mod tests { } BinaryRequest::Get(GetRequest::State(req)) if matches!( - &*req, - GlobalStateRequest::Item { + req.clone().destructure().1, + GlobalStateEntityQualifier::Item { base_key: Key::Account(_), .. } @@ -2403,8 +2405,8 @@ mod tests { } BinaryRequest::Get(GetRequest::State(req)) if matches!( - &*req, - GlobalStateRequest::Item { + req.clone().destructure().1, + GlobalStateEntityQualifier::Item { base_key: Key::Account(_), .. } @@ -2602,7 +2604,10 @@ mod tests { ) -> Result { match req { BinaryRequest::Get(GetRequest::State(req)) - if matches!(&*req, GlobalStateRequest::DictionaryItem { .. }) => + if matches!( + req.clone().destructure().1, + GlobalStateEntityQualifier::DictionaryItem { .. } + ) => { Ok(BinaryResponseAndRequest::new( BinaryResponse::from_value( @@ -2628,7 +2633,10 @@ mod tests { ) -> Result { match req { BinaryRequest::Get(GetRequest::State(req)) - if matches!(&*req, GlobalStateRequest::Item { .. }) => + if matches!( + req.clone().destructure().1, + GlobalStateEntityQualifier::Item { .. } + ) => { Ok(BinaryResponseAndRequest::new( BinaryResponse::from_value(self.0.clone(), SUPPORTED_PROTOCOL_VERSION), @@ -2667,7 +2675,10 @@ mod tests { )) } BinaryRequest::Get(GetRequest::State(req)) - if matches!(&*req, GlobalStateRequest::Item { .. }) => + if matches!( + req.clone().destructure().1, + GlobalStateEntityQualifier::Item { .. } + ) => { Ok(BinaryResponseAndRequest::new( BinaryResponse::from_value(self.result.clone(), SUPPORTED_PROTOCOL_VERSION), @@ -2706,8 +2717,8 @@ mod tests { } BinaryRequest::Get(GetRequest::State(req)) if matches!( - &*req, - GlobalStateRequest::Item { + req.clone().destructure().1, + GlobalStateEntityQualifier::Item { base_key: Key::Account(_), .. } @@ -2740,7 +2751,10 @@ mod tests { ) -> Result { match req { BinaryRequest::Get(GetRequest::State(req)) - if matches!(&*req, GlobalStateRequest::Balance { .. }) => + if matches!( + req.clone().destructure().1, + GlobalStateEntityQualifier::Balance { .. } + ) => { Ok(BinaryResponseAndRequest::new( BinaryResponse::from_value(self.0.clone(), SUPPORTED_PROTOCOL_VERSION), @@ -2763,7 +2777,10 @@ mod tests { ) -> Result { match req { BinaryRequest::Get(GetRequest::State(req)) - if matches!(&*req, GlobalStateRequest::Balance { .. }) => + if matches!( + req.clone().destructure().1, + GlobalStateEntityQualifier::Balance { .. } + ) => { Ok(BinaryResponseAndRequest::new( BinaryResponse::new_error( diff --git a/types/src/legacy_sse_data/fixtures.rs b/types/src/legacy_sse_data/fixtures.rs index c444c7b6..fbf04bbc 100644 --- a/types/src/legacy_sse_data/fixtures.rs +++ b/types/src/legacy_sse_data/fixtures.rs @@ -366,75 +366,31 @@ const RAW_TRANSACTION_ACCEPTED: &str = r#" { "TransactionAccepted": { "Version1": { - "serialization_version": 1, - "hash": "2084a40f58874fb2997e029e61ec55e3d5a6cd5f6de77a1d42dcaf21aeddc760", - "header": { - "chain_name":"⸻⋉◬⸗ⶨ⼄≙⡫⨁ⶃℍ⊨⇏ⴲⲋ⪝⣬ⴂ⨨⪯⿉⺙⚚⻰⒯ⶖ⟽⬪❴⴯╽♥⅏⏵❲⃽ⶁ⾠⸗◩⋑Ⅹ♼⺓⊻⼠Ⓩ∇Ⅺ⸔◘⠝◓⚾◯⦁★⢹␄⍆⨿⵮⭭⮛⸹⃻⹶⎶⟆⛎⤑₇⩐╨⋸⠸₈⥡ⷔ⹪⤛⭺⵫Ⲗ⃁⪏⫵⚎⁘⦳☉␛Ⲹ⥝⇡Ⰰ⫂⁎⍆⼸", - "timestamp": "2020-08-07T01:30:25.521Z", - "ttl": "5h 6m 46s 219ms", - "body_hash": "11ddedb85acbe04217e4f322663e7a3b90630321cdff7d7a8f0ce97fd76ead9a", - "pricing_mode": { - "Fixed": { - "gas_price_tolerance": 5 - } - }, - "initiator_addr": { - "PublicKey": "01b0c1bc1910f3e2e5fa8329d642b34e72e34183e0a2b239021906df8d7d968fcd" - } - }, - "body": { - "args": [ - [ - "source", - { - "cl_type": { - "Option": "URef" - }, - "bytes": "01d4ce239a968d7ac214964f714f6aa267612d1da1ec9c65dfc40a99d0e1a673ce02", - "parsed": "uref-d4ce239a968d7ac214964f714f6aa267612d1da1ec9c65dfc40a99d0e1a673ce-002" - } - ], - [ - "target", - { - "cl_type": "PublicKey", - "bytes": "015a977c34eeff036613837814822a1a44986f2a7057c17436d01d200132614c58", - "parsed": "015a977c34eeff036613837814822a1a44986f2a7057c17436d01d200132614c58" - } - ], - [ - "amount", - { - "cl_type": "U512", - "bytes": "08b30d8646748b0f87", - "parsed": "9732150651286588851" - } - ], - [ - "id", - { - "cl_type": { - "Option": "U64" - }, - "bytes": "01dfd56bb1e2ac2494", - "parsed": 10674847106414138847 - } - ] - ], - "target": "Native", - "entry_point": "Transfer", - "scheduling": { - "FutureTimestamp": "2020-08-07T01:32:59.428Z" - }, - "transaction_category": 0 - }, - "approvals": [ - { - "signer": "01b0c1bc1910f3e2e5fa8329d642b34e72e34183e0a2b239021906df8d7d968fcd", - "signature": "01fb52d40bd36c813ca69b982f6b7f4bac79314187e51e69128fa4d87fbb2cfe8e803b2eedaa6f39566ca3a4dc59ac418824aa2e7fc05611910162cf9f6a164902" - } - ] - } + "hash": "2084a40f58874fb2997e029e61ec55e3d5a6cd5f6de77a1d42dcaf21aeddc760", + "payload": { + "initiator_addr": { + "PublicKey": "020394489ced801f72d5ae25d66dfa4e5f7d045fa3f16085d780be901054d8386295" + }, + "timestamp": "2020-08-07T01:27:53.316Z", + "ttl": "16h 57m 31s 19ms", + "chain_name": "⸻⋉◬⸗ⶨ⼄≙⡫⨁ⶃℍ⊨⇏ⴲⲋ⪝⣬ⴂ⨨⪯⿉⺙⚚⻰⒯ⶖ⟽⬪❴⴯╽♥⅏⏵❲⃽ⶁ⾠⸗◩⋑Ⅹ♼⺓⊻⼠Ⓩ∇Ⅺ⸔◘⠝◓⚾◯⦁★⢹␄⍆⨿⵮⭭⮛⸹⃻⹶⎶⟆⛎⤑₇⩐╨⋸⠸₈⥡ⷔ⹪⤛⭺⵫Ⲗ⃁⪏⫵⚎⁘⦳☉␛Ⲹ⥝⇡Ⰰ⫂⁎⍆⼸", + "pricing_mode": { + "Fixed": { "additional_computation_factor": 0, "gas_price_tolerance": 5 } + }, + "fields": { + "0": "010000001c000000f1a894a7f2bfa889f18687bff399bbb8f3b0bd80f09697aff0989ca63b00000037000000093785a57f89410a5f4d46ac25426cd9807bccd0a32dad671f08119214999e6929fc8c6662d81af9d69b7750baee8f04a93432cf1e706a0e03", + "1": "010000000000000000000100000000", + "2": "010000000000000000000100000004", + "3": "010000000000000000000100000000" + } + }, + "approvals": [ + { + "signer": "020394489ced801f72d5ae25d66dfa4e5f7d045fa3f16085d780be901054d8386295", + "signature": "02a679a7db9f6123672309812706b2e2316c66fc16ac6ff6745539f1708264dfc33eb72883f142c90c1ab183191a83a474394203aaf6b21dcaf7b559137ccc604b" + } + ] +} } } "#; @@ -771,10 +727,10 @@ const RAW_BLOCK_ADDED_V2: &str = r#"{ }, "body": { "transactions": { - "0": [{"Deploy": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e80"}, {"Deploy": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e81"}, {"Version1": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e91"}], - "1": [{"Deploy": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e80"}, {"Deploy": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e90"}, {"Version1": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e82"}], - "2": [{"Deploy": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e83"}, {"Deploy": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e84"}, {"Version1": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e85"}], - "3": [{"Deploy": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e89"}, {"Deploy": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e90"}, {"Version1": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e88"}] + "0": [{"Deploy": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e80"}, {"Deploy": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e81"}, {"Version1": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e90"}], + "1": [{"Deploy": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e82"}, {"Deploy": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e83"}, {"Version1": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e91"}], + "2": [{"Deploy": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e84"}, {"Deploy": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e85"}, {"Version1": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e92"}], + "3": [{"Deploy": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e86"}, {"Deploy": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e87"}, {"Version1": "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e93"}] }, "rewarded_signatures": [[240],[0],[0]] } @@ -843,8 +799,12 @@ const RAW_LEGACY_BLOCK_ADDED_FROM_V2: &str = r#"{ "body": { "proposer": "01d3eec0445635f136ae560b43e9d8f656a6ba925f01293eaf2610b39ebe0fc28d", "deploy_hashes": [ - "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e89", - "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e90" + "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e82", + "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e83", + "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e84", + "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e85", + "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e86", + "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e87" ], "transfer_hashes": [ "58aca0009fc41bd045d303db9e9f07416ff1fd8c76ecd98545eedf86f9459e80", diff --git a/types/src/legacy_sse_data/translate_deploy_hashes.rs b/types/src/legacy_sse_data/translate_deploy_hashes.rs index 0c558d43..dafd1877 100644 --- a/types/src/legacy_sse_data/translate_deploy_hashes.rs +++ b/types/src/legacy_sse_data/translate_deploy_hashes.rs @@ -1,4 +1,4 @@ -use casper_types::{BlockBodyV2, DeployHash, TransactionHash}; +use casper_types::{BlockBodyV2, DeployHash, TransactionHash, MINT_LANE_ID}; use mockall::automock; #[automock] @@ -13,14 +13,19 @@ pub struct StandardDeployHashesTranslator; pub struct TransferDeployHashesTranslator; impl DeployHashTranslator for StandardDeployHashesTranslator { - fn translate(&self, block_body_v2: &casper_types::BlockBodyV2) -> Vec { + fn translate(&self, block_body_v2: &BlockBodyV2) -> Vec { block_body_v2 - .small() - .chain(block_body_v2.medium()) - .chain(block_body_v2.large()) - .filter_map(|el| match el { - TransactionHash::Deploy(deploy_hash) => Some(deploy_hash), - TransactionHash::V1(_) => None, + .transactions() + .iter() + .filter(|(lane_id, _)| **lane_id != MINT_LANE_ID) + .flat_map(|(_, hashes)| { + hashes + .iter() + .filter_map(|hash| match hash { + TransactionHash::Deploy(deploy_hash) => Some(*deploy_hash), + TransactionHash::V1(_) => None, + }) + .collect::>() }) .collect() } diff --git a/types/src/sse_data.rs b/types/src/sse_data.rs index a4111039..a1dcc795 100644 --- a/types/src/sse_data.rs +++ b/types/src/sse_data.rs @@ -50,7 +50,7 @@ pub(crate) fn to_error(msg: String) -> SseDataDeserializeError { /// * `json_raw`: string slice which should contain raw json data. pub fn deserialize(json_raw: &str) -> Result { serde_json::from_str::(json_raw).map_err(|err| { - let error_message = format!("Serde Error: {}", err); + let error_message = format!("Error when deserializing SSE event from node: {}", err); to_error(error_message) }) }