Added build call handling to get account module data for smart accounts

This commit is contained in:
Juan Manuel Rodriguez Defago 2020-05-22 11:45:22 -03:00
parent 816653c12b
commit 17aba58915
4 changed files with 34 additions and 12 deletions

View File

@ -11,9 +11,11 @@ type SmartAccount @entity {
owner: User! owner: User!
creator: User! creator: User
origin: String! origin: String!
accountModule: AccountModule
} }
type AccountModule @entity { type AccountModule @entity {
@ -27,6 +29,8 @@ type AccountModule @entity {
check: String check: String
instaIndex: InstaIndex! instaIndex: InstaIndex!
accountsCloned: [SmartAccount!]! @derivedFrom(field: "accountModule")
} }
type InstaIndex @entity { type InstaIndex @entity {

View File

@ -4,5 +4,6 @@ export {
handleLogNewCheck, handleLogNewCheck,
handleLogNewMaster, handleLogNewMaster,
handleLogUpdateMaster, handleLogUpdateMaster,
handleSetBasics handleSetBasics,
handleBuild
} from "./mappings/instaIndex"; } from "./mappings/instaIndex";

View File

@ -6,6 +6,7 @@ import {
LogNewMaster, LogNewMaster,
LogUpdateMaster, LogUpdateMaster,
SetBasicsCall, SetBasicsCall,
BuildCall,
InstaIndex InstaIndex
} from "../../generated/InstaIndex/InstaIndex"; } from "../../generated/InstaIndex/InstaIndex";
import { import {
@ -13,7 +14,7 @@ import {
getOrCreateUser, getOrCreateUser,
getOrCreateSmartAccount, getOrCreateSmartAccount,
getOrCreateInstaIndex getOrCreateInstaIndex
} from '../utils/helpers' } from "../utils/helpers";
// - event: LogAccountCreated(address,indexed address,indexed address,indexed address) // - event: LogAccountCreated(address,indexed address,indexed address,indexed address)
// handler: handleLogAccountCreated // handler: handleLogAccountCreated
@ -21,9 +22,11 @@ import {
// event LogAccountCreated(address sender, address indexed owner, address indexed account, address indexed origin); // event LogAccountCreated(address sender, address indexed owner, address indexed account, address indexed origin);
export function handleLogAccountCreated(event: LogAccountCreated): void { export function handleLogAccountCreated(event: LogAccountCreated): void {
let smartAccount = getOrCreateSmartAccount(event.params.account.toHexString()); let smartAccount = getOrCreateSmartAccount(
let owner = getOrCreateUser(event.params.owner.toHexString()) event.params.account.toHexString()
let sender = getOrCreateUser(event.params.sender.toHexString()) );
let owner = getOrCreateUser(event.params.owner.toHexString());
let sender = getOrCreateUser(event.params.sender.toHexString());
smartAccount.owner = owner.id; smartAccount.owner = owner.id;
smartAccount.creator = sender.id; smartAccount.creator = sender.id;
@ -40,7 +43,7 @@ export function handleLogAccountCreated(event: LogAccountCreated): void {
export function handleLogNewAccount(event: LogNewAccount): void { export function handleLogNewAccount(event: LogNewAccount): void {
// current account version has to be retrieved from the contract // current account version has to be retrieved from the contract
let accountVersion = InstaIndex.bind(event.address).versionCount(); let accountVersion = InstaIndex.bind(event.address).versionCount();
let accountModule = getOrCreateAccountModule(accountVersion.toString()) let accountModule = getOrCreateAccountModule(accountVersion.toString());
accountModule.address = event.params._newAccount.toHexString(); accountModule.address = event.params._newAccount.toHexString();
accountModule.connectors = event.params._connectors.toHexString(); accountModule.connectors = event.params._connectors.toHexString();
@ -53,7 +56,9 @@ export function handleLogNewAccount(event: LogNewAccount): void {
// handler: handleLogNewCheck // handler: handleLogNewCheck
export function handleLogNewCheck(event: LogNewCheck): void { export function handleLogNewCheck(event: LogNewCheck): void {
let accountModule = getOrCreateAccountModule(event.params.accountVersion.toString()); let accountModule = getOrCreateAccountModule(
event.params.accountVersion.toString()
);
accountModule.check = event.params.check.toHexString(); accountModule.check = event.params.check.toHexString();
@ -82,15 +87,25 @@ export function handleLogUpdateMaster(event: LogUpdateMaster): void {
index.save(); index.save();
} }
// - event: LogUpdateMaster(indexed address)
// handler: handleLogUpdateMaster
export function handleSetBasics(call: SetBasicsCall): void { export function handleSetBasics(call: SetBasicsCall): void {
let accountVersion = InstaIndex.bind(call.to).versionCount(); let accountVersion = InstaIndex.bind(call.to).versionCount();
let accountModule = getOrCreateAccountModule(accountVersion.toString()) let accountModule = getOrCreateAccountModule(accountVersion.toString());
accountModule.address = call.inputs._account.toHexString(); accountModule.address = call.inputs._account.toHexString();
accountModule.connectors = call.inputs._connectors.toHexString(); accountModule.connectors = call.inputs._connectors.toHexString();
accountModule.save(); accountModule.save();
} }
export function handleBuild(call: BuildCall): void {
let smartAccount = getOrCreateSmartAccount(
call.outputs._account.toHexString()
);
let owner = getOrCreateUser(call.inputs._owner.toHexString());
smartAccount.owner = owner.id;
smartAccount.origin = call.inputs._origin.toHexString();
smartAccount.accountModule = call.inputs.accountVersion.toString();
smartAccount.save();
}

View File

@ -36,3 +36,5 @@ dataSources:
callHandlers: callHandlers:
- function: setBasics(address,address,address,address) - function: setBasics(address,address,address,address)
handler: handleSetBasics handler: handleSetBasics
- function: build(address,uint256,address)
handler: handleBuild