Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
feat: renames and refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
julianmrodri committed Jul 27, 2020
1 parent a1b3ea5 commit 1f36b7c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Eth } from 'web3-eth'

import type { AgreementService, OfferService } from './services/storage'
import type { RatesService } from './services/rates'
import type { RnsService } from './services/rns'
import type { RnsBaseService } from './services/rns'
import { ConfirmatorService } from './blockchain/confirmator'

export enum SupportedServices {
Expand Down Expand Up @@ -34,9 +34,9 @@ interface ServiceTypes {
[ServiceAddresses.STORAGE_OFFERS]: OfferService & ServiceAddons<any>
[ServiceAddresses.STORAGE_AGREEMENTS]: AgreementService & ServiceAddons<any>
[ServiceAddresses.XR]: RatesService & ServiceAddons<any>
[ServiceAddresses.RNS_DOMAINS]: RnsService & ServiceAddons<any>
[ServiceAddresses.RNS_SOLD]: RnsService & ServiceAddons<any>
[ServiceAddresses.RNS_OFFERS]: RnsService & ServiceAddons<any>
[ServiceAddresses.RNS_DOMAINS]: RnsBaseService & ServiceAddons<any>
[ServiceAddresses.RNS_SOLD]: RnsBaseService & ServiceAddons<any>
[ServiceAddresses.RNS_OFFERS]: RnsBaseService & ServiceAddons<any>
[ServiceAddresses.CONFIRMATIONS]: ConfirmatorService & ServiceAddons<any>
}

Expand Down
20 changes: 10 additions & 10 deletions src/services/rns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import eventProcessor from './rns.processor'

const logger = loggingFactory('rns')

export class RnsService extends Service {
export class RnsBaseService extends Service {
emit?: Function
}
export interface RnsServices {
domains: RnsService & { emit?: Function }
sold: RnsService & { emit?: Function }
offers: RnsService & { emit?: Function }
domains: RnsBaseService & { emit?: Function }
sold: RnsBaseService & { emit?: Function }
offers: RnsBaseService & { emit?: Function }
}

function fetchEventsForService (eth: Eth, serviceName: string, abi: AbiItem[], dataPusher: (event: EventData) => void): Promise<void> {
Expand Down Expand Up @@ -76,9 +76,9 @@ async function precache (eth?: Eth): Promise<void> {
})

const sequelizeServices = {
domains: new RnsService({ Model: Domain }),
sold: new RnsService({ Model: SoldDomain }),
offers: new RnsService({ Model: DomainOffer, multi: true })
domains: new RnsBaseService({ Model: Domain }),
sold: new RnsBaseService({ Model: SoldDomain }),
offers: new RnsBaseService({ Model: DomainOffer, multi: true })
}

for (const event of eventsDataQueue) {
Expand All @@ -98,9 +98,9 @@ const rns: CachedService = {
await waitForReadyApp(app)

// Initialize feather's service
app.use(ServiceAddresses.RNS_DOMAINS, new RnsService({ Model: Domain }))
app.use(ServiceAddresses.RNS_SOLD, new RnsService({ Model: SoldDomain }))
app.use(ServiceAddresses.RNS_OFFERS, new RnsService({ Model: DomainOffer }))
app.use(ServiceAddresses.RNS_DOMAINS, new RnsBaseService({ Model: Domain }))
app.use(ServiceAddresses.RNS_SOLD, new RnsBaseService({ Model: SoldDomain }))
app.use(ServiceAddresses.RNS_OFFERS, new RnsBaseService({ Model: DomainOffer }))

const domains = app.service(ServiceAddresses.RNS_DOMAINS)
const sold = app.service(ServiceAddresses.RNS_SOLD)
Expand Down
12 changes: 7 additions & 5 deletions src/services/rns/rns.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import config from 'config'
import { Eth } from 'web3-eth'
import { EventData } from 'web3-eth-contract'
import Utils from 'web3-utils'
import { RnsService, RnsServices } from '.'
import { RnsBaseService, RnsServices } from '.'
import { getBlockDate } from '../../blockchain/utils'
import { Logger } from '../../definitions'
import DomainOffer from './models/domain-offer.model'
Expand All @@ -13,8 +13,10 @@ import DomainOwner from './models/owner.model'
import Transfer from './models/transfer.model'
import SoldDomain from './models/sold-domain.model'

// registerTransfer: creates the transfer record and updates DomainOwner
async function registerTransfer (transactionHash: string, tokenId: string, sellerAddress: string, buyerAddress: string, logger: Logger, domainsService: RnsService) {
/**
* Creates the transfer record and updates DomainOwner
*/
async function registerTransfer (transactionHash: string, tokenId: string, sellerAddress: string, buyerAddress: string, logger: Logger, domainsService: RnsBaseService) {
const transferDomain = await Transfer.create({
id: transactionHash,
tokenId,
Expand Down Expand Up @@ -52,7 +54,7 @@ async function transferHandler (logger: Logger, eventData: EventData, eth: Eth,

const fiftsAddr = config.get('rns.fifsAddrRegistrar.contractAddress')
const registrar = config.get('rns.registrar.contractAddress')
const marketplace = config.get('rns.placement.contractAddress')
const marketplace = config.get<string>('rns.placement.contractAddress')
const tld = config.get('rns.tld')

const transactionHash = eventData.transactionHash
Expand Down Expand Up @@ -90,7 +92,7 @@ async function transferHandler (logger: Logger, eventData: EventData, eth: Eth,
return
}

if (ownerAddress === (marketplace as string).toLowerCase() || from === (marketplace as string).toLowerCase()) {
if (ownerAddress === marketplace.toLowerCase() || from === marketplace.toLowerCase()) {
return // Marketplace transfers are handled in TokenSold
}

Expand Down

0 comments on commit 1f36b7c

Please sign in to comment.