diff --git a/packages/near-contract-standards/src/fungible_token/events.ts b/packages/near-contract-standards/src/fungible_token/events.ts index 96a613c0..862d0ecb 100644 --- a/packages/near-contract-standards/src/fungible_token/events.ts +++ b/packages/near-contract-standards/src/fungible_token/events.ts @@ -18,19 +18,24 @@ import { NearEvent } from "../event"; import { Option } from "../non_fungible_token/utils"; import { AccountId, Balance } from "near-sdk-js"; +import { toSnakeCase } from "../util"; export type Nep141EventKind = FtMint[] | FtTransfer[] | FtBurn[]; export class Nep141Event extends NearEvent { - version: string; - event_kind: Nep141EventKind; - - constructor(version: string, event_kind: Nep141EventKind) { - super(); - this.version = version; - this.event_kind = event_kind; - } + standard: string; + version: string; + event: string; + data: Nep141EventKind; + + constructor(version: string, event_kind: Nep141EventKind) { + super(); + this.standard = "nep141" + this.version = version + this.event = toSnakeCase(event_kind[0].constructor.name) + this.data = event_kind } +} /** Data to log for an FT mint event. To log this event, call [`.emit()`](FtMint::emit). */ export class FtMint { diff --git a/packages/near-contract-standards/src/non_fungible_token/events.ts b/packages/near-contract-standards/src/non_fungible_token/events.ts index f8d5e810..c94d374b 100644 --- a/packages/near-contract-standards/src/non_fungible_token/events.ts +++ b/packages/near-contract-standards/src/non_fungible_token/events.ts @@ -16,17 +16,22 @@ import { AccountId } from "near-sdk-js"; import { NearEvent } from "../event"; import { TokenId } from "./token"; +import { toSnakeCase } from "../util"; export type Nep171EventKind = NftMint[] | NftTransfer[] | NftBurn[]; export class Nep171Event extends NearEvent { + standard: string; version: string; - event_kind: Nep171EventKind; + event: string; + data: Nep171EventKind; constructor(version: string, event_kind: Nep171EventKind) { super(); - this.version = version; - this.event_kind = event_kind; + this.standard = "nep171" + this.version = version + this.event = toSnakeCase(event_kind[0].constructor.name) + this.data = event_kind } } diff --git a/packages/near-contract-standards/src/util.ts b/packages/near-contract-standards/src/util.ts new file mode 100644 index 00000000..6878f2d9 --- /dev/null +++ b/packages/near-contract-standards/src/util.ts @@ -0,0 +1,3 @@ +export const toSnakeCase = (str: string) => { + return str.replace(/[A-Z]/g, (letter, index) => { return index == 0 ? letter.toLowerCase() : '_'+ letter.toLowerCase();}); +} \ No newline at end of file