From 52fbe1baad2fcf98abfd0c48973e9b53e389afe0 Mon Sep 17 00:00:00 2001 From: Sowmay Jain Date: Sat, 2 May 2020 22:18:39 +1000 Subject: [PATCH] modified mock.sol and readme --- README.md | 9 +++++---- contracts/connectors/mock.sol | 13 ++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b371440..a34ddae 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,11 @@ Connectors are standardized modules that let Smart Account interact with various - The contracts should not have `selfdestruct()`. - The contracts should not have `delegatecall()`. -- Use `uint(-1)` for maximum amount everywhere ([example](/)). -- Import `contracts/common` files ([example](/)). -- Add `getId` & `setId`, two additional parameter for external public facing functions ([example](/)). -- Use `getUint()` or `setUint()` functions to fetch or store values ([example](/)). +- Use `uint(-1)` for maximum amount everywhere. +- Import files from common directory. +- If needed, add `getId` & `setId`, two additional parameter for external public facing functions to fetch or store values. +- Use `getUint()` or `setUint()` functions to fetch or store values. +- Call `emitEvent()` after every external public facing functions to follow a common event standard for better analytics. ## Support diff --git a/contracts/connectors/mock.sol b/contracts/connectors/mock.sol index 03a8bc3..9e7059f 100644 --- a/contracts/connectors/mock.sol +++ b/contracts/connectors/mock.sol @@ -1,5 +1,6 @@ pragma solidity ^0.6.0; +// import files from common directory import { DSMath } from "../common/math.sol"; import { Stores } from "../common/stores.sol"; @@ -7,9 +8,19 @@ contract MockProtocol is Stores, DSMath { event LogMock(uint mockOne, uint mockTwo, uint getId, uint setId); + // added two additional parameter (getId & setId) for external public facing functions function mockFunction(uint mockNumber, uint getId, uint setId) external payable { - uint mockBalance = mockNumber == uint(-1) ? address(this).balance : mockNumber; + // fetch value of specific id + uint mockBalance = getUint(getId, mockNumber); + + // uses uint(-1) + mockBalance = mockBalance == uint(-1) ? address(this).balance : mockNumber; + + // store new value for specific id + setUint(setId, mockNumber); + + // common event standard emit LogMock(mockNumber, mockBalance, getId, setId); bytes32 eventCode = keccak256("LogMock(uint256,uint256,uint256,uint256)"); bytes memory eventData = abi.encode(mockNumber, mockBalance, getId, setId);