Struct flow_sdk::entities::Event[][src]

pub struct Event {
    pub ty: String,
    pub transaction_id: Box<[u8]>,
    pub transaction_index: u32,
    pub event_index: u32,
    pub payload: Box<[u8]>,
}
Expand description

An event is emitted as the result of a transaction execution.

Events are either user-defined events originating from a Cadence smart contract, or built-in Flow system events.

Fields

ty: String

Fully-qualified unique type identifier for the event

transaction_id: Box<[u8]>

ID of the transaction the event was emitted from

transaction_index: u32

Zero-based index of the transaction within the block

event_index: u32

Zero-based index of the event within the transaction

payload: Box<[u8]>

Event fields encoded as JSON-Cadence values

Implementations

Parses the payload of this event as a cadence JSON value.

Parses the payload of this event.

Examples found in repository
examples/events.rs (line 33)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let latest_block_height = client.latest_block_header(Seal::Sealed).await?.height;
    let start_height = latest_block_height - 20;

    println!(
        "Searching for accounts created within the last 20 blocks ({}-{})...",
        start_height, latest_block_height
    );

    for events in client
        .events_for_height_range("flow.AccountCreated", start_height, latest_block_height)
        .await?
        .results
        .iter()
    {
        if events.events.is_empty() {
            continue;
        }
        println!(
            "\nBlock #{} ({}):",
            events.block_height,
            hex::encode(&events.block_id)
        );
        for event in events.events.iter() {
            let val = event.parse_payload()?;

            println!("  - {:#?}", val);
        }
    }

    Ok(())
}
More examples
examples/transactions.rs (line 65)
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    let mut buf = String::new();

    // Let's make a transaction!

    // First, generate a keypair for us to use.
    let secp = Secp256k1::signing_only();

    // `EntropyRng` is a secure random number generator.
    let mut rng = secp256k1::rand::rngs::EntropyRng::new();
    let secret_key = SecretKey::new(&mut rng);
    let public_key = PublicKey::from_secret_key(&secp, &secret_key);

    // Print the public key as a hexadecimal.
    println!("This is your public key:");
    let public_key_bytes = public_key.serialize_uncompressed();
    // There is a leading 0x04 which we don't need to emit
    // https://bitcoin.stackexchange.com/a/3043
    for ch in &public_key_bytes[1..] {
        print!("{:02x}", *ch);
    }
    println!();
    println!("Go to https://flow-faucet.vercel.app/, select secp256k1 and sha3 and create your testnet account.");
    println!("Paste the address you get and press ENTER to continue");

    stdin.read_line(&mut buf)?;

    let addr = buf.trim();

    let address: AddressOwned = addr.parse()?;
    let net = TonicHyperFlowClient::testnet().await?;

    let mut account = Account::<_, _>::new(net, &address.data, secret_key).await?;

    let create_account = CreateAccountTransaction {
        public_keys: &[public_key],
    };

    let create_account_header = create_account.to_header::<_, tiny_keccak::Sha3>(account.signer());
    let res = account
        .send_transaction_header(&create_account_header)
        .await?;

    println!(
        "Just made {} to create another account :p",
        hex::encode(&res.id)
    );

    let response = res.finalize(account.client()).await?;

    match response {
        Some(res) => {
            for ev in res.events.iter() {
                if ev.ty == "flow.AccountCreated" {
                    let payload = ev.parse_payload()?;

                    let addr = payload
                        .fields
                        .into_iter()
                        .find(|field| field.name == "address")
                        .map(|field| field.value)
                        .unwrap();
                    if let ValueOwned::Address(addr) = addr {
                        println!("Created account's address is: {}", addr);
                    }
                }
            }
        }
        None => {
            panic!("The transaction did not get sealed... Perhaps the network is malfunctioning?")
        }
    }

    Ok(())
}

Trait Implementations

Formats the value using the given formatter. Read more

If this is a message, call merge() on all fields, if this is repeated, extend this with the elements of other. for all other types simply overwrite this with other, which is the default. Read more

How big the tag message gets. This is an unsigned varint. Read more

Decodes a field with the given tag. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Wrap the input message T in a tonic::Request

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more