Replies: 2 comments 1 reply
-
This design achieves all the objectives. I wonder if it would be possible to avoid storing a |
Beta Was this translation helpful? Give feedback.
-
@AlianBenabdallah Thanks for the feedback! I think I tried something like this and can't remember exactly what stopped me. iirc it got weird because of wrapping the trait object with a In any cause, I think |
Beta Was this translation helpful? Give feedback.
-
Ocular Transaction API Design Proposal
Overview
This proposal outlines an API for transaction construction, signing, and broadcasting that is more flexible than having a method per message type, more easily extended for custom modules, and, in my opinion, is very readable.
Goals
Non-goals
Design
Each core Cosmos SDK module’s set of transaction
Msg
s will map to an enum representation, where each variant corresponds to a particularMsg
. Each variant will take in an anonymous struct whose fields correspond to theMsg
parameters. This approach makes it very easy to tell exactly what msg is being constructed and what parameter each argument represents. An example of what the Bank module implementation might look like (without MultiSend):Each of these enums will implement a
ModuleMsg
trait responsible for providing a common way to serialize a msg to aprost::Any
. There will also be a traitIntoTx
which will blanket implement aninto_tx()
method on allModuleMsg
which converts them into anUnsignedTx
.This trait makes this tx model easily extensible because all that needs to be done to use it with a non-SDK module is create an enum with variants that represent each msg, and implement
ModuleMsg
for it. The implementation is pretty straight forward and will look very similar for most msgs.The
UnsignedTx
type acts like a builder for the final transaction. It contains a vec of msgs and a method for adding new ones, sensible defaults for all metadata/tx configuration, and setters for each. Finally, it has a method.sign()
used to build the final Tx object and sign it with the provided account. Signing converts theUnsignedTx
to aSignedTx
, a wrapper for the raw transaction bytes that provides a broadcast method.Example Usage
Future work
The outlined traits and their implementations are simple enough that it may be possible to create a macro
impl_msgs!()
which generates an enum and the ModuleMsg implementation automatically given a proto or generated proto definitions.Tony has suggested part or all of this model may be a good fit for the
cosmrs
crate.Beta Was this translation helpful? Give feedback.
All reactions