Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
justraman committed Jun 12, 2023
1 parent dfe989f commit a2a9735
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 81 deletions.
26 changes: 3 additions & 23 deletions src/mappings/balances/events/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ interface EventData {
function getEventData(ctx: CommonContext, event: Event): EventData {
const data = new BalancesTransferEvent(ctx, event)

if (data.isEfinityV2) {
const { from, to, amount } = data.asEfinityV2
return { from, to, amount }
}
if (data.isEfinityV1) {
const [from, to, amount] = data.asEfinityV1
if (data.isEfinityV3014) {
const { from, to, amount } = data.asEfinityV3014
return { from, to, amount }
}

throw new UnknownVersionError(data.constructor.name)
}

Expand All @@ -44,21 +41,4 @@ export async function transfer(
amount: eventData.amount,
}),
})

// const call = ctx.event.extrinsic?.call
// if (!call || call.name !== 'Balances.transfer_all') return
//
// await saveTransfer(ctx, {
// id: call.id,
// timestamp: new Date(ctx.block.timestamp),
// blockNumber: ctx.block.height,
// extrinsicHash: ctx.event.extrinsic?.hash,
// fromId: encodeId(eventData.from),
// toId: encodeId(eventData.to),
// amount: eventData.amount,
// tip: ctx.event.extrinsic?.tip,
// error: ctx.event.extrinsic?.error,
// success: call.success,
// type: TransferType.Native,
// })
}
4 changes: 2 additions & 2 deletions src/mappings/balances/events/withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { CommonContext } from '../../types/contexts'
function getEventData(ctx: CommonContext, event: Event): bigint {
const data = new BalancesWithdrawEvent(ctx, event)

if (data.isEfinityV2) {
const { amount } = data.asEfinityV2
if (data.isEfinityV3014) {
const { amount } = data.asEfinityV3014
return amount
}

Expand Down
14 changes: 3 additions & 11 deletions src/mappings/marketplace/events/auction_finalized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,17 @@ import {
ListingStatusType,
MarketplaceAuctionFinalized,
} from '../../../model'
import { Bid } from '../../../types/generated/efinityV3012'
import { CommonContext } from '../../types/contexts'
import { Event } from '../../../types/generated/support'
import { CollectionService } from '../../../services'
import { Pusher } from '../../../common/pusher'
import { safeJson } from '../../../common/tools'

interface EventData {
listingId: Uint8Array
winningBid: Bid | undefined
protocolFee: bigint
royalty: bigint
}

function getEventData(ctx: CommonContext, event: Event): EventData {
function getEventData(ctx: CommonContext, event: Event) {
const data = new MarketplaceAuctionFinalizedEvent(ctx, event)

if (data.isEfinityV3000) {
const { listingId, winningBid, protocolFee, royalty } = data.asEfinityV3000
if (data.isEfinityV3014) {
const { listingId, winningBid, protocolFee, royalty } = data.asEfinityV3014
return { listingId, winningBid, protocolFee, royalty }
}
throw new UnknownVersionError(data.constructor.name)
Expand Down
13 changes: 3 additions & 10 deletions src/mappings/marketplace/events/bid_placed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,16 @@ import {
} from '../../../model'
import { CommonContext } from '../../types/contexts'
import { Event } from '../../../types/generated/support'
import { Bid as BidEvent } from '../../../types/generated/efinityV3012'
import { CollectionService } from '../../../services'
import { getOrCreateAccount } from '../../util/entities'
import { Pusher } from '../../../common/pusher'
import { safeJson } from '../../../common/tools'

interface EventData {
listingId: Uint8Array
bid: BidEvent
}

function getEventData(ctx: CommonContext, event: Event): EventData {
function getEventData(ctx: CommonContext, event: Event) {
const data = new MarketplaceBidPlacedEvent(ctx, event)

if (data.isEfinityV3000) {
const { listingId, bid } = data.asEfinityV3000
return { listingId, bid }
if (data.isEfinityV3014) {
return data.asEfinityV3014
}
throw new UnknownVersionError(data.constructor.name)
}
Expand Down
11 changes: 3 additions & 8 deletions src/mappings/marketplace/events/listing_cancelled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@ import { CommonContext } from '../../types/contexts'
import { Pusher } from '../../../common/pusher'
import { safeJson } from '../../../common/tools'

interface EventData {
listingId: Uint8Array
}

function getEventData(ctx: CommonContext, event: Event): EventData {
function getEventData(ctx: CommonContext, event: Event) {
const data = new MarketplaceListingCancelledEvent(ctx, event)

if (data.isEfinityV3000) {
const { listingId } = data.asEfinityV3000
return { listingId }
if (data.isEfinityV3014) {
return data.asEfinityV3014
}
throw new UnknownVersionError(data.constructor.name)
}
Expand Down
19 changes: 6 additions & 13 deletions src/mappings/marketplace/events/listing_created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,16 @@ import {
} from '../../../model'
import { Event } from '../../../types/generated/support'
import { CollectionService } from '../../../services'
import { Listing as ListingEvent, ListingData_Auction } from '../../../types/generated/efinityV3012'
import { CommonContext } from '../../types/contexts'
import { getOrCreateAccount } from '../../util/entities'
import { Pusher } from '../../../common/pusher'
import { safeJson } from '../../../common/tools'

interface EventData {
listingId: Uint8Array
listing: ListingEvent
}

function getEventData(ctx: CommonContext, event: Event): EventData {
function getEventData(ctx: CommonContext, event: Event) {
const data = new MarketplaceListingCreatedEvent(ctx, event)

if (data.isEfinityV3000) {
const { listingId, listing } = data.asEfinityV3000
return { listingId, listing }
if (data.isEfinityV3014) {
return data.asEfinityV3014
}
throw new UnknownVersionError(data.constructor.name)
}
Expand All @@ -64,12 +57,12 @@ export async function listingCreated(
const account = await getOrCreateAccount(ctx, data.listing.seller)
const feeSide = data.listing.feeSide.__kind as FeeSide
const listingData =
data.listing.data.__kind === ListingType.FixedPrice.toString()
data.listing.data.__kind === ListingType.FixedPrice
? new FixedPriceData({ listingType: ListingType.FixedPrice })
: new AuctionData({
listingType: ListingType.Auction,
startHeight: (data.listing.data as ListingData_Auction).value.startBlock,
endHeight: (data.listing.data as ListingData_Auction).value.endBlock,
startHeight: data.listing.data.value.startBlock,
endHeight: data.listing.data.value.endBlock,
})
const listingState =
data.listing.state.__kind === ListingType.FixedPrice.toString()
Expand Down
16 changes: 3 additions & 13 deletions src/mappings/marketplace/events/listing_filled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,11 @@ import { CommonContext } from '../../types/contexts'
import { Pusher } from '../../../common/pusher'
import { safeJson } from '../../../common/tools'

interface EventData {
listingId: Uint8Array
buyer: Uint8Array
amountFilled: bigint
amountRemaining: bigint
protocolFee: bigint
royalty: bigint
}

function getEventData(ctx: CommonContext, event: Event): EventData {
function getEventData(ctx: CommonContext, event: Event) {
const data = new MarketplaceListingFilledEvent(ctx, event)

if (data.isEfinityV3000) {
const { listingId, buyer, amountFilled, amountRemaining, protocolFee, royalty } = data.asEfinityV3000
return { listingId, buyer, amountFilled, amountRemaining, protocolFee, royalty }
if (data.isEfinityV3014) {
return data.asEfinityV3014
}
throw new UnknownVersionError(data.constructor.name)
}
Expand Down
3 changes: 2 additions & 1 deletion src/storage/system/account.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { UnknownVersionError } from '../../common/errors'
import { decodeId } from '../../common/tools'
import { AccountInfo } from '../../types/generated/efinityV3014'
import { SystemAccountStorage } from '../../types/generated/storage'
import { BlockContext } from '../../types/generated/support'
import { AccountInfo } from '../../types/generated/efinityV1'

async function getStorageData(ctx: BlockContext, accounts: Uint8Array[]): Promise<(AccountInfo | undefined)[] | undefined> {
const storage = new SystemAccountStorage(ctx)
Expand All @@ -11,6 +11,7 @@ async function getStorageData(ctx: BlockContext, accounts: Uint8Array[]): Promis
if (storage.isEfinityV3014) {
return storage.asEfinityV3014.getMany(accounts)
}

throw new UnknownVersionError(storage.constructor.name)
}

Expand Down

0 comments on commit a2a9735

Please sign in to comment.