Skip to content

Commit

Permalink
refactor: consolidate api-genesis with api-cardano-db-hasura
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyslbw committed Nov 3, 2020
1 parent b0d0344 commit 0f927c4
Show file tree
Hide file tree
Showing 57 changed files with 315 additions and 601 deletions.
5 changes: 1 addition & 4 deletions .graphqlconfig
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"name": "Cardano GraphQL Schema",
"schemaPath": [
"./packages/api-cardano-db-hasura/schema.graphql",
"./packages/api-genesis/schema.graphql"
],
"schemaPath": "./packages/api-cardano-db-hasura/schema.graphql",
"extensions": {
"endpoints": {
"Cardano GraphQL Endpoint": {
Expand Down
7 changes: 1 addition & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ WORKDIR /application
RUN mkdir /application/packages
COPY tsconfig.json /application/
COPY packages/api-cardano-db-hasura /application/packages/api-cardano-db-hasura
COPY packages/api-genesis /application/packages/api-genesis
COPY packages/server /application/packages/server
COPY packages/util /application/packages/util
COPY packages/util-dev /application/packages/util-dev
Expand All @@ -19,9 +18,8 @@ RUN mkdir -p application/packages
COPY package.json yarn.lock .yarnrc /application/
COPY --from=builder /application/packages-cache /application/packages-cache
WORKDIR /application/packages
RUN mkdir api-cardano-db-hasura api-genesis util server
RUN mkdir api-cardano-db-hasura util server
COPY packages/api-cardano-db-hasura/package.json api-cardano-db-hasura/
COPY packages/api-genesis/package.json api-genesis/
COPY packages/server/package.json server/
COPY packages/util/package.json util/
WORKDIR /application
Expand All @@ -40,9 +38,6 @@ COPY --from=builder /application/packages/api-cardano-db-hasura/dist /applicatio
COPY --from=builder /application/packages/api-cardano-db-hasura/hasura/project /application/packages/api-cardano-db-hasura/hasura/project
COPY --from=builder /application/packages/api-cardano-db-hasura/package.json /application/packages/api-cardano-db-hasura/package.json
COPY --from=builder /application/packages/api-cardano-db-hasura/schema.graphql /application/packages/api-cardano-db-hasura/schema.graphql
COPY --from=builder /application/packages/api-genesis/dist /application/packages/api-genesis/dist
COPY --from=builder /application/packages/api-genesis/package.json /application/packages/api-genesis/package.json
COPY --from=builder /application/packages/api-genesis/schema.graphql /application/packages/api-genesis/schema.graphql
COPY --from=builder /application/packages/server/dist /application/packages/server/dist
COPY --from=builder /application/packages/server/package.json /application/packages/server/package.json
COPY --from=builder /application/packages/util/dist /application/packages/util/dist
Expand Down
101 changes: 99 additions & 2 deletions packages/api-cardano-db-hasura/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ schema {
query: Query
}

scalar BigInt
scalar DateTime
scalar Hash28Hex
scalar Hash32Hex
scalar IPv4
scalar IPv6
scalar JSONObject
scalar BigInt
scalar DateTime
scalar Percentage
scalar Timestamp
scalar URL

type Query {
Expand Down Expand Up @@ -57,6 +58,7 @@ type Query {
offset: Int
where: Epoch_bool_exp
): Epoch_aggregate!
genesis: Genesis!
rewards (
limit: Int
order_by: [Reward_order_by!]
Expand Down Expand Up @@ -197,6 +199,49 @@ type ActiveStake_sum_fields {
amount: String
}

type ByronBlockVersionData {
scriptVersion: Int!
slotDuration: Int!
maxBlockSize: Int!
maxHeaderSize: Int!
maxTxSize: Int!
maxProposalSize: Int!
mpcThd: String!
heavyDelThd: String!
updateVoteThd: String!
updateProposalThd: String!
updateImplicit: String!
softforkRule: ByronSoftForkRule!
txFeePolicy: ByronTxFeePolicy!
unlockStakeEpoch: String!
}

type ByronGenesis {
bootStakeholders: JSONObject!
heavyDelegation: JSONObject!
startTime: Timestamp!
nonAvvmBalances: JSONObject!
blockVersionData: ByronBlockVersionData!
protocolConsts: ByronProtocolConsts!
avvmDistr: JSONObject!
}

type ByronProtocolConsts {
k: Int!
protocolMagic: Int
}

type ByronSoftForkRule {
initThd: String!
minThd: String!
thdDecrement: String!
}

type ByronTxFeePolicy {
summand: String!
multiplier: String!
}

type Cardano {
tip: Block!
currentEpoch: Epoch!
Expand Down Expand Up @@ -236,6 +281,15 @@ type Delegation_aggregate_fields {
count: String
}

type ExtraEntropy {
tag: String!
}

type Genesis {
byron: ByronGenesis
shelley: ShelleyGenesis
}

type Relay {
ipv4: IPv4
ipv6: IPv6
Expand Down Expand Up @@ -301,6 +355,49 @@ input Reward_order_by {
stakePool: StakePool_order_by
}

type ShelleyGenesis {
activeSlotsCoeff: Float!
epochLength: Int!
genDelegs: JSONObject
initialFunds: JSONObject!
maxKESEvolutions: Int!
maxLovelaceSupply: String!
networkId: String!
networkMagic: Int!
protocolParams: ShelleyProtocolParams!
securityParam: Int!
slotLength: Int!
slotsPerKESPeriod: Int!
staking: ShelleyGenesisStaking
systemStart: String!
updateQuorum: Int!
}

type ShelleyGenesisStaking {
pools: JSONObject!
stake: JSONObject!
}

type ShelleyProtocolParams {
a0: Float!
decentralisationParam: Int!
eMax: Int!
extraEntropy: ExtraEntropy!
keyDeposit: Int!
maxBlockBodySize: Int!
maxBlockHeaderSize: Int!
maxTxSize: Int!
minFeeA: Int!
minFeeB: Int!
minPoolCost: Int!
minUTxOValue: Int!
nOpt: Int!
poolDeposit: Int!
protocolVersion: JSONObject!
rho: Float!
tau: Float!
}

type StakeDeregistration {
address: String!
transaction: Transaction!
Expand Down
4 changes: 4 additions & 0 deletions packages/api-cardano-db-hasura/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ export interface Config {
port: number
user: string,
},
genesis: {
byronPath: string,
shelleyPath: string
},
hasuraUri: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ query keyNetworkInfo {
minUTxOValue
nOpt
poolDeposit
protocolVersion {
major
minor
}
protocolVersion
rho
tau
}
Expand Down
14 changes: 9 additions & 5 deletions packages/api-cardano-db-hasura/src/executableSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ import { delegateToSchema } from '@graphql-tools/delegate'
import pRetry from 'p-retry'
import path from 'path'
import util from '@cardano-graphql/util'
import { Resolvers } from './graphql_types'
import { Resolvers, Genesis } from './graphql_types'
import { HasuraClient } from './HasuraClient'
import { GraphQLSchema } from 'graphql'
import { JSONObjectResolver, TimestampResolver } from 'graphql-scalars'

const GraphQLBigInt = require('graphql-bigint')

export const scalarResolvers = {
Hash28Hex: util.scalars.Hash28Hex,
Hash32Hex: util.scalars.Hash32Hex,
BigInt: GraphQLBigInt,
DateTime: util.scalars.DateTimeUtcToIso,
Percentage: util.scalars.Percentage
Hash28Hex: util.scalars.Hash28Hex,
Hash32Hex: util.scalars.Hash32Hex,
JSONObject: JSONObjectResolver,
Percentage: util.scalars.Percentage,
Timestamp: TimestampResolver
} as any

export async function buildSchema (hasuraClient: HasuraClient) {
export async function buildSchema (hasuraClient: HasuraClient, genesis: Genesis) {
let hasuraSchema: GraphQLSchema
await pRetry(async () => {
hasuraSchema = await hasuraClient.buildHasuraSchema()
Expand Down Expand Up @@ -125,6 +128,7 @@ export async function buildSchema (hasuraClient: HasuraClient) {
schema: hasuraSchema
})
},
genesis: async () => genesis,
rewards: (_root, args, context, info) => {
return delegateToSchema({
args,
Expand Down
10 changes: 9 additions & 1 deletion packages/api-cardano-db-hasura/test/activeStake.query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import { DocumentNode } from 'graphql'
import util from '@cardano-graphql/util'
import { TestClient } from '@cardano-graphql/util-dev'
import { buildClient } from './util'
import { Genesis } from '@src/graphql_types'

const genesis = {
mainnet: {
byron: require('../../../config/network/mainnet/genesis/byron.json'),
shelley: require('../../../config/network/mainnet/genesis/shelley.json')
}
} as Genesis

function loadQueryNode (name: string): Promise<DocumentNode> {
return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'active_stake'), name)
Expand All @@ -13,7 +21,7 @@ function loadQueryNode (name: string): Promise<DocumentNode> {
describe('activeStake', () => {
let client: TestClient
beforeAll(async () => {
client = await buildClient('http://localhost:3100', 'http://localhost:8090', 5442)
client = await buildClient('http://localhost:3100', 'http://localhost:8090', 5442, genesis)
})

it('can return active stake snapshots for an address', async () => {
Expand Down
10 changes: 9 additions & 1 deletion packages/api-cardano-db-hasura/test/blocks.query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import util from '@cardano-graphql/util'
import { TestClient } from '@cardano-graphql/util-dev'
import { block29021, block29022, block4490600 } from './data_assertions'
import { buildClient } from './util'
import { Genesis } from '@src/graphql_types'

const genesis = {
mainnet: {
byron: require('../../../config/network/mainnet/genesis/byron.json'),
shelley: require('../../../config/network/mainnet/genesis/shelley.json')
}
} as Genesis

function loadQueryNode (name: string): Promise<DocumentNode> {
return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'blocks'), name)
Expand All @@ -13,7 +21,7 @@ function loadQueryNode (name: string): Promise<DocumentNode> {
describe('blocks', () => {
let client: TestClient
beforeAll(async () => {
client = await buildClient('http://localhost:3100', 'http://localhost:8090', 5442)
client = await buildClient('http://localhost:3100', 'http://localhost:8090', 5442, genesis)
})

it('caps the response to 100 blocks', async () => {
Expand Down
10 changes: 9 additions & 1 deletion packages/api-cardano-db-hasura/test/cardano.query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { DocumentNode } from 'graphql'
import util from '@cardano-graphql/util'
import { TestClient } from '@cardano-graphql/util-dev'
import { buildClient } from './util'
import { Genesis } from '@src/graphql_types'

const genesis = {
mainnet: {
byron: require('../../../config/network/mainnet/genesis/byron.json'),
shelley: require('../../../config/network/mainnet/genesis/shelley.json')
}
} as Genesis

function loadQueryNode (name: string): Promise<DocumentNode> {
return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'cardano'), name)
Expand All @@ -12,7 +20,7 @@ function loadQueryNode (name: string): Promise<DocumentNode> {
describe('cardano', () => {
let client: TestClient
beforeAll(async () => {
client = await buildClient('http://localhost:3100', 'http://localhost:8090', 5442)
client = await buildClient('http://localhost:3100', 'http://localhost:8090', 5442, genesis)
})

it('Returns core information about the current state of the network', async () => {
Expand Down
10 changes: 9 additions & 1 deletion packages/api-cardano-db-hasura/test/delegations.query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import { DocumentNode } from 'graphql'
import util from '@cardano-graphql/util'
import { TestClient } from '@cardano-graphql/util-dev'
import { buildClient } from './util'
import { Genesis } from '@src/graphql_types'

const genesis = {
mainnet: {
byron: require('../../../config/network/mainnet/genesis/byron.json'),
shelley: require('../../../config/network/mainnet/genesis/shelley.json')
}
} as Genesis

function loadQueryNode (name: string): Promise<DocumentNode> {
return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'delegations'), name)
Expand All @@ -13,7 +21,7 @@ function loadQueryNode (name: string): Promise<DocumentNode> {
describe('delegations', () => {
let client: TestClient
beforeAll(async () => {
client = await buildClient('http://localhost:3100', 'http://localhost:8090', 5442)
client = await buildClient('http://localhost:3100', 'http://localhost:8090', 5442, genesis)
})

it('can return details for stake delegation', async () => {
Expand Down
10 changes: 9 additions & 1 deletion packages/api-cardano-db-hasura/test/epochs.query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import util from '@cardano-graphql/util'
import { TestClient } from '@cardano-graphql/util-dev'
import { epoch1, epoch220 } from './data_assertions'
import { buildClient } from './util'
import { Genesis } from '@src/graphql_types'

const genesis = {
mainnet: {
byron: require('../../../config/network/mainnet/genesis/byron.json'),
shelley: require('../../../config/network/mainnet/genesis/shelley.json')
}
} as Genesis

function loadQueryNode (name: string): Promise<DocumentNode> {
return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'epochs'), name)
Expand All @@ -14,7 +22,7 @@ function loadQueryNode (name: string): Promise<DocumentNode> {
describe('epochs', () => {
let client: TestClient
beforeAll(async () => {
client = await buildClient('http://localhost:3100', 'http://localhost:8090', 5442)
client = await buildClient('http://localhost:3100', 'http://localhost:8090', 5442, genesis)
})

it('Returns epoch details by number', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ import { DocumentNode } from 'graphql'
import util from '@cardano-graphql/util'
import { TestClient } from '@cardano-graphql/util-dev'
import { buildClient } from './util'
import { Genesis } from '@src/graphql_types'

const genesisFiles = {
const genesis = {
mainnet: {
byron: require('../../../config/network/mainnet/genesis/byron.json'),
shelley: require('../../../config/network/mainnet/genesis/shelley.json')
}
}
} as Genesis

function loadQueryNode (name: string): Promise<DocumentNode> {
return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries'), name)
return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'genesis'), name)
}

describe('genesis', () => {
let client: TestClient

beforeAll(async () => {
client = await buildClient(genesisFiles.mainnet)
client = await buildClient('http://localhost:3100', 'http://localhost:8090', 5442, genesis)
console.log(client)
})

it('Returns key information about the network genesis', async () => {
Expand Down
Loading

0 comments on commit 0f927c4

Please sign in to comment.