Skip to content

Commit

Permalink
Save failed submsg result in reply
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Aug 28, 2023
1 parent 6f6c914 commit eca866c
Show file tree
Hide file tree
Showing 6 changed files with 441 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2097,6 +2097,22 @@
}
]
},
"Attribute": {
"description": "An key value pair that is used in the context of event attributes in logs",
"type": "object",
"required": [
"key",
"value"
],
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
}
}
},
"BankMsg": {
"description": "The message types of the bank module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto",
"oneOf": [
Expand Down Expand Up @@ -2404,6 +2420,27 @@
}
]
},
"Event": {
"description": "A full [*Cosmos SDK* event].\n\nThis version uses string attributes (similar to [*Cosmos SDK* StringEvent]), which then get magically converted to bytes for Tendermint somewhere between the Rust-Go interface, JSON deserialization and the `NewEvent` call in Cosmos SDK.\n\n[*Cosmos SDK* event]: https://docs.cosmos.network/main/core/events.html [*Cosmos SDK* StringEvent]: https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/base/abci/v1beta1/abci.proto#L56-L70",
"type": "object",
"required": [
"attributes",
"type"
],
"properties": {
"attributes": {
"description": "The attributes to be included in the event.\n\nYou can learn more about these from [*Cosmos SDK* docs].\n\n[*Cosmos SDK* docs]: https://docs.cosmos.network/main/core/events.html",
"type": "array",
"items": {
"$ref": "#/definitions/Attribute"
}
},
"type": {
"description": "The event type. This is renamed to \"ty\" because \"type\" is reserved in Rust. This sucks, we know.",
"type": "string"
}
}
},
"GovMsg": {
"description": "This message type allows the contract interact with the [x/gov] module in order to cast votes.\n\n[x/gov]: https://github.com/cosmos/cosmos-sdk/tree/v0.45.12/x/gov\n\n## Examples\n\nCast a simple vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); use cosmwasm_std::{GovMsg, VoteOption};\n\n#[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result<Response, StdError> { // ... Ok(Response::new().add_message(GovMsg::Vote { proposal_id: 4, vote: VoteOption::Yes, })) } ```\n\nCast a weighted vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); # #[cfg(feature = \"cosmwasm_1_2\")] use cosmwasm_std::{Decimal, GovMsg, VoteOption, WeightedVoteOption};\n\n# #[cfg(feature = \"cosmwasm_1_2\")] #[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result<Response, StdError> { // ... Ok(Response::new().add_message(GovMsg::VoteWeighted { proposal_id: 4, options: vec![ WeightedVoteOption { option: VoteOption::Yes, weight: Decimal::percent(65), }, WeightedVoteOption { option: VoteOption::Abstain, weight: Decimal::percent(35), }, ], })) } ```",
"oneOf": [
Expand Down Expand Up @@ -3240,10 +3277,23 @@
},
{
"description": "The proposal's execution failed.",
"type": "string",
"enum": [
"type": "object",
"required": [
"execution_failed"
]
],
"properties": {
"execution_failed": {
"anyOf": [
{
"$ref": "#/definitions/SubMsgResult"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
}
]
},
Expand Down Expand Up @@ -3427,6 +3477,61 @@
}
]
},
"SubMsgResponse": {
"description": "The information we get back from a successful sub message execution, with full Cosmos SDK events.",
"type": "object",
"required": [
"events"
],
"properties": {
"data": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
},
"events": {
"type": "array",
"items": {
"$ref": "#/definitions/Event"
}
}
}
},
"SubMsgResult": {
"description": "This is the result type that is returned from a sub message execution.\n\nWe use a custom type here instead of Rust's Result because we want to be able to define the serialization, which is a public interface. Every language that compiles to Wasm and runs in the ComsWasm VM needs to create the same JSON representation.\n\nUntil version 1.0.0-beta5, `ContractResult<SubMsgResponse>` was used instead of this type. Once serialized, the two types are the same. However, in the Rust type system we want different types for clarity and documenation reasons.\n\n# Examples\n\nSuccess:\n\n``` # use cosmwasm_std::{to_vec, Binary, Event, SubMsgResponse, SubMsgResult}; let response = SubMsgResponse { data: Some(Binary::from_base64(\"MTIzCg==\").unwrap()), events: vec![Event::new(\"wasm\").add_attribute(\"fo\", \"ba\")], }; let result: SubMsgResult = SubMsgResult::Ok(response); assert_eq!(to_vec(&result).unwrap(), br#\"{\"ok\":{\"events\":[{\"type\":\"wasm\",\"attributes\":[{\"key\":\"fo\",\"value\":\"ba\"}]}],\"data\":\"MTIzCg==\"}}\"#); ```\n\nFailure:\n\n``` # use cosmwasm_std::{to_vec, SubMsgResult, Response}; let error_msg = String::from(\"Something went wrong\"); let result = SubMsgResult::Err(error_msg); assert_eq!(to_vec(&result).unwrap(), br#\"{\"error\":\"Something went wrong\"}\"#); ```",
"oneOf": [
{
"type": "object",
"required": [
"ok"
],
"properties": {
"ok": {
"$ref": "#/definitions/SubMsgResponse"
}
},
"additionalProperties": false
},
{
"description": "An error type that every custom error created by contract developers can be converted to. This could potientially have more structure, but String is the easiest.",
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "string"
}
},
"additionalProperties": false
}
]
},
"SudoContractProposal": {
"description": "SudoContractProposal defines the struct for sudo execution proposal.",
"type": "object",
Expand Down Expand Up @@ -3906,6 +4011,22 @@
}
]
},
"Attribute": {
"description": "An key value pair that is used in the context of event attributes in logs",
"type": "object",
"required": [
"key",
"value"
],
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
}
}
},
"BankMsg": {
"description": "The message types of the bank module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto",
"oneOf": [
Expand Down Expand Up @@ -4213,6 +4334,27 @@
}
]
},
"Event": {
"description": "A full [*Cosmos SDK* event].\n\nThis version uses string attributes (similar to [*Cosmos SDK* StringEvent]), which then get magically converted to bytes for Tendermint somewhere between the Rust-Go interface, JSON deserialization and the `NewEvent` call in Cosmos SDK.\n\n[*Cosmos SDK* event]: https://docs.cosmos.network/main/core/events.html [*Cosmos SDK* StringEvent]: https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/base/abci/v1beta1/abci.proto#L56-L70",
"type": "object",
"required": [
"attributes",
"type"
],
"properties": {
"attributes": {
"description": "The attributes to be included in the event.\n\nYou can learn more about these from [*Cosmos SDK* docs].\n\n[*Cosmos SDK* docs]: https://docs.cosmos.network/main/core/events.html",
"type": "array",
"items": {
"$ref": "#/definitions/Attribute"
}
},
"type": {
"description": "The event type. This is renamed to \"ty\" because \"type\" is reserved in Rust. This sucks, we know.",
"type": "string"
}
}
},
"GovMsg": {
"description": "This message type allows the contract interact with the [x/gov] module in order to cast votes.\n\n[x/gov]: https://github.com/cosmos/cosmos-sdk/tree/v0.45.12/x/gov\n\n## Examples\n\nCast a simple vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); use cosmwasm_std::{GovMsg, VoteOption};\n\n#[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result<Response, StdError> { // ... Ok(Response::new().add_message(GovMsg::Vote { proposal_id: 4, vote: VoteOption::Yes, })) } ```\n\nCast a weighted vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); # #[cfg(feature = \"cosmwasm_1_2\")] use cosmwasm_std::{Decimal, GovMsg, VoteOption, WeightedVoteOption};\n\n# #[cfg(feature = \"cosmwasm_1_2\")] #[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result<Response, StdError> { // ... Ok(Response::new().add_message(GovMsg::VoteWeighted { proposal_id: 4, options: vec![ WeightedVoteOption { option: VoteOption::Yes, weight: Decimal::percent(65), }, WeightedVoteOption { option: VoteOption::Abstain, weight: Decimal::percent(35), }, ], })) } ```",
"oneOf": [
Expand Down Expand Up @@ -5049,10 +5191,23 @@
},
{
"description": "The proposal's execution failed.",
"type": "string",
"enum": [
"type": "object",
"required": [
"execution_failed"
]
],
"properties": {
"execution_failed": {
"anyOf": [
{
"$ref": "#/definitions/SubMsgResult"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
}
]
},
Expand Down Expand Up @@ -5210,6 +5365,61 @@
}
]
},
"SubMsgResponse": {
"description": "The information we get back from a successful sub message execution, with full Cosmos SDK events.",
"type": "object",
"required": [
"events"
],
"properties": {
"data": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
},
"events": {
"type": "array",
"items": {
"$ref": "#/definitions/Event"
}
}
}
},
"SubMsgResult": {
"description": "This is the result type that is returned from a sub message execution.\n\nWe use a custom type here instead of Rust's Result because we want to be able to define the serialization, which is a public interface. Every language that compiles to Wasm and runs in the ComsWasm VM needs to create the same JSON representation.\n\nUntil version 1.0.0-beta5, `ContractResult<SubMsgResponse>` was used instead of this type. Once serialized, the two types are the same. However, in the Rust type system we want different types for clarity and documenation reasons.\n\n# Examples\n\nSuccess:\n\n``` # use cosmwasm_std::{to_vec, Binary, Event, SubMsgResponse, SubMsgResult}; let response = SubMsgResponse { data: Some(Binary::from_base64(\"MTIzCg==\").unwrap()), events: vec![Event::new(\"wasm\").add_attribute(\"fo\", \"ba\")], }; let result: SubMsgResult = SubMsgResult::Ok(response); assert_eq!(to_vec(&result).unwrap(), br#\"{\"ok\":{\"events\":[{\"type\":\"wasm\",\"attributes\":[{\"key\":\"fo\",\"value\":\"ba\"}]}],\"data\":\"MTIzCg==\"}}\"#); ```\n\nFailure:\n\n``` # use cosmwasm_std::{to_vec, SubMsgResult, Response}; let error_msg = String::from(\"Something went wrong\"); let result = SubMsgResult::Err(error_msg); assert_eq!(to_vec(&result).unwrap(), br#\"{\"error\":\"Something went wrong\"}\"#); ```",
"oneOf": [
{
"type": "object",
"required": [
"ok"
],
"properties": {
"ok": {
"$ref": "#/definitions/SubMsgResponse"
}
},
"additionalProperties": false
},
{
"description": "An error type that every custom error created by contract developers can be converted to. This could potientially have more structure, but String is the easiest.",
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "string"
}
},
"additionalProperties": false
}
]
},
"SudoContractProposal": {
"description": "SudoContractProposal defines the struct for sudo execution proposal.",
"type": "object",
Expand Down
Loading

0 comments on commit eca866c

Please sign in to comment.