[−][src]Struct exonum_rust_runtime::Broadcaster
Transaction broadcaster.
Transaction broadcast allows a service to create transactions in the after_commit
handler or the HTTP API handlers and broadcast them to the connected Exonum nodes.
The transactions are addressed to the executing service instance and are signed
by the service keypair of the node.
Broadcasting functionality is primarily useful for services that receive information from outside the blockchain and need to translate it to transactions. As an example, a time oracle service may broadcast local node time and build the blockchain-wide time by processing corresponding transactions.
Examples
Using Broadcaster
in service logic:
use exonum::runtime::{ExecutionContext, ExecutionError}; use exonum_rust_runtime::{AfterCommitContext, Service}; #[exonum_interface] trait MyInterface<Ctx> { type Output; #[interface_method(id = 0)] fn publish_string(&self, ctx: Ctx, value: String) -> Self::Output; } #[derive(Debug, ServiceDispatcher, ServiceFactory)] #[service_dispatcher(implements("MyInterface"))] struct MyService; impl MyInterface<ExecutionContext<'_>> for MyService { // implementation skipped... } impl Service for MyService { fn after_commit(&self, ctx: AfterCommitContext<'_>) { if let Some(broadcaster) = ctx.broadcaster() { // Broadcast a `do_something` transaction with // the specified payload. We swallow an error in this case // (in a more thorough setup, it could be logged). broadcaster.blocking().publish_string((), "!".to_owned()).ok(); } } }
Methods
impl Broadcaster
[src]
pub fn blocking(self) -> BlockingBroadcaster
[src]
Returns a synchronous broadcaster that blocks the current thread to broadcast transaction.
Trait Implementations
impl Clone for Broadcaster
[src]
fn clone(&self) -> Broadcaster
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for Broadcaster
[src]
impl GenericCall<()> for Broadcaster
[src]
Signs and asynchronous broadcasts a transaction to the other nodes in the network.
The transaction is signed by the service keypair of the node. The same input transaction
will lead to the identical transaction being broadcast. If this is undesired, add a nonce
field to the input transaction (e.g., a u64
) and change it between the calls.
Return value
Returns the hash of the created transaction, or an error if the transaction cannot be broadcast. An error means that the node is being shut down.
Auto Trait Implementations
impl !RefUnwindSafe for Broadcaster
impl Send for Broadcaster
impl Sync for Broadcaster
impl Unpin for Broadcaster
impl !UnwindSafe for Broadcaster
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,