Skip to content
Permalink
Browse files

Merge pull request #631 from input-output-hk/rename-message-to-fragment

Rename Message to Fragment
  • Loading branch information...
vincenthz committed Jul 11, 2019
2 parents 814963d + dc27eb9 commit a140d15369993e20dc2d5835af638ea6b0b50a66

Large diffs are not rendered by default.

Submodule chain-deps updated 39 files
+20 −69 .circleci/config.yml
+201 −0 LICENSE-APACHE
+1 −1 LICENSE-MIT
+5 −1 chain-addr/src/lib.rs
+1 −0 chain-core/Cargo.toml
+244 −0 chain-crypto/src/digest.rs
+1 −22 chain-crypto/src/hash.rs
+2 −1 chain-crypto/src/lib.rs
+1 −9 chain-crypto/src/testing.rs
+1 −0 chain-impl-mockchain/Cargo.toml
+0 −0 chain-impl-mockchain/doc/multisig.md
+5 −5 chain-impl-mockchain/src/block/builder.rs
+9 −9 chain-impl-mockchain/src/block/mod.rs
+0 −0 chain-impl-mockchain/src/fragment/config.rs
+162 −0 chain-impl-mockchain/src/fragment/mod.rs
+9 −10 chain-impl-mockchain/src/fragment/raw.rs
+19 −19 chain-impl-mockchain/src/ledger/ledger.rs
+5 −4 chain-impl-mockchain/src/ledger/tests/discrimination_tests.rs
+2 −2 chain-impl-mockchain/src/ledger/tests/initial_funds_tests.rs
+100 −124 chain-impl-mockchain/src/ledger/tests/ledger_tests.rs
+1 −1 chain-impl-mockchain/src/lib.rs
+0 −156 chain-impl-mockchain/src/message/mod.rs
+2 −2 chain-impl-mockchain/src/multiverse.rs
+1 −1 chain-impl-mockchain/src/setting.rs
+31 −4 chain-impl-mockchain/src/testing/address.rs
+1 −1 chain-impl-mockchain/src/testing/arbitrary/address.rs
+39 −3 chain-impl-mockchain/src/testing/arbitrary/mod.rs
+7 −5 chain-impl-mockchain/src/testing/arbitrary/output.rs
+183 −0 chain-impl-mockchain/src/testing/arbitrary/transaction.rs
+11 −13 chain-impl-mockchain/src/testing/ledger.rs
+67 −23 chain-impl-mockchain/src/testing/tx_builder.rs
+12 −0 chain-impl-mockchain/src/transaction/transfer.rs
+2 −2 chain-impl-mockchain/src/update.rs
+1 −0 chain-storage-sqlite/Cargo.toml
+1 −0 chain-storage/Cargo.toml
+1 −0 chain-time/Cargo.toml
+1 −0 imhamt/Cargo.toml
+1 −0 network-core/Cargo.toml
+1 −0 network-grpc/Cargo.toml
@@ -1,5 +1,5 @@
use chain_core::property::Deserialize as _;
use chain_impl_mockchain::message::Message as MockMessage;
use chain_impl_mockchain::fragment::Fragment as MockFragment;
use hex;
use jcli_app::debug::Error;
use jcli_app::utils::{error::CustomErrorFiller, io};
@@ -23,11 +23,12 @@ impl Message {
let mut hex_str = String::new();
BufReader::new(reader).read_line(&mut hex_str)?;
let bytes = hex::decode(hex_str.trim())?;
let message =
MockMessage::deserialize(bytes.as_ref()).map_err(|source| Error::MessageMalformed {
let message = MockFragment::deserialize(bytes.as_ref()).map_err(|source| {
Error::MessageMalformed {
source,
filler: CustomErrorFiller,
})?;
}
})?;
println!("{:#?}", message);
Ok(())
}
@@ -2,7 +2,7 @@ use chain_addr::Address;
use chain_impl_mockchain::{
self as chain,
fee::FeeAlgorithm,
message::Message,
fragment::Fragment,
transaction::{NoExtra, Output, Transaction, TransactionId},
txbuilder,
value::Value,
@@ -164,7 +164,7 @@ impl Staging {

let balance = if let Some(certificate) = self.extra.clone() {
let tx = self.transaction_with_extra(&certificate);
let mut builder = txbuilder::TransactionBuilder::from(tx);
let builder = txbuilder::TransactionBuilder::from(tx);

let (balance, tx) = builder.finalize(fee_algorithm, output_policy)?;

@@ -173,7 +173,7 @@ impl Staging {
balance
} else {
let tx = self.transaction();
let mut builder = txbuilder::TransactionBuilder::from(tx);
let builder = txbuilder::TransactionBuilder::from(tx);
let (balance, tx) = builder.finalize(fee_algorithm, output_policy)?;

self.update_tx(tx);
@@ -201,7 +201,7 @@ impl Staging {
Ok(self.kind = StagingKind::Sealed)
}

pub fn message(&self) -> Result<Message, Error> {
pub fn message(&self) -> Result<Fragment, Error> {
if self.kind != StagingKind::Sealed {
Err(Error::TxKindToGetMessageInvalid { kind: self.kind })?
}
@@ -216,8 +216,8 @@ impl Staging {
})?;

match result {
chain::txbuilder::GeneratedTransaction::Type1(auth) => Ok(Message::Transaction(auth)),
chain::txbuilder::GeneratedTransaction::Type2(auth) => Ok(Message::Certificate(auth)),
chain::txbuilder::GeneratedTransaction::Type1(auth) => Ok(Fragment::Transaction(auth)),
chain::txbuilder::GeneratedTransaction::Type2(auth) => Ok(Fragment::Certificate(auth)),
}
}

@@ -10,7 +10,7 @@ use chain_impl_mockchain::{
block::ConsensusVersion,
config::{Block0Date, ConfigParam},
fee::LinearFee,
message::config::ConfigParams,
fragment::config::ConfigParams,
};
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;
@@ -1,8 +1,8 @@
use crate::interfaces::{Address, Certificate, OldAddress, Value};
use chain_impl_mockchain::{
certificate,
fragment::Fragment,
legacy::UtxoDeclaration,
message::Message,
transaction::{AuthenticatedTransaction, NoExtra, Output, Transaction},
};
use serde::{Deserialize, Serialize};
@@ -36,14 +36,14 @@ custom_error! {pub Error
}

pub fn try_initials_vec_from_messages<'a>(
messages: impl Iterator<Item = &'a Message>,
messages: impl Iterator<Item = &'a Fragment>,
) -> Result<Vec<Initial>, Error> {
let mut inits = Vec::new();
for message in messages {
match message {
Message::Transaction(tx) => try_extend_inits_with_tx(&mut inits, tx)?,
Message::Certificate(tx) => extend_inits_with_cert(&mut inits, tx),
Message::OldUtxoDeclaration(utxo) => extend_inits_with_legacy_utxo(&mut inits, utxo),
Fragment::Transaction(tx) => try_extend_inits_with_tx(&mut inits, tx)?,
Fragment::Certificate(tx) => extend_inits_with_cert(&mut inits, tx),
Fragment::OldUtxoDeclaration(utxo) => extend_inits_with_legacy_utxo(&mut inits, utxo),
_ => return Err(Error::Block0MessageUnexpected),
}
}
@@ -81,8 +81,8 @@ fn extend_inits_with_legacy_utxo(initials: &mut Vec<Initial>, utxo_decl: &UtxoDe
initials.push(Initial::LegacyFund(inits_iter.collect()))
}

impl<'a> From<&'a Initial> for Message {
fn from(initial: &'a Initial) -> Message {
impl<'a> From<&'a Initial> for Fragment {
fn from(initial: &'a Initial) -> Fragment {
match initial {
Initial::Fund(utxo) => pack_utxo_in_message(&utxo),
Initial::Cert(cert) => cert.into(),
@@ -91,7 +91,7 @@ impl<'a> From<&'a Initial> for Message {
}
}

fn pack_utxo_in_message(v: &[InitialUTxO]) -> Message {
fn pack_utxo_in_message(v: &[InitialUTxO]) -> Fragment {
let outputs = v
.iter()
.map(|utxo| Output {
@@ -100,7 +100,7 @@ fn pack_utxo_in_message(v: &[InitialUTxO]) -> Message {
})
.collect();

Message::Transaction(AuthenticatedTransaction {
Fragment::Transaction(AuthenticatedTransaction {
transaction: Transaction {
inputs: vec![],
outputs: outputs,
@@ -110,17 +110,17 @@ fn pack_utxo_in_message(v: &[InitialUTxO]) -> Message {
})
}

fn pack_legacy_utxo_in_message(v: &[LegacyUTxO]) -> Message {
fn pack_legacy_utxo_in_message(v: &[LegacyUTxO]) -> Fragment {
let addrs = v
.iter()
.map(|utxo| (utxo.address.clone().into(), utxo.value.into()))
.collect();
Message::OldUtxoDeclaration(UtxoDeclaration { addrs: addrs })
Fragment::OldUtxoDeclaration(UtxoDeclaration { addrs: addrs })
}

impl<'a> From<&'a Certificate> for Message {
fn from(utxo: &'a Certificate) -> Message {
Message::Certificate(AuthenticatedTransaction {
impl<'a> From<&'a Certificate> for Fragment {
fn from(utxo: &'a Certificate) -> Fragment {
Fragment::Certificate(AuthenticatedTransaction {
transaction: Transaction {
inputs: vec![],
outputs: vec![],
@@ -20,7 +20,7 @@ pub use self::slots_duration::SlotDuration;
use chain_core::property::HasMessages as _;
use chain_impl_mockchain::{
block::{Block, BlockBuilder},
message::Message,
fragment::Fragment,
};
use serde::{Deserialize, Serialize};
use std::convert::TryFrom as _;
@@ -57,7 +57,7 @@ impl Block0Configuration {
let mut messages = block.messages();

let blockchain_configuration = match messages.next() {
Some(Message::Initial(initial)) => BlockchainConfiguration::try_from(initial.clone())?,
Some(Fragment::Initial(initial)) => BlockchainConfiguration::try_from(initial.clone())?,
_ => return Err(Block0ConfigurationError::FirstBlock0MessageNotInit),
};

@@ -69,10 +69,10 @@ impl Block0Configuration {

pub fn to_block(&self) -> Block {
let mut builder = BlockBuilder::new();
builder.message(Message::Initial(
builder.message(Fragment::Initial(
self.blockchain_configuration.clone().into(),
));
builder.messages(self.initial.iter().map(Message::from));
builder.messages(self.initial.iter().map(Fragment::from));
builder.make_genesis_block()
}
}
@@ -7,9 +7,9 @@ pub use chain_impl_mockchain::{
HeaderContentEvalContext, HeaderHash, SlotId,
},
config::{self, Block0Date, ConfigParam},
fragment::{ConfigParams, Fragment, FragmentId},
leadership::{BftLeader, GenesisLeader, Leader, LeaderOutput, Leadership},
ledger::{Ledger, LedgerParameters, LedgerStaticParameters},
message::{ConfigParams, Message, MessageId},
multiverse::Multiverse,
value::{Value, ValueError},
};
@@ -65,7 +65,7 @@ impl Block0DataSource for Block {

fn initial(block: &Block) -> Result<&ConfigParams, Block0Malformed> {
for message in block.messages() {
if let Message::Initial(init) = message {
if let Fragment::Initial(init) = message {
return Ok(init);
}
}
@@ -9,7 +9,4 @@ pub use self::logs::Logs;
pub use self::pool::Pool;
pub use self::process::Process;

use crate::blockcfg::{Message, MessageId};

pub type FragmentId = MessageId;
pub type Fragment = Message;
pub use crate::blockcfg::{Fragment, FragmentId};
@@ -1,4 +1,4 @@
use crate::blockcfg::{Block, Epoch, Header, HeaderHash, Message, MessageId};
use crate::blockcfg::{Block, Epoch, Fragment, FragmentId, Header, HeaderHash};
use crate::network::p2p::topology::NodeId;
use futures::prelude::*;
use futures::sync::{mpsc, oneshot};
@@ -243,9 +243,9 @@ where
/// ...
#[derive(Debug)]
pub enum TransactionMsg {
ProposeTransaction(Vec<MessageId>, ReplyHandle<Vec<bool>>),
SendTransaction(FragmentOrigin, Vec<Message>),
GetTransactions(Vec<MessageId>, ReplyStreamHandle<Message>),
ProposeTransaction(Vec<FragmentId>, ReplyHandle<Vec<bool>>),
SendTransaction(FragmentOrigin, Vec<Fragment>),
GetTransactions(Vec<FragmentId>, ReplyStreamHandle<Fragment>),
}

/// Client messages, mainly requests from connected peers to our node.
@@ -319,7 +319,7 @@ pub enum BlockMsg {
#[derive(Clone, Debug)]
pub enum PropagateMsg {
Block(Header),
Message(Message),
Message(Fragment),
}

/// Messages to the network task.
@@ -1,7 +1,7 @@
mod peer_map;

use super::topology;
use crate::blockcfg::{Block, Header, HeaderHash, Message};
use crate::blockcfg::{Block, Fragment, Header, HeaderHash};
use futures::prelude::*;
use futures::{stream, sync::mpsc};
use network_core::error as core_error;
@@ -143,7 +143,7 @@ pub struct PeerComms {
block_announcements: CommHandle<Header>,
block_solicitations: CommHandle<Vec<HeaderHash>>,
chain_pulls: CommHandle<ChainPullRequest<HeaderHash>>,
messages: CommHandle<Message>,
messages: CommHandle<Fragment>,
gossip: CommHandle<Gossip<topology::Node>>,
}

@@ -159,7 +159,7 @@ impl PeerComms {
self.block_announcements.try_send(header)
}

pub fn try_send_message(&mut self, message: Message) -> Result<(), PropagateError<Message>> {
pub fn try_send_message(&mut self, message: Fragment) -> Result<(), PropagateError<Fragment>> {
self.messages.try_send(message)
}

@@ -182,7 +182,7 @@ impl PeerComms {
self.chain_pulls.subscribe()
}

pub fn subscribe_to_messages(&mut self) -> Subscription<Message> {
pub fn subscribe_to_messages(&mut self) -> Subscription<Fragment> {
self.messages.subscribe()
}

@@ -231,7 +231,7 @@ impl Peers {
.select(missing_events)
}

pub fn subscribe_to_messages(&self, id: topology::NodeId) -> Subscription<Message> {
pub fn subscribe_to_messages(&self, id: topology::NodeId) -> Subscription<Fragment> {
let mut map = self.mutex.lock().unwrap();
let handles = map.ensure_peer_comms(id);
handles.messages.subscribe()
@@ -299,7 +299,7 @@ impl Peers {
pub fn propagate_message(
&self,
nodes: Vec<topology::Node>,
message: Message,
message: Fragment,
) -> Result<(), Vec<topology::Node>> {
self.propagate_with(nodes, |handles| handles.try_send_message(message.clone()))
}
@@ -4,7 +4,7 @@ use super::{
p2p::topology,
subscription, Channels, GlobalStateR,
};
use crate::blockcfg::{Block, BlockDate, Header, HeaderHash, Message, MessageId};
use crate::blockcfg::{Block, BlockDate, Fragment, FragmentId, Header, HeaderHash};
use crate::intercom::{stream_reply, unary_reply, BlockMsg, ClientMsg, ReplyFuture, ReplyStream};
use futures::future::{self, FutureResult};
use futures::prelude::*;
@@ -185,11 +185,11 @@ impl BlockService for NodeService {
}

impl ContentService for NodeService {
type Message = Message;
type MessageId = MessageId;
type Message = Fragment;
type MessageId = FragmentId;
type GetMessagesStream = ReplyStream<Self::Message, core_error::Error>;
type GetMessagesFuture = ReplyFuture<Self::GetMessagesStream, core_error::Error>;
type MessageSubscription = Subscription<Message>;
type MessageSubscription = Subscription<Fragment>;
type MessageSubscriptionFuture = FutureResult<Self::MessageSubscription, core_error::Error>;

fn get_messages(&mut self, _ids: &[Self::MessageId]) -> Self::GetMessagesFuture {
@@ -8,8 +8,8 @@ use chain_crypto::{Blake2b256, PublicKey};
use chain_impl_mockchain::account::{AccountAlg, Identifier};
use chain_impl_mockchain::key::Hash;

use chain_impl_mockchain::fragment::Fragment;
use chain_impl_mockchain::leadership::LeadershipConsensus;
use chain_impl_mockchain::message::Message;
use chain_storage::store;

use bytes::{Bytes, IntoBuf};
@@ -65,7 +65,7 @@ pub fn post_message(
{
let sender = request.state().transaction_task.clone();
request.body().map(move |message| -> Result<_, ActixError> {
let msg = Message::deserialize(message.into_buf()).map_err(|e| {
let msg = Fragment::deserialize(message.into_buf()).map_err(|e| {
println!("{}", e);
ErrorBadRequest(e)
})?;

0 comments on commit a140d15

Please sign in to comment.
You can’t perform that action at this time.