Skip to content

Commit

Permalink
feat: sanitize abi
Browse files Browse the repository at this point in the history
  • Loading branch information
nachomazzara committed Feb 23, 2019
1 parent 3e1ff06 commit 7d603b2
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
36 changes: 27 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/contracts/LANDRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as CSV from 'comma-separated-values'
import { Contract } from '../ethereum'
import { Contract, Abi } from '../ethereum'
import { fulfillContractMethods } from './verification'
const { abi } = require('./artifacts/LANDRegistry.json')

Expand All @@ -18,8 +18,9 @@ export class LANDRegistry extends Contract {
static DataError = DataError

constructor(address: string) {
super(address, abi)
fulfillContractMethods(this, abi)
const sanitizedABI = Abi.sanitize(abi)
super(address, sanitizedABI)
fulfillContractMethods(this, sanitizedABI)
}

static decodeLandData(data = '') {
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/artifacts/LANDAuction.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,4 +861,4 @@
"type": "function"
}
]
}
}
2 changes: 1 addition & 1 deletion src/contracts/artifacts/MortgageHelper.json
Original file line number Diff line number Diff line change
Expand Up @@ -715,4 +715,4 @@
"type": "event"
}
]
}
}
22 changes: 22 additions & 0 deletions src/ethereum/abi/Abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ const abi = {
if (param) {
return param.value
}
},

/**
* Sanitize ABI.
* Web3 0.X.X has "owner" as a reserved word, so if one of the event parameters name is "owner"
* it will break. This method will change every "owner" to "_owner"
* @param {array} ABI
* @return {array} - Sanitized ABI
*/
sanitize(abi) {
return abi.map(prop => {
let inputs = prop.inputs
if (prop.name && prop.type === 'event') {
inputs = prop.inputs.map(input => {
if (input.name === 'owner') {
input.name = '_owner'
}
return input
})
}
return { ...prop, inputs }
})
}
}

Expand Down

0 comments on commit 7d603b2

Please sign in to comment.