-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jin
committed
Oct 13, 2023
1 parent
9fc979b
commit 40ccc2e
Showing
8 changed files
with
146 additions
and
1 deletion.
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
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,32 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { getEventsByCreationNumber } from "../internal/event"; | ||
import { AnyNumber, GetEventsByCreationNumberResponse } from "../types"; | ||
import { AptosConfig } from "./aptos_config"; | ||
|
||
/** | ||
* A class to query all `Event` Aptos related queries | ||
*/ | ||
export class Event { | ||
readonly config: AptosConfig; | ||
|
||
constructor(config: AptosConfig) { | ||
this.config = config; | ||
} | ||
|
||
/** | ||
* Get events by creation number and the address | ||
* | ||
* @param args.address - The account address | ||
* @param args.creationNumber - The event creation number | ||
* @returns Promise<GetEventsByCreationNumberResponse> | ||
*/ | ||
async getEventsByCreationNumber(args: { | ||
address: string; | ||
creationNumber: AnyNumber; | ||
}): Promise<GetEventsByCreationNumberResponse> { | ||
const data = await getEventsByCreationNumber({ aptosConfig: this.config, ...args }); | ||
return data; | ||
} | ||
} |
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,43 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/** | ||
* This file contains the underlying implementations for exposed API surface in | ||
* the {@link api/event}. By moving the methods out into a separate file, | ||
* other namespaces and processes can access these methods without depending on the entire | ||
* account namespace and without having a dependency cycle error. | ||
*/ | ||
|
||
import { AptosConfig } from "../api/aptos_config"; | ||
import { AnyNumber, GetEventsByCreationNumberResponse, HexInput } from "../types"; | ||
import { GetEventsByCreationNumberQuery } from "../types/generated/operations"; | ||
import { GetEventsByCreationNumber } from "../types/generated/queries"; | ||
import { queryIndexer } from "./general"; | ||
|
||
/** | ||
* Get events by creation number and the address | ||
* | ||
* @param args.aptosConfig - The aptos config | ||
* @param args.address - The account address | ||
* @param args.creationNumber - The event creation number | ||
* @returns Promise<GetEventsByCreationNumberResponse> | ||
*/ | ||
export async function getEventsByCreationNumber(args: { | ||
aptosConfig: AptosConfig; | ||
address: HexInput; | ||
creationNumber: AnyNumber; | ||
}): Promise<GetEventsByCreationNumberResponse> { | ||
const { aptosConfig, address, creationNumber } = args; | ||
const graphqlQuery = { | ||
query: GetEventsByCreationNumber, | ||
variables: { address, creationNumber }, | ||
}; | ||
|
||
const data = await queryIndexer<GetEventsByCreationNumberQuery>({ | ||
aptosConfig, | ||
query: graphqlQuery, | ||
originMethod: "getEventsByCreationNumber", | ||
}); | ||
|
||
return data.events; | ||
} |
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,12 @@ | ||
query getEventsByCreationNumber($address: String, $creationNumber: bigint) { | ||
events(where: { creation_number: { _eq: $creationNumber }, account_address: { _eq: $address } }) { | ||
sequence_number | ||
type | ||
transaction_version | ||
transaction_block_height | ||
event_index | ||
data | ||
creation_number | ||
account_address | ||
} | ||
} |
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
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,24 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Account, Aptos, AptosConfig, Network, SigningScheme } from "../../../src"; | ||
|
||
describe("Event", () => { | ||
test("it should get fund events by creation number and address", async () => { | ||
const config = new AptosConfig({ network: Network.TESTNET }); | ||
const aptos = new Aptos(config); | ||
|
||
// Fund the account | ||
const testAccount = Account.generate({ scheme: SigningScheme.Ed25519 }); | ||
await aptos.fundAccount({ accountAddress: testAccount.accountAddress.toString(), amount: 10_000_000 }); | ||
|
||
const events = await aptos.getEventsByCreationNumber({ | ||
address: testAccount.accountAddress.toString(), | ||
creationNumber: 0, | ||
}); | ||
|
||
// Ensure events are returned and that the event type is CoinRegisterEvent | ||
expect(events.length).toBeGreaterThan(0); | ||
expect(events[0].type).toEqual("0x1::account::CoinRegisterEvent"); | ||
}); | ||
}); |