Skip to content

Commit dbdab1e

Browse files
committed
near: Change contract 'address' to 'account'
1 parent 3c4a600 commit dbdab1e

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

manifest-schema.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type EthereumContractSource {
3737
}
3838

3939
type NearContractSource {
40-
address: String
40+
account: String
4141
startBlock: BigInt
4242
}
4343

src/protocols/ethereum/subgraph.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const immutable = require('immutable')
22
const ABI = require('./abi')
33
const DataSourcesExtractor = require('../../command-helpers/data-sources')
4-
const { validateContractAddresses } = require('../../validation')
4+
const { validateContractValues } = require('../../validation')
55

66
module.exports = class EthereumSubgraph {
77
constructor(options = {}) {
@@ -75,9 +75,10 @@ ${abiNames
7575
validateContractAddresses() {
7676
const ethereumAddressPattern = /^(0x)?[0-9a-fA-F]{40}$/
7777

78-
return validateContractAddresses(
78+
return validateContractValues(
7979
this.manifest,
8080
this.protocol,
81+
'address',
8182
address => ethereumAddressPattern.test(address),
8283
"Must be 40 hexadecimal characters, with an optional '0x' prefix.",
8384
)

src/protocols/near/subgraph.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const immutable = require('immutable')
2-
const { validateContractAddresses } = require('../../validation')
2+
const { validateContractValues } = require('../../validation')
33

44
module.exports = class NearSubgraph {
55
constructor(options = {}) {
@@ -9,10 +9,10 @@ module.exports = class NearSubgraph {
99
}
1010

1111
validateManifest() {
12-
return this.validateContractAddresses()
12+
return this.validateContractAccounts()
1313
}
1414

15-
validateContractAddresses() {
15+
validateContractAccounts() {
1616
// Reference: https://docs.near.org/docs/concepts/account#account-id-rules
1717
const MINIMUM_ACCOUNT_ID_LENGTH = 2
1818
const MAXIMUM_ACCOUNT_ID_LENGTH = 64
@@ -21,9 +21,10 @@ module.exports = class NearSubgraph {
2121
accountId.length <= MAXIMUM_ACCOUNT_ID_LENGTH
2222
const nearAccountIdPattern = /^(([a-z\d]+[\-_])*[a-z\d]+\.)*([a-z\d]+[\-_])*[a-z\d]+$/
2323

24-
return validateContractAddresses(
24+
return validateContractValues(
2525
this.manifest,
2626
this.protocol,
27+
'account',
2728
accountId => validateLength(accountId) && nearAccountIdPattern.test(accountId),
2829
`Must be between '${MINIMUM_ACCOUNT_ID_LENGTH}' and '${MAXIMUM_ACCOUNT_ID_LENGTH}' characters
2930
An Account ID consists of Account ID parts separated by '.' (dots)

src/validation/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
22
validateSchema: require('./schema').validateSchema,
33
validateManifest: require('./manifest').validateManifest,
4-
validateContractAddresses: require('./manifest').validateContractAddresses,
4+
validateContractValues: require('./manifest').validateContractValues,
55
}

src/validation/manifest.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,35 +282,35 @@ const validateManifest = (value, type, schema, protocol, { resolveFile }) => {
282282
return validateDataSourceNetworks(value, protocol)
283283
}
284284

285-
const validateContractAddresses = (manifest, protocol, validator, errorMessage) =>
285+
const validateContractValues = (manifest, protocol, fieldName, validator, errorMessage) =>
286286
manifest
287287
.get('dataSources')
288288
.filter(dataSource => protocol.isValidKindName(dataSource.get('kind')))
289289
.reduce((errors, dataSource, dataSourceIndex) => {
290-
let path = ['dataSources', dataSourceIndex, 'source', 'address']
290+
let path = ['dataSources', dataSourceIndex, 'source', fieldName]
291291

292-
// No need to validate if the source has no contract address
293-
if (!dataSource.get('source').has('address')) {
292+
// No need to validate if the source has no contract field
293+
if (!dataSource.get('source').has(fieldName)) {
294294
return errors
295295
}
296296

297-
let address = dataSource.getIn(['source', 'address'])
297+
let contractValue = dataSource.getIn(['source', fieldName])
298298

299-
// Validate whether the address is valid
300-
if (validator(address)) {
299+
// Validate whether the contract is valid
300+
if (validator(contractValue)) {
301301
return errors
302302
} else {
303303
return errors.push(
304304
immutable.fromJS({
305305
path,
306306
message: `\
307-
Contract address is invalid: ${address}${errorMessage ? `\n${errorMessage}` : ''}`,
307+
Contract ${fieldName} is invalid: ${contractValue}${errorMessage ? `\n${errorMessage}` : ''}`,
308308
}),
309309
)
310310
}
311311
}, immutable.List())
312312

313313
module.exports = {
314314
validateManifest,
315-
validateContractAddresses,
315+
validateContractValues,
316316
}

tests/cli/validation/near-is-valid/subgraph.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dataSources:
77
- kind: near
88
name: NearSubgraph
99
source:
10-
address: wnear.flux-dev
10+
account: wnear.flux-dev
1111
startBlock: 1
1212
mapping:
1313
apiVersion: 0.0.5

0 commit comments

Comments
 (0)