|
1 | 1 | use ethabi; |
2 | 2 |
|
| 3 | +use graph::blockchain::block_stream::{EntitySubgraphOperation, EntityWithType}; |
3 | 4 | use graph::data::store::scalar::Timestamp; |
4 | 5 | use graph::data::value::Word; |
5 | 6 | use graph::prelude::{BigDecimal, BigInt}; |
6 | 7 | use graph::runtime::gas::GasCounter; |
7 | 8 | use graph::runtime::{ |
8 | | - asc_get, asc_new, AscIndexId, AscPtr, AscType, AscValue, HostExportError, ToAscObj, |
| 9 | + asc_get, asc_new, AscIndexId, AscPtr, AscType, AscValue, HostExportError, IndexForAscTypeId, |
| 10 | + ToAscObj, |
9 | 11 | }; |
10 | 12 | use graph::{data::store, runtime::DeterministicHostError}; |
11 | 13 | use graph::{prelude::serde_json, runtime::FromAscObj}; |
12 | 14 | use graph::{prelude::web3::types as web3, runtime::AscHeap}; |
| 15 | +use graph_runtime_derive::AscType; |
13 | 16 |
|
14 | 17 | use crate::asc_abi::class::*; |
15 | 18 |
|
@@ -463,3 +466,43 @@ where |
463 | 466 | }) |
464 | 467 | } |
465 | 468 | } |
| 469 | + |
| 470 | +#[derive(Debug, Clone, Eq, PartialEq, AscType)] |
| 471 | +pub enum AscSubgraphEntityOp { |
| 472 | + Create, |
| 473 | + Modify, |
| 474 | + Delete, |
| 475 | +} |
| 476 | + |
| 477 | +#[derive(AscType)] |
| 478 | +pub struct AscEntityTrigger { |
| 479 | + pub entity_op: AscSubgraphEntityOp, |
| 480 | + pub entity_type: AscPtr<AscString>, |
| 481 | + pub entity: AscPtr<AscEntity>, |
| 482 | + pub vid: i64, |
| 483 | +} |
| 484 | + |
| 485 | +impl ToAscObj<AscEntityTrigger> for EntityWithType { |
| 486 | + fn to_asc_obj<H: AscHeap + ?Sized>( |
| 487 | + &self, |
| 488 | + heap: &mut H, |
| 489 | + gas: &GasCounter, |
| 490 | + ) -> Result<AscEntityTrigger, HostExportError> { |
| 491 | + let entity_op = match self.entity_op { |
| 492 | + EntitySubgraphOperation::Create => AscSubgraphEntityOp::Create, |
| 493 | + EntitySubgraphOperation::Modify => AscSubgraphEntityOp::Modify, |
| 494 | + EntitySubgraphOperation::Delete => AscSubgraphEntityOp::Delete, |
| 495 | + }; |
| 496 | + |
| 497 | + Ok(AscEntityTrigger { |
| 498 | + entity_op, |
| 499 | + entity_type: asc_new(heap, &self.entity_type.as_str(), gas)?, |
| 500 | + entity: asc_new(heap, &self.entity.sorted_ref(), gas)?, |
| 501 | + vid: self.vid, |
| 502 | + }) |
| 503 | + } |
| 504 | +} |
| 505 | + |
| 506 | +impl AscIndexId for AscEntityTrigger { |
| 507 | + const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::AscEntityTrigger; |
| 508 | +} |
0 commit comments