Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bindings/go/examples/package_events/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ func main() {
fmt.Println("Type: ", event.Type)
fmt.Println("Sender: ", event.Sender.ToHex())
fmt.Println("Module: ", event.Module)
fmt.Println("JSON: ", event.Json)
}
}
15 changes: 15 additions & 0 deletions bindings/go/iota_sdk_ffi/iota_sdk_ffi.go
Original file line number Diff line number Diff line change
Expand Up @@ -24206,6 +24206,12 @@ type Event struct {
Type string
// BCS serialized bytes of the event
Contents []byte
// UTC timestamp in milliseconds since epoch (1/1/1970)
Timestamp string
// Structured contents of a Move value
Data string
// Representation of a Move value in JSON
Json string
}

func (r *Event) Destroy() {
Expand All @@ -24214,6 +24220,9 @@ func (r *Event) Destroy() {
FfiDestroyerAddress{}.Destroy(r.Sender);
FfiDestroyerString{}.Destroy(r.Type);
FfiDestroyerBytes{}.Destroy(r.Contents);
FfiDestroyerString{}.Destroy(r.Timestamp);
FfiDestroyerString{}.Destroy(r.Data);
FfiDestroyerString{}.Destroy(r.Json);
}

type FfiConverterEvent struct {}
Expand All @@ -24231,6 +24240,9 @@ func (c FfiConverterEvent) Read(reader io.Reader) Event {
FfiConverterAddressINSTANCE.Read(reader),
FfiConverterStringINSTANCE.Read(reader),
FfiConverterBytesINSTANCE.Read(reader),
FfiConverterStringINSTANCE.Read(reader),
FfiConverterStringINSTANCE.Read(reader),
FfiConverterStringINSTANCE.Read(reader),
}
}

Expand All @@ -24244,6 +24256,9 @@ func (c FfiConverterEvent) Write(writer io.Writer, value Event) {
FfiConverterAddressINSTANCE.Write(writer, value.Sender);
FfiConverterStringINSTANCE.Write(writer, value.Type);
FfiConverterBytesINSTANCE.Write(writer, value.Contents);
FfiConverterStringINSTANCE.Write(writer, value.Timestamp);
FfiConverterStringINSTANCE.Write(writer, value.Data);
FfiConverterStringINSTANCE.Write(writer, value.Json);
}

type FfiDestroyerEvent struct {}
Expand Down
1 change: 1 addition & 0 deletions bindings/kotlin/examples/PackageEvents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fun main() = runBlocking {
println("Type: ${event.type}")
println("Sender: ${event.sender}")
println("Module: ${event.module}")
println("JSON: ${event.json}")
}
} catch (e: Exception) {
e.printStackTrace()
Expand Down
30 changes: 27 additions & 3 deletions bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44043,7 +44043,19 @@ data class Event (
/**
* BCS serialized bytes of the event
*/
var `contents`: kotlin.ByteArray
var `contents`: kotlin.ByteArray,
/**
* UTC timestamp in milliseconds since epoch (1/1/1970)
*/
var `timestamp`: kotlin.String,
/**
* Structured contents of a Move value
*/
var `data`: kotlin.String,
/**
* Representation of a Move value in JSON
*/
var `json`: kotlin.String
) : Disposable {

@Suppress("UNNECESSARY_SAFE_CALL") // codegen is much simpler if we unconditionally emit safe calls here
Expand All @@ -44054,7 +44066,10 @@ data class Event (
this.`module`,
this.`sender`,
this.`type`,
this.`contents`
this.`contents`,
this.`timestamp`,
this.`data`,
this.`json`
)
}

Expand All @@ -44072,6 +44087,9 @@ public object FfiConverterTypeEvent: FfiConverterRustBuffer<Event> {
FfiConverterTypeAddress.read(buf),
FfiConverterString.read(buf),
FfiConverterByteArray.read(buf),
FfiConverterString.read(buf),
FfiConverterString.read(buf),
FfiConverterString.read(buf),
)
}

Expand All @@ -44080,7 +44098,10 @@ public object FfiConverterTypeEvent: FfiConverterRustBuffer<Event> {
FfiConverterString.allocationSize(value.`module`) +
FfiConverterTypeAddress.allocationSize(value.`sender`) +
FfiConverterString.allocationSize(value.`type`) +
FfiConverterByteArray.allocationSize(value.`contents`)
FfiConverterByteArray.allocationSize(value.`contents`) +
FfiConverterString.allocationSize(value.`timestamp`) +
FfiConverterString.allocationSize(value.`data`) +
FfiConverterString.allocationSize(value.`json`)
)

override fun write(value: Event, buf: ByteBuffer) {
Expand All @@ -44089,6 +44110,9 @@ public object FfiConverterTypeEvent: FfiConverterRustBuffer<Event> {
FfiConverterTypeAddress.write(value.`sender`, buf)
FfiConverterString.write(value.`type`, buf)
FfiConverterByteArray.write(value.`contents`, buf)
FfiConverterString.write(value.`timestamp`, buf)
FfiConverterString.write(value.`data`, buf)
FfiConverterString.write(value.`json`, buf)
}
}

Expand Down
1 change: 1 addition & 0 deletions bindings/python/examples/package_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ async def main():
print(f"Type: {event.type}")
print(f"Sender: {event.sender.to_hex()}")
print(f"Module: {event.module}")
print(f"JSON: {event.json}")


if __name__ == "__main__":
Expand Down
37 changes: 35 additions & 2 deletions bindings/python/lib/iota_sdk_ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10064,15 +10064,33 @@ class Event:
BCS serialized bytes of the event
"""

def __init__(self, *, package_id: "ObjectId", module: "str", sender: "Address", type: "str", contents: "bytes"):
timestamp: "str"
"""
UTC timestamp in milliseconds since epoch (1/1/1970)
"""

data: "str"
"""
Structured contents of a Move value
"""

json: "str"
"""
Representation of a Move value in JSON
"""

def __init__(self, *, package_id: "ObjectId", module: "str", sender: "Address", type: "str", contents: "bytes", timestamp: "str", data: "str", json: "str"):
self.package_id = package_id
self.module = module
self.sender = sender
self.type = type
self.contents = contents
self.timestamp = timestamp
self.data = data
self.json = json

def __str__(self):
return "Event(package_id={}, module={}, sender={}, type={}, contents={})".format(self.package_id, self.module, self.sender, self.type, self.contents)
return "Event(package_id={}, module={}, sender={}, type={}, contents={}, timestamp={}, data={}, json={})".format(self.package_id, self.module, self.sender, self.type, self.contents, self.timestamp, self.data, self.json)

def __eq__(self, other):
if self.package_id != other.package_id:
Expand All @@ -10085,6 +10103,12 @@ def __eq__(self, other):
return False
if self.contents != other.contents:
return False
if self.timestamp != other.timestamp:
return False
if self.data != other.data:
return False
if self.json != other.json:
return False
return True

class _UniffiConverterTypeEvent(_UniffiConverterRustBuffer):
Expand All @@ -10096,6 +10120,9 @@ def read(buf):
sender=_UniffiConverterTypeAddress.read(buf),
type=_UniffiConverterString.read(buf),
contents=_UniffiConverterBytes.read(buf),
timestamp=_UniffiConverterString.read(buf),
data=_UniffiConverterString.read(buf),
json=_UniffiConverterString.read(buf),
)

@staticmethod
Expand All @@ -10105,6 +10132,9 @@ def check_lower(value):
_UniffiConverterTypeAddress.check_lower(value.sender)
_UniffiConverterString.check_lower(value.type)
_UniffiConverterBytes.check_lower(value.contents)
_UniffiConverterString.check_lower(value.timestamp)
_UniffiConverterString.check_lower(value.data)
_UniffiConverterString.check_lower(value.json)

@staticmethod
def write(value, buf):
Expand All @@ -10113,6 +10143,9 @@ def write(value, buf):
_UniffiConverterTypeAddress.write(value.sender, buf)
_UniffiConverterString.write(value.type, buf)
_UniffiConverterBytes.write(value.contents, buf)
_UniffiConverterString.write(value.timestamp, buf)
_UniffiConverterString.write(value.data, buf)
_UniffiConverterString.write(value.json, buf)


class EventFilter:
Expand Down
7 changes: 4 additions & 3 deletions crates/iota-graphql-client/examples/package_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ async fn main() -> Result<()> {
.await?;

for event in events.data() {
println!("Type: {}", event.type_);
println!("Sender: {}", event.sender);
println!("Module: {}", event.module);
println!("Type: {}", event.type_.repr);
println!("Sender: {}", event.sender.as_ref().unwrap().address);
println!("Module: {}", event.sending_module.as_ref().unwrap().name);
println!("JSON: {}", event.json);
}

Ok(())
Expand Down
28 changes: 5 additions & 23 deletions crates/iota-graphql-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ use cynic::{GraphQlResponse, MutationBuilder, Operation, QueryBuilder, serde};
use error::Error;
use futures::Stream;
use iota_types::{
Address, CheckpointSequenceNumber, CheckpointSummary, Digest, Event, Identifier, MovePackage,
Object, ObjectId, SignedTransaction, Transaction, TransactionEffects, TransactionKind, TypeTag,
UserSignature, framework::Coin,
Address, CheckpointSequenceNumber, CheckpointSummary, Digest, MovePackage, Object, ObjectId,
SignedTransaction, Transaction, TransactionEffects, TransactionKind, TypeTag, UserSignature,
framework::Coin,
};
use query_types::{
ActiveValidatorsArgs, ActiveValidatorsQuery, BalanceArgs, BalanceQuery, ChainIdentifierQuery,
CheckpointArgs, CheckpointId, CheckpointQuery, CheckpointsArgs, CheckpointsQuery, CoinMetadata,
CoinMetadataArgs, CoinMetadataQuery, DryRunArgs, DryRunQuery, DynamicFieldArgs,
DynamicFieldConnectionArgs, DynamicFieldQuery, DynamicFieldsOwnerQuery,
DynamicObjectFieldQuery, Epoch, EpochArgs, EpochQuery, EpochSummaryQuery, EventFilter,
DynamicObjectFieldQuery, Epoch, EpochArgs, EpochQuery, EpochSummaryQuery, Event, EventFilter,
EventsQuery, EventsQueryArgs, ExecuteTransactionArgs, ExecuteTransactionQuery,
LatestPackageQuery, MoveFunction, MoveModule, MovePackageVersionFilter,
NormalizedMoveFunctionQuery, NormalizedMoveFunctionQueryArgs, NormalizedMoveModuleQuery,
Expand Down Expand Up @@ -890,25 +890,7 @@ impl Client {
let ec = events.events;
let page_info = ec.page_info;

let events = ec
.nodes
.into_iter()
.map(|node| {
let module = node.sending_module.ok_or_else(|| {
Error::from_error(
Kind::Deserialization,
"Expected a sending module for this event, but it is missing.",
)
})?;
Ok(Event {
package_id: module.package.address.into(),
module: Identifier::new(module.name)?,
sender: node.sender.map(|s| s.address).unwrap_or(Address::ZERO),
type_: node.type_.repr.parse()?,
contents: base64ct::Base64::decode_vec(&node.bcs.0)?,
})
})
.collect::<Result<Vec<_>>>()?;
let events = ec.nodes;

Ok(Page::new(page_info, events))
} else {
Expand Down
8 changes: 6 additions & 2 deletions crates/iota-graphql-client/src/query_types/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// SPDX-License-Identifier: Apache-2.0

use crate::query_types::{
Address, Base64, GQLAddress, MoveType, PageInfo, normalized_move::MoveModuleQuery, schema,
Address, Base64, DateTime, GQLAddress, JsonValue, MoveData, MoveType, PageInfo,
normalized_move::MoveModuleQuery, schema,
};

// ===========================================================================
Expand Down Expand Up @@ -50,11 +51,14 @@ pub struct EventFilter {
pub transaction_digest: Option<String>,
}

#[derive(cynic::QueryFragment, Debug)]
#[derive(cynic::QueryFragment, Debug, Clone)]
#[cynic(schema = "rpc", graphql_type = "Event")]
pub struct Event {
pub sending_module: Option<MoveModuleQuery>,
pub sender: Option<GQLAddress>,
pub type_: MoveType,
pub bcs: Base64,
pub timestamp: Option<DateTime>,
pub data: MoveData,
pub json: JsonValue,
}
7 changes: 6 additions & 1 deletion crates/iota-graphql-client/src/query_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ pub struct BigInt(pub String);
#[cynic(graphql_type = "DateTime")]
pub struct DateTime(pub String);

#[derive(cynic::Scalar, Debug, Clone, derive_more::From)]
#[cynic(graphql_type = "MoveData")]
pub struct MoveData(pub serde_json::Value);

// ===========================================================================
// Types used in several queries
// ===========================================================================
Expand Down Expand Up @@ -124,11 +128,12 @@ pub struct MoveValue {
pub json: Option<JsonValue>,
}

#[derive(cynic::QueryFragment, Debug)]
#[derive(cynic::QueryFragment, Debug, Clone)]
#[cynic(schema = "rpc", graphql_type = "MoveType")]
pub struct MoveType {
pub repr: String,
}

// ===========================================================================
// Utility Types
// ===========================================================================
Expand Down
Loading