use crate::common::{
crypto::signature::{signature_context_with_chain_separation, Signed},
quantity::Quantity,
};
pub const SIGNATURE_CONTEXT: &[u8] = b"oasis-core/consensus: tx";
fn signature_context(chain_context: &String) -> Vec<u8> {
let context = SIGNATURE_CONTEXT.to_vec();
signature_context_with_chain_separation(context, chain_context)
}
#[derive(Debug, cbor::Encode, cbor::Decode)]
#[cbor(no_default)]
pub struct Transaction {
pub nonce: u64,
pub fee: Option<Fee>,
pub method: MethodName,
pub body: cbor::Value,
}
pub type SignedTransaction = Signed;
impl SignedTransaction {
pub fn verify(&self, chain_context: &String) -> bool {
let context = signature_context(chain_context);
self.signature.verify(&context, &self.blob)
}
}
#[derive(Debug, Default, cbor::Encode, cbor::Decode)]
pub struct Fee {
pub amount: Quantity,
pub gas: Gas,
}
pub type Gas = u64;
pub type MethodName = String;
#[derive(Debug, Default, cbor::Encode, cbor::Decode)]
pub struct Proof {
pub height: u64,
pub raw_proof: Vec<u8>,
}
#[derive(Debug, Default, cbor::Encode, cbor::Decode)]
pub struct SignedTransactionWithProof {
pub signed_tx: SignedTransaction,
pub proof: Proof,
}