-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from aragon/f/generate-action-id
feat: update generateActionEntityId to include all of data on caller, dao, callId and actionIndex
- Loading branch information
Showing
7 changed files
with
68 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {generateEntityIdFromAddress} from './ids'; | ||
import {Address} from '@graphprotocol/graph-ts'; | ||
|
||
/** | ||
* @param caller the user/plugin that will invoke the execute function on the DAO | ||
* @param daoAddress the DAO address | ||
* @param callId the callID determined by the user or plugin | ||
* @param index the index # of the action in the batch | ||
* | ||
* @returns a deterministic Action ID for an action on the DAO. | ||
* This implementation only relies on data that can be fetched | ||
* from the event logs of the `Executed` event, so can be used | ||
* by client applications to query both the OSx core and the plugin | ||
* subgraphs. | ||
*/ | ||
export function generateActionEntityId( | ||
caller: Address, | ||
daoAddress: Address, | ||
callId: string, | ||
index: i32 | ||
): string { | ||
return [ | ||
generateEntityIdFromAddress(caller), | ||
generateEntityIdFromAddress(daoAddress), | ||
callId, | ||
index.toString(), | ||
].join('_'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './actions'; | ||
export * from './balance'; | ||
export * from './callbacks'; | ||
export * from './dao'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {generateActionEntityId} from '../../src'; | ||
import {ADDRESS_ONE, ADDRESS_TWO} from '../constants'; | ||
import {Address} from '@graphprotocol/graph-ts'; | ||
import {describe, test, assert} from 'matchstick-as'; | ||
|
||
function checksum(s: string): string { | ||
return Address.fromHexString(s).toHexString(); | ||
} | ||
|
||
describe('Actions ID generation', () => { | ||
test('We correctly generate the action ID', () => { | ||
const caller = ADDRESS_ONE; | ||
const daoAddress = ADDRESS_TWO; | ||
const callId = 'c4ll me'; | ||
const index = 255; | ||
|
||
const actionId = generateActionEntityId( | ||
Address.fromString(caller), | ||
Address.fromString(daoAddress), | ||
callId, | ||
index | ||
); | ||
|
||
assert.stringEquals( | ||
actionId, | ||
[checksum(caller), checksum(daoAddress), callId, index.toString()].join( | ||
'_' | ||
) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters