mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-10 07:08:05 -05:00
daod: implement Encodable for Box<T> and create isolated error case in demo.rs
This commit is contained in:
@@ -6,6 +6,7 @@ use pasta_curves::{
|
||||
|
||||
use darkfi::{
|
||||
crypto::{coin::Coin, keypair::PublicKey, types::DrkCircuitField},
|
||||
util::serial::{Encodable, SerialDecodable, SerialEncodable},
|
||||
Error as DarkFiError,
|
||||
};
|
||||
|
||||
@@ -56,6 +57,7 @@ impl From<DarkFiError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, SerialEncodable, SerialDecodable)]
|
||||
pub struct CallData {
|
||||
pub proposal: pallas::Base,
|
||||
pub coin_0: pallas::Base,
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use std::any::{Any, TypeId};
|
||||
|
||||
use darkfi::crypto::{keypair::PublicKey, types::DrkCircuitField};
|
||||
use darkfi::{
|
||||
crypto::{keypair::PublicKey, types::DrkCircuitField},
|
||||
util::serial::{Encodable, SerialDecodable, SerialEncodable},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
dao_contract::{DaoBulla, State},
|
||||
@@ -43,6 +46,7 @@ pub enum Error {}
|
||||
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
#[derive(Clone, SerialEncodable, SerialDecodable)]
|
||||
pub struct CallData {
|
||||
pub dao_bulla: DaoBulla,
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ impl From<DarkFiError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, SerialEncodable, SerialDecodable)]
|
||||
pub struct CallData {
|
||||
pub header: Header,
|
||||
pub inputs: Vec<Input>,
|
||||
|
||||
@@ -5,9 +5,12 @@ use pasta_curves::{
|
||||
};
|
||||
use std::{any::Any, collections::HashMap, hash::Hasher};
|
||||
|
||||
use darkfi::crypto::{constants::MERKLE_DEPTH, merkle_node::MerkleNode, nullifier::Nullifier};
|
||||
use darkfi::{
|
||||
crypto::{constants::MERKLE_DEPTH, merkle_node::MerkleNode, nullifier::Nullifier},
|
||||
util::serial::{Encodable, SerialDecodable, SerialEncodable},
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, SerialEncodable, SerialDecodable)]
|
||||
pub struct DaoBulla(pub pallas::Base);
|
||||
|
||||
type MerkleTree = BridgeTree<MerkleNode, MERKLE_DEPTH>;
|
||||
|
||||
@@ -49,6 +49,7 @@ impl From<DarkFiError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, SerialEncodable, SerialDecodable)]
|
||||
pub struct CallData {
|
||||
pub header: Header,
|
||||
pub inputs: Vec<Input>,
|
||||
|
||||
@@ -166,6 +166,7 @@ fn sign(signature_secrets: Vec<SecretKey>) -> Vec<Signature> {
|
||||
type ContractId = String;
|
||||
type FuncId = String;
|
||||
|
||||
//#[derive(Clone, SerialEncodable)]
|
||||
pub struct FuncCall {
|
||||
pub contract_id: ContractId,
|
||||
pub func_id: FuncId,
|
||||
@@ -173,6 +174,17 @@ pub struct FuncCall {
|
||||
pub proofs: Vec<Proof>,
|
||||
}
|
||||
|
||||
pub trait TestTrait: Encodable {
|
||||
fn foo(&self);
|
||||
}
|
||||
|
||||
#[derive(Clone, SerialEncodable)]
|
||||
pub struct TestStruct {
|
||||
// Bang!
|
||||
// This usage of Encodable fails. Note: Encodable is implemented for Box<T>.
|
||||
//pub test: Box<dyn TestTrait>,
|
||||
}
|
||||
|
||||
pub trait CallDataBase {
|
||||
// Public values for verifying the proofs
|
||||
// Needed so we can convert internal types so they can be used in Proof::verify()
|
||||
|
||||
@@ -30,6 +30,7 @@ impl From<DarkFiError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, SerialEncodable, SerialDecodable)]
|
||||
pub struct CallData {
|
||||
pub public_value: pallas::Base,
|
||||
pub signature_public: PublicKey,
|
||||
|
||||
@@ -581,6 +581,15 @@ impl Decodable for Box<[u8]> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Encodable> Encodable for Box<T> {
|
||||
fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
|
||||
let mut len = 0;
|
||||
let t: &T = &**self;
|
||||
len += t.encode(&mut s)?;
|
||||
Ok(len)
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for blake3::Hash {
|
||||
fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
|
||||
s.write_slice(self.as_bytes())?;
|
||||
|
||||
Reference in New Issue
Block a user