Only use subgraph query result to populate function history (#93)

* Only use subgraph query result to populate function history

* Fix rollback for functions with no rollback history
This commit is contained in:
mzhu25 2020-12-16 23:14:19 -08:00 committed by GitHub
parent 15a508f3ea
commit 7a42df9a65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -236,13 +236,16 @@ async function functionHistoryAsync(proxyFunctions: ProxyFunctionEntity[]): Prom
name: 'fnSelector', name: 'fnSelector',
message: 'Enter the selector or name of the function:', message: 'Enter the selector or name of the function:',
choices: [ choices: [
..._.flatMap(Object.entries(selectorToSignature), ([selector, signature]) => [ ...proxyFunctions.map(fn => ({
{ title: selector, value: selector, description: signature }, title: fn.id,
{ title: signature, value: selector, description: selector }, value: fn.id,
]), description: selectorToSignature[fn.id] || '(function signature not found)',
...proxyFunctions })),
.filter(fn => !Object.keys(selectorToSignature).includes(fn.id)) ...proxyFunctions.map(fn => ({
.map(fn => ({ title: fn.id, value: fn.id, description: '(function signature not found)' })), title: selectorToSignature[fn.id] || '(function signature not found)',
value: fn.id,
description: fn.id,
})),
], ],
}); });
const functionEntity = proxyFunctions.find(fn => fn.id === fnSelector); const functionEntity = proxyFunctions.find(fn => fn.id === fnSelector);
@ -312,6 +315,8 @@ async function generateRollbackAsync(proxyFunctions: ProxyFunctionEntity[]): Pro
value: constants.NULL_ADDRESS, value: constants.NULL_ADDRESS,
description: 'Rolls back to address(0)', description: 'Rolls back to address(0)',
}, },
...(previousImpl !== constants.NULL_ADDRESS
? [
{ {
title: 'PREVIOUS', title: 'PREVIOUS',
value: previousImpl, value: previousImpl,
@ -319,6 +324,8 @@ async function generateRollbackAsync(proxyFunctions: ProxyFunctionEntity[]): Pro
_.findLast(fullHistory, update => update.impl === previousImpl)!.timestamp, _.findLast(fullHistory, update => update.impl === previousImpl)!.timestamp,
)})`, )})`,
}, },
]
: []),
...[...new Set(rollbackHistory)] ...[...new Set(rollbackHistory)]
.filter(impl => impl !== constants.NULL_ADDRESS) .filter(impl => impl !== constants.NULL_ADDRESS)
.map(impl => ({ .map(impl => ({