Skip to content

Commit

Permalink
fix: revert conversion of case in calls to compiler
Browse files Browse the repository at this point in the history
partially reverts 0d82161
  • Loading branch information
davidyuk committed May 11, 2021
1 parent 342accf commit 0a69e49
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/contract/aci/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export function getFunctionACI (aci, name, { external }) {
bindings: [
{
state: aci.state,
typeDefs: aci.typeDefs,
type_defs: aci.type_defs,
name: aci.name
},
...external.map(R.pick(['state', 'typeDefs', 'name']))
...external.map(R.pick(['state', 'type_defs', 'name']))
],
event: aci.event ? aci.event.variant : []
}
Expand Down
4 changes: 2 additions & 2 deletions src/contract/aci/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export default async function getContractInstance (source, { aci, contractAddres
}
const instance = {
interface: R.defaultTo(null, R.prop('interface', aci)),
aci: R.defaultTo(null, R.path(['encodedAci', 'contract'], aci)),
externalAci: aci.externalEncodedAci ? aci.externalEncodedAci.map(a => a.contract || a.namespace) : [],
aci: R.defaultTo(null, R.path(['encoded_aci', 'contract'], aci)),
externalAci: aci.external_encoded_aci ? aci.external_encoded_aci.map(a => a.contract || a.namespace) : [],
source,
compiled: null,
deployInfo: { address: contractAddress },
Expand Down
2 changes: 1 addition & 1 deletion src/contract/aci/transformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function linkTypeDefs (t, bindings) {
const [root, typeDef] = typeof t === 'object' ? Object.keys(t)[0].split('.') : t.split('.')
const contractTypeDefs = bindings.find(c => c.name === root)
const aciType = [
...contractTypeDefs.typeDefs,
...contractTypeDefs.type_defs,
{ name: 'state', typedef: contractTypeDefs.state, vars: [] }
].find(({ name }) => name === typeDef)
if (aciType.vars.length) {
Expand Down
4 changes: 2 additions & 2 deletions src/contract/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default AsyncInit.compose(ContractBase, {
compilerUrl = compilerUrl.replace(/\/$/, '')
const client = await genSwaggerClient(`${compilerUrl}/api`, {
disableBigNumbers: true,
keysOfValuesToIgnore: ['fileSystem', 'arguments']
disableCaseConversion: true
})
this.compilerVersion = client.spec.info.version
this._compilerApi = client.api
Expand All @@ -67,7 +67,7 @@ export default AsyncInit.compose(ContractBase, {
if (!this._compilerApi) throw new Error('Compiler is not ready')
},
_prepareCompilerOptions ({ filesystem = {} } = {}) {
return { fileSystem: filesystem }
return { file_system: filesystem }
},
getCompilerVersion () {
this._ensureCompilerReady()
Expand Down
12 changes: 3 additions & 9 deletions src/utils/other.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,19 @@ export const filterObject = (object, fn) => Object.fromEntries(Object.entries(ob
* @rtype (fn: (s: String) => String) => (o: Object) => Object
* @param {Function} fn - Key transformation function
* @param {Object} object - Object to traverse
* @param {Array} [keysOfValuesToIgnore] - Workaround to fix serialisation
* @return {Object} Transformed object
*/
export const traverseKeys = (fn, object, keysOfValuesToIgnore = []) => {
export const traverseKeys = (fn, object) => {
if (typeof object !== 'object' || object === null) return object
if (Array.isArray(object)) return object.map(i => traverseKeys(fn, i, keysOfValuesToIgnore))
return mapObject(object, ([key, value]) => [
fn(key),
keysOfValuesToIgnore.includes(key) ? value : traverseKeys(fn, value, keysOfValuesToIgnore)
])
if (Array.isArray(object)) return object.map(i => traverseKeys(fn, i))
return mapObject(object, ([key, value]) => [fn(key), traverseKeys(fn, value)])
}

/**
* snake_case key traversal
* @static
* @rtype (o: Object) => Object
* @param {Object} object - Object to traverse
* @param {Array} keysOfValuesToIgnore
* @return {Object} Transformed object
* @see pascalToSnake
*/
Expand All @@ -40,7 +35,6 @@ export const snakizeKeys = traverseKeys.bind(null, pascalToSnake)
* @static
* @rtype (o: Object) => Object
* @param {Object} object - Object to traverse
* @param {Array} keysOfValuesToIgnore
* @return {Object} Transformed object
* @see snakeToPascal
*/
Expand Down
12 changes: 7 additions & 5 deletions src/utils/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ import { snakizeKeys, pascalizeKeys, mapObject, filterObject } from './other'
* @param {String} [options.spec] - Override OpenAPI definition
* @param {String} [options.internalUrl] - Node internal URL
* @param {Boolean} [options.disableBigNumbers]
* @param {Boolean} [options.keysOfValuesToIgnore] TODO: Convert keys according to Swagger definitions instead
* @param {Boolean} [options.disableCaseConversion]
* @return {Object} Swagger client
* @example (await genSwaggerClient('https://mainnet.aeternity.io/api')).getAccountByPubkey('ak_jupBUgZNbcC4krDLR3tAkw1iBZoBbkNeShAq4atBtpFWmz36r')
*/
export default async (specUrl, { spec, internalUrl, disableBigNumbers, keysOfValuesToIgnore } = {}) => {
export default async (specUrl, { spec, internalUrl, disableBigNumbers, disableCaseConversion } = {}) => {
spec = spec || await (await fetch(specUrl)).json()
const jsonImp = disableBigNumbers ? JSON : JsonBig

Expand Down Expand Up @@ -69,8 +69,10 @@ export default async (specUrl, { spec, internalUrl, disableBigNumbers, keysOfVal
},
responseInterceptor: response => {
if (!response.text) return response
const body = pascalizeKeys(jsonImp.parse(response.text), keysOfValuesToIgnore)
return Object.assign(response, { body })
const body = jsonImp.parse(response.text)
return Object.assign(response, {
body: disableCaseConversion ? body : pascalizeKeys(body)
})
}
})
}))
Expand Down Expand Up @@ -107,7 +109,7 @@ export default async (specUrl, { spec, internalUrl, disableBigNumbers, keysOfVal
if (typeof value !== 'object') return [param, value]
const rootKeys = Object.keys(parameters.find(p => p.name === param).schema.properties)
const filteredValue = filterObject(
snakizeKeys(value, keysOfValuesToIgnore),
disableCaseConversion ? value : snakizeKeys(value),
([key]) => rootKeys.includes(key)
)
return [param, jsonImp.stringify(filteredValue)]
Expand Down
8 changes: 1 addition & 7 deletions test/unit/other.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,17 @@ describe('Other utils', function () {
c: [3, {
ca: 4
}],
t: {
f: 6
},
d: null
}

expect(traverseKeys(k => 'x' + k, input, ['t'])).to.deep.equal({
expect(traverseKeys(k => 'x' + k, input)).to.deep.equal({
xa: 1,
xb: {
xba: 2
},
xc: [3, {
xca: 4
}],
xt: {
f: 6
},
xd: null
})
})
Expand Down

0 comments on commit 0a69e49

Please sign in to comment.