This repository has been archived by the owner on Jun 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cosmos-stdtx: add Amino types for encoding StdTx
The schema-based encoder is only for `Msg`. This adds a `StdTx` type using `prost-amino-derive` to programatically declare it.
- Loading branch information
1 parent
22c11d7
commit 1dc247f
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//! StdTx Amino types | ||
use crate::type_name::TypeName; | ||
use prost_amino::{encode_length_delimiter, Message}; | ||
use prost_amino_derive::Message; | ||
|
||
/// StdTx Amino type | ||
#[derive(Clone, Message)] | ||
pub struct StdTx { | ||
/// Messages in transction | ||
#[prost_amino(bytes, repeated, tag = "1")] | ||
pub msg: Vec<Vec<u8>>, | ||
|
||
/// Feeds to be paid | ||
#[prost_amino(message)] | ||
pub fee: Option<StdFee>, | ||
|
||
/// Signatures | ||
#[prost_amino(message, repeated)] | ||
pub signatures: Vec<StdSignature>, | ||
|
||
/// Memo field | ||
#[prost_amino(string)] | ||
pub memo: String, | ||
} | ||
|
||
impl StdTx { | ||
/// Encode this [`StdTx`] in Amino encoding identifying it with the given | ||
/// type name (e.g. `cosmos-sdk/StdTx`) | ||
pub fn to_amino_bytes(&self, type_name: &TypeName) -> Vec<u8> { | ||
let mut amino_tx = type_name.amino_prefix(); | ||
self.encode(&mut amino_tx).expect("LEB128 encoding error"); | ||
|
||
let mut amino_encoded = vec![]; | ||
encode_length_delimiter(amino_tx.len(), &mut amino_encoded).expect("LEB128 encoding error"); | ||
amino_encoded.append(&mut amino_tx); | ||
amino_encoded | ||
} | ||
} | ||
|
||
/// StdFee amino type | ||
#[derive(Clone, Message)] | ||
pub struct StdFee { | ||
/// Fee to be paid | ||
#[prost_amino(message, repeated, tag = "1")] | ||
pub amount: Vec<Coin>, | ||
|
||
/// Gas requested for transaction | ||
#[prost_amino(uint64)] | ||
pub gas: u64, | ||
} | ||
|
||
/// Coin amino type | ||
#[derive(Clone, Message)] | ||
pub struct Coin { | ||
/// Denomination of coin | ||
#[prost_amino(string, tag = "1")] | ||
pub denom: String, | ||
|
||
/// Amount of the given denomination | ||
#[prost_amino(string)] | ||
pub amount: String, | ||
} | ||
|
||
/// StdSignature amino type | ||
#[derive(Clone, Message)] | ||
pub struct StdSignature { | ||
/// Public key which can verify this signature | ||
#[prost_amino(bytes, tag = "1", amino_name = "tendermint/PubKeySecp256k1")] | ||
pub pub_key: Vec<u8>, | ||
|
||
/// Serialized signature | ||
#[prost_amino(bytes)] | ||
pub signature: Vec<u8>, | ||
} |