Skip to content

Commit

Permalink
fix(hydra-cli): update hydra-cli scaffold template (#39)
Browse files Browse the repository at this point in the history
* fix(hydra-cli): update hydra-cli scaffold template

affects: @subsquid/hydra-cli

1) remove timestamp extrinsic call 2) add batch_size and block_window default overrides in .env

* fix(hydra-cli): add subsquid indexers to the scaffold selector

affects: @subsquid/hydra-cli
  • Loading branch information
dzhelezov committed Jul 8, 2021
1 parent 4a4425d commit 7a1c52b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 30 deletions.
24 changes: 18 additions & 6 deletions packages/hydra-cli/src/commands/scaffold.ts
Expand Up @@ -28,14 +28,26 @@ const INDEXERS = [
url: 'http://localhost:4001/graphql',
},
{
name: 'subsocial',
value: 'subsocial',
description: 'Ready-to use indexer of Subsocial, hosted by Joystream',
url: 'https://subsocial-indexer.joystream.app/graphql',
name: 'Polkadot',
value: 'polkadot',
description: 'Ready-to use indexer for Polkadot, hosted by Subsquid',
url: 'https://polkadot.indexer.gc.subsquid.io/graphql',
},
{
name: 'other',
value: 'other',
name: 'Kusama',
value: 'kusama',
description: 'Ready-to use indexer for Kusama, hosted by Subsquid',
url: 'https://kusama.indexer.gc.subsquid.io/graphql',
},
{
name: 'Karura',
value: 'karura',
description: 'Ready-to use indexer for Karura, hosted by Subsquid',
url: 'https://karura.indexer.gc.subsquid.io/graphql',
},
{
name: 'manual',
value: 'manual',
description:
'Skip for now, I will manually set INDEXER_ENDPOINT_URL later on',
url: '',
Expand Down
2 changes: 2 additions & 0 deletions packages/hydra-cli/src/templates/scaffold/.env.mst
Expand Up @@ -27,6 +27,8 @@ INDEXER_ENDPOINT_URL={{{indexerUrl}}}
# Processor GraphQL API #
###############################

BATCH_SIZE=100

GRAPHQL_SERVER_PORT={{appPort}}{{^appPort}}4000{{/appPort}}
GRAPHQL_SERVER_HOST=localhost
WARTHOG_APP_PORT={{appPort}}{{^appPort}}4000{{/appPort}}
Expand Down
4 changes: 1 addition & 3 deletions packages/hydra-cli/src/templates/scaffold/manifest.yml
Expand Up @@ -24,9 +24,7 @@ mappings:
- event: balances.Transfer
handler: balancesTransfer
extrinsicHandlers:
# infer defaults
- extrinsic: timestamp.set
handler: timestampCall
# put extrinsic handlers here
preBlockHooks:
postBlockHooks:

3 changes: 1 addition & 2 deletions packages/hydra-cli/src/templates/scaffold/mappings/index.ts
@@ -1,5 +1,4 @@
// Export here all the event handler functions
// so that the indexer picks them up
//export { balancesTransfer as balances_Transfer } from './transfer'
export { balancesTransfer, timestampCall } from './mappings'

export { balancesTransfer } from './mappings'
21 changes: 4 additions & 17 deletions packages/hydra-cli/src/templates/scaffold/mappings/mappings.ts
@@ -1,8 +1,8 @@
import { Transfer, BlockTimestamp } from '../generated/graphql-server/model'
import { Transfer } from '../generated/graphql-server/model'

// run 'NODE_URL=<RPC_ENDPOINT> EVENTS=<comma separated list of events> yarn codegen:mappings-types'
// to genenerate typescript classes for events, such as Balances.TransferEvent
import { Balances, Timestamp } from './generated/types'
import { Balances } from './generated/types'
import BN from 'bn.js'
import {
ExtrinsicContext,
Expand All @@ -18,27 +18,14 @@ export async function balancesTransfer({
}: EventContext & StoreContext) {
const transfer = new Transfer()
const [from, to, value] = new Balances.TransferEvent(event).params
transfer.from = Buffer.from(from.toHex())
transfer.to = Buffer.from(to.toHex())
transfer.from = from.toHuman()
transfer.to = to.toHuman()
transfer.value = value.toBn()
transfer.tip = extrinsic ? new BN(extrinsic.tip.toString(10)) : new BN(0)
transfer.insertedAt = new Date(block.timestamp)

transfer.block = block.height
transfer.comment = `Transferred ${transfer.value} from ${transfer.from} to ${transfer.to}`
transfer.timestamp = new BN(block.timestamp)
console.log(`Saving transfer: ${JSON.stringify(transfer, null, 2)}`)
await store.save<Transfer>(transfer)
}

export async function timestampCall({
store,
event,
block,
}: ExtrinsicContext & StoreContext) {
const call = new Timestamp.SetCall(event)
const blockT = new BlockTimestamp()
blockT.timestamp = call.args.now.toBn()
blockT.blockNumber = block.height
await store.save<BlockTimestamp>(blockT)
}
4 changes: 2 additions & 2 deletions packages/hydra-cli/src/templates/scaffold/schema.graphql
@@ -1,7 +1,7 @@
" All transfers "
type Transfer @entity {
from: Bytes!
to: Bytes!
from: String!
to: String!
value: BigInt!
comment: String @fulltext(query: "commentSearch")
block: Int!
Expand Down

0 comments on commit 7a1c52b

Please sign in to comment.