Fixed recursive promise filling for contract calls.

This commit is contained in:
Richard Moore 2018-07-26 16:57:47 -04:00
parent dda957c8e5
commit 640ed5dc33
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295

View File

@ -37,7 +37,7 @@ var allowedTransactionKeys: { [ key: string ]: boolean } = {
// @TODO: Expand this to resolve any promises too
function resolveAddresses(provider: MinimalProvider, value: any, paramType: ParamType | Array<ParamType>): Promise<any> {
if (Array.isArray(paramType)) {
var promises: Array<Promise<string>> = [];
var promises: Array<Promise<any>> = [];
paramType.forEach((paramType, index) => {
var v = null;
if (Array.isArray(value)) {
@ -54,10 +54,25 @@ function resolveAddresses(provider: MinimalProvider, value: any, paramType: Para
return provider.resolveName(value);
}
if (paramType.components) {
if (paramType.type === 'tuple') {
return resolveAddresses(provider, value, paramType.components);
}
// Strips one level of array indexing off the end to recuse into
let isArrayMatch = paramType.type.match(/(.*)(\[[0-9]*\]$)/);
if (isArrayMatch) {
if (!Array.isArray(value)) { throw new Error('invalid value for array'); }
var promises: Array<Promise<any>> = [];
var subParamType = {
components: paramType.components,
type: isArrayMatch[1],
};
value.forEach((v) => {
promises.push(resolveAddresses(provider, v, subParamType));
});
return Promise.all(promises);
}
return Promise.resolve(value);
}