-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updateing databse models and indexes
updating log filter logic
- Loading branch information
Showing
5 changed files
with
126 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,60 @@ | ||
import { Schema, SchemaFactory } from '@nestjs/mongoose' | ||
import { SourceIntentWS } from '../dtos/SourceIntentWS' | ||
import { Network } from 'alchemy-sdk' | ||
import { IntentStruct } from '../../typing/contracts/IntentSource' | ||
import { AddressLike, BigNumberish, BytesLike } from 'ethers' | ||
|
||
@Schema() | ||
export class SourceIntentDataModel implements SourceIntentWS { | ||
blockNumber: number | ||
blockHash: string | ||
transactionIndex: number | ||
removed: boolean | ||
address: string | ||
network: Network | ||
data: string | ||
topics: string[] | ||
transactionHash: string | ||
logIndex: number | ||
export class SourceIntentDataModel implements IntentStruct { | ||
hash: BytesLike | ||
creator: AddressLike | ||
destinationChain: BigNumberish | ||
targets: AddressLike[] | ||
data: BytesLike[] | ||
rewardTokens: AddressLike[] | ||
rewardAmounts: BigNumberish[] | ||
expiryTime: BigNumberish | ||
hasBeenWithdrawn: boolean | ||
nonce: BytesLike | ||
|
||
constructor( | ||
hash: BytesLike, | ||
creator: AddressLike, | ||
destinationChain: BigNumberish, | ||
targets: AddressLike[], | ||
data: BytesLike[], | ||
rewardTokens: AddressLike[], | ||
rewardAmounts: BigNumberish[], | ||
expiryTime: BigNumberish, | ||
nonce: BytesLike, | ||
) { | ||
this.hash = hash | ||
this.creator = creator | ||
this.destinationChain = destinationChain | ||
this.targets = targets | ||
this.data = data | ||
this.rewardTokens = rewardTokens | ||
this.rewardAmounts = rewardAmounts | ||
this.expiryTime = expiryTime | ||
this.hasBeenWithdrawn = false | ||
this.nonce = nonce | ||
} | ||
|
||
static fromEvent(event: Array<any>): SourceIntentDataModel { | ||
return new SourceIntentDataModel( | ||
event[0], | ||
event[1], | ||
event[2], | ||
event[3], | ||
event[4], | ||
event[5], | ||
event[6], | ||
event[7], | ||
event[8], | ||
) | ||
} | ||
} | ||
export const SourceIntentDataSchema = SchemaFactory.createForClass(SourceIntentDataModel) | ||
SourceIntentDataSchema.index({ transactionHash: 1 }, { unique: true }) | ||
SourceIntentDataSchema.index({ hash: 1 }, { unique: true }) | ||
SourceIntentDataSchema.index( | ||
{ hasBeenWithdrawn: 1, destinationChain: 'ascending', expiryTime: 'ascending' }, | ||
{ unique: false }, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Schema, SchemaFactory } from '@nestjs/mongoose' | ||
import { SourceIntentWS } from '../dtos/SourceIntentWS' | ||
import { Network } from 'alchemy-sdk' | ||
|
||
@Schema() | ||
export class SourceIntentEventModel implements SourceIntentWS { | ||
blockNumber: number | ||
blockHash: string | ||
transactionIndex: number | ||
removed: boolean | ||
address: string | ||
network: Network | ||
data: string | ||
topics: string[] | ||
transactionHash: string | ||
logIndex: number | ||
} | ||
export const SourceIntentEventSchema = SchemaFactory.createForClass(SourceIntentEventModel) | ||
SourceIntentEventSchema.index({ transactionHash: 1 }, { unique: true }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,43 @@ | ||
import { Utils } from 'alchemy-sdk' | ||
import { EventFilter } from 'ethers' | ||
import { IntentSource__factory } from '../typing/contracts' | ||
import { SourceIntentDataModel } from '../source-intent/schemas/source-intent-data.schema' | ||
|
||
/** | ||
* | ||
* Creates the filter for the events that we want to listen to for the IntentSource contract | ||
* | ||
* event IntentCreated( | ||
bytes32 indexed _hash, | ||
address _creator, | ||
uint256 indexed _destinationChain, | ||
address[] _targets, | ||
bytes[] _data, | ||
address[] _rewardTokens, | ||
uint256[] _rewardAmounts, | ||
uint256 indexed _expiryTime, | ||
bytes32 nonce | ||
); | ||
* @param sourceIntentContractAddress | ||
* @returns | ||
* bytes32 indexed _hash, | ||
* address _creator, | ||
* uint256 indexed _destinationChain, | ||
* address[] _targets, | ||
* bytes[] _data, | ||
* address[] _rewardTokens, | ||
* uint256[] _rewardAmounts, | ||
* uint256 indexed _expiryTime, | ||
* bytes32 nonce | ||
* ); | ||
* | ||
* @param sourceIntentContractAddress address of the contract | ||
* @returns | ||
*/ | ||
export function getCreateIntentLogFilter(sourceIntentContractAddress: string): EventFilter { | ||
const intentCreated = IntentSource__factory.createInterface().getEvent('IntentCreated').topicHash | ||
return { | ||
address: sourceIntentContractAddress, | ||
topics: [ | ||
Utils.id( | ||
'IntentCreated(bytes32,address,uint256,address[],bytes[],address[],uint256[],uint256,bytes32)', | ||
), | ||
], | ||
topics: [intentCreated], | ||
} | ||
} | ||
|
||
/** | ||
* Decodes the IntentCreated event log | ||
* | ||
* @param data the encoded data from the event log | ||
* @param topics the log topics | ||
* @returns | ||
*/ | ||
export function decodeCreateIntentLog(data: string, topics: string[]): SourceIntentDataModel { | ||
const ii = IntentSource__factory.createInterface() | ||
const frag = ii.getEvent('IntentCreated') | ||
const decode = ii.decodeEventLog(frag, data, topics) | ||
return SourceIntentDataModel.fromEvent(decode) | ||
} |