Skip to content

Commit

Permalink
modify dapps to multisignature
Browse files Browse the repository at this point in the history
  • Loading branch information
edumar111 committed Feb 24, 2022
1 parent c7b0980 commit d958906
Show file tree
Hide file tree
Showing 62 changed files with 4,719 additions and 523 deletions.
5 changes: 5 additions & 0 deletions contracts/AccountRules.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ contract AccountRules is AccountRulesProxy, AccountRulesList {
return confirmed;
}

function revokeConfirmation(uint256 _transactionId) public onlyAdmin returns (bool){
bool confirmed = _revokeConfirmation(_transactionId);
return confirmed;
}

function addAccount(
address account
) external onlyAdmin onlyOnEditMode returns (bool) {
Expand Down
9 changes: 8 additions & 1 deletion contracts/AccountRulesList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ contract AccountRulesList {
function setStorage(AccountStorageMultiSig _storage) internal {
accountStorage = _storage;
}


function getStorage() public view returns (address){
return address(accountStorage);
}
function upgradeVersion(address _newVersion) internal {
accountStorage.upgradeVersion(_newVersion);
}
Expand Down Expand Up @@ -83,6 +86,10 @@ contract AccountRulesList {
accountStorage.confirmTransaction(msg.sender, transactionId);
return true;
}
function _revokeConfirmation(uint256 transactionId) internal returns (bool){
accountStorage.revokeConfirmation(msg.sender, transactionId);
return true;
}

function _addAllTargets(address[] memory targets) internal returns (bool) {
bool allAdded = true;
Expand Down
15 changes: 12 additions & 3 deletions contracts/AccountStorageMultiSig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ contract AccountStorageMultiSig is AccountStorage{
uint public transactionCount;

struct Transaction {
uint transactionId;
address account_target;
bool isAccount;
bool executed;
Expand Down Expand Up @@ -108,12 +109,12 @@ contract AccountStorageMultiSig is AccountStorage{
function revokeConfirmation(address sender, uint transactionId)
public
ownerExists(sender)
confirmed(transactionId, msg.sender)
confirmed(transactionId, sender)
notExecuted(transactionId)
onlyAccountRules
{
confirmations[transactionId][msg.sender] = false;
emit Revocation(msg.sender, transactionId);
confirmations[transactionId][sender] = false;
emit Revocation(sender, transactionId);
}

/// @dev Allows anyone to execute a confirmed transaction.
Expand Down Expand Up @@ -176,6 +177,7 @@ contract AccountStorageMultiSig is AccountStorage{
transactionId = transactionCount;

transactions[transactionId] = Transaction({
transactionId:transactionId,
account_target: _account_target,
isAccount: _isAccount,
executed: false
Expand Down Expand Up @@ -262,6 +264,13 @@ contract AccountStorageMultiSig is AccountStorage{
_transactionIds[i - from] = transactionIdsTemp[i];
}

/// @dev Returns list of transaction in defined range.
/// @param transactionId Transaction ID.
/// @return Returns transaction
function getTransaction(uint transactionId) public view returns (address ,bool, bool,uint ) {
Transaction memory txn = transactions[transactionId];
return (txn.account_target, txn.isAccount,txn.executed , txn.transactionId);
}
/*
* Events
*/
Expand Down
6 changes: 6 additions & 0 deletions contracts/NodeRules.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ contract NodeRules is NodeRulesProxy, NodeRulesList {
return confirmed;
}

function revokeConfirmation(uint256 _transactionId) public onlyAdmin returns (bool){
bool confirmed = _revokeConfirmation(_transactionId);
return confirmed;
}


function addEnode(
bytes32 enodeHigh,
bytes32 enodeLow,
Expand Down
17 changes: 9 additions & 8 deletions contracts/NodeRulesList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ contract NodeRulesList is Types{
nodeStorage = _storage;
}

function getStorage() public view returns (address){
return address(nodeStorage);
}
function upgradeVersion(address _newVersion) internal {
nodeStorage.upgradeVersion(_newVersion);
}
Expand Down Expand Up @@ -57,6 +60,11 @@ contract NodeRulesList is Types{
return true;
}

function _revokeConfirmation(uint256 transactionId) internal returns (bool){
nodeStorage.revokeConfirmation(msg.sender, transactionId);
return true;
}

function calculateKey(bytes32 _enodeHigh, bytes32 _enodeLow, bytes16 _ip, uint16 _port) public view returns(uint256) {
return nodeStorage.calculateKey(_enodeHigh, _enodeLow , _ip, _port);
}
Expand All @@ -65,14 +73,7 @@ contract NodeRulesList is Types{
return nodeStorage.getByIndex(index);
}

/*function getByEnode(
bytes32 _enodeHigh,
bytes32 _enodeLow,
bytes16 _ip,
uint16 _port)public view returns (NodeType nodeType, bytes6 geoHash, string memory name, string memory organization, string memory did, bytes32 group) {
return nodeStorage.getByEnode()
}*/


function setValidateEnodeIdOnly(bool _onlyUseEnodeId) internal returns (bool) {
return nodeStorage.setValidateEnodeIdOnly(_onlyUseEnodeId);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/NodeStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ contract NodeStorage is Types{
return allowlist.length;
}

function getOwner(uint256 index) internal onlyNodeRules view returns(address){
function getOwner(uint256 index) internal view returns(address){
address adminContractAddress = ingressContract.getContractAddress(ingressContract.ADMIN_CONTRACT());
require(adminContractAddress != address(0), "Ingress contract must have Admin contract registered");
return Admin(adminContractAddress).getOwner(index);
Expand Down
16 changes: 13 additions & 3 deletions contracts/NodeStorageMultiSig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ contract NodeStorageMultiSig is NodeStorage{
uint public transactionCount;

struct Transaction {
uint transactionId;
Enode node;
bool executed;
}
Expand Down Expand Up @@ -107,12 +108,12 @@ contract NodeStorageMultiSig is NodeStorage{
function revokeConfirmation(address sender, uint transactionId)
public
ownerExists(sender)
confirmed(transactionId, msg.sender)
confirmed(transactionId, sender)
notExecuted(transactionId)
onlyNodeRules
{
confirmations[transactionId][msg.sender] = false;
emit Revocation(msg.sender, transactionId);
confirmations[transactionId][sender] = false;
emit Revocation(sender, transactionId);
}

/// @dev Allows anyone to execute a confirmed transaction.
Expand Down Expand Up @@ -178,6 +179,7 @@ contract NodeStorageMultiSig is NodeStorage{
});

transactions[transactionId] = Transaction({
transactionId:transactionId,
node: enode,
executed: false
});
Expand Down Expand Up @@ -263,6 +265,14 @@ contract NodeStorageMultiSig is NodeStorage{
_transactionIds[i - from] = transactionIdsTemp[i];
}

/// @dev Returns list of transaction in defined range.
/// @param transactionId Transaction ID.
/// @return Returns transaction
function getTransaction(uint transactionId) public view returns (bytes32 enodeHigh, bytes32 enodeLow, bytes16 ip, uint16 port, NodeType nodeType, bytes6 geoHash, string memory name, string memory organization, string memory did, bytes32 group, uint transactionid, bool executed){
Transaction memory txn = transactions[transactionId];
return (txn.node.enodeHigh, txn.node.enodeLow, txn.node.ip, txn.node.port, txn.node.nodeType, txn.node.geoHash, txn.node.name, txn.node.organization, txn.node.did, txn.node.group, txn.transactionId,txn.executed );
}

/*
* Events
*/
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"dependencies": {
"@material-ui/core": "^4.12.3",
"@material-ui/icons": "^4.11.2",
"@openzeppelin/cli": "^2.8.2",
"@truffle/hdwallet-provider": "^1.2.0",
"@types/classnames": "^2.2.8",
"@types/enzyme": "^3.9.3",
Expand All @@ -52,16 +53,20 @@
"@types/node": "^12.0.4",
"@types/react": "^16.8.19",
"@types/react-dom": "^16.8.4",
"@types/styled-components": "^4.1.15",
"classnames": "^2.3.1",
"dotenv": "^10.0.0",
"ethers": "^4.0.49",
"idx": "^2.5.6",
"jest-junit": "^12.2.0",
"ngeohash": "^0.6.3",
"react": "16.14.0",
"react-dom": "16.14.0",
"react-router-dom": "^5.2.1",
"react-scripts": "3.4.4",
"rimble-ui": "^0.8.0",
"sass": "*",
"styled-components": "^4.2.0",
"typescript": "^3.5.1",
"web3": "^1.5.3",
"web3-utils": "^1.5.3"
Expand Down
3 changes: 3 additions & 0 deletions src/@types/rimble-ui/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/** Declaration file generated by dts-gen */

declare module 'rimble-ui';
16 changes: 16 additions & 0 deletions src/chain/contracts/AccountStorageMultiSig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Contract } from 'ethers';
import AccountStorageMultiSigAbi from '../abis/AccountStorageMultiSig.json';
import { AccountRules } from '../@types/AccountRules';
import { AccountStorageMultiSig } from '../@types/AccountStorageMultiSig';

let instance: AccountStorageMultiSig | null = null;

export const accountStorageMultiSigFactory = async (accountRulesInstance: AccountRules) => {
if (instance) return instance;


const accountStorageMultiSigAddress = await accountRulesInstance.functions.getStorage();

instance = new Contract(accountStorageMultiSigAddress, AccountStorageMultiSigAbi.abi, accountRulesInstance.signer) as AccountStorageMultiSig;
return instance;
};
1 change: 0 additions & 1 deletion src/chain/contracts/NodeRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const nodeRulesFactory = async (ingressInstance: NodeIngress) => {

const ruleContractName = await ingressInstance.functions.RULES_CONTRACT();
const nodeRulesAddress = await ingressInstance.functions.getContractAddress(ruleContractName);

instance = new Contract(nodeRulesAddress, NodeRulesAbi.abi, ingressInstance.signer) as NodeRules;
return instance;
};
15 changes: 15 additions & 0 deletions src/chain/contracts/NodeStorageMultiSig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Contract, Signer } from 'ethers';
import NodeStorageMultiSigAbi from '../abis/NodeStorageMultiSig.json';
import {NodeRules } from '../@types/NodeRules';
import { NodeStorageMultiSig } from '../@types/NodeStorageMultiSig';


let instance: NodeStorageMultiSig | null = null;

export const nodeStorageMultiSigFactory = async (nodeRulesInstance: NodeRules ) => {
if (instance) return instance;

const nodeStorageMultiSigAddress = await nodeRulesInstance.functions.getStorage();
instance = new Contract(nodeStorageMultiSigAddress, NodeStorageMultiSigAbi.abi, nodeRulesInstance.signer) as NodeStorageMultiSig;
return instance;
};
11 changes: 11 additions & 0 deletions src/components/AccountTab/AccountTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { addAccountDisplay, removeAccountDisplay } from '../../constants/modals'

type AccountTab = {
list: any[];
listTransaction:any[];
modals: {
add: boolean;
remove: boolean | string;
Expand All @@ -18,6 +19,8 @@ type AccountTab = {
toggleModal: (name: 'add' | 'remove' | 'lock') => (value?: boolean | string) => void;
handleAdd: (value: any) => Promise<void>;
handleRemove: (value: any) => Promise<void>;
handleConfirm:(value: any) => Promise<void>;
handleRevoke:(value: any) => Promise<void>;
isAdmin: boolean;
deleteTransaction: (identifier: string) => void;
isValid: (address: string) => { valid: boolean };
Expand All @@ -27,10 +30,13 @@ type AccountTab = {

const AccountTab: React.FC<AccountTab> = ({
list,
listTransaction,
modals,
toggleModal,
handleAdd,
handleRemove,
handleConfirm,
handleRevoke,
isAdmin,
deleteTransaction,
isValid,
Expand All @@ -42,9 +48,12 @@ const AccountTab: React.FC<AccountTab> = ({
<Fragment>
<AccountTable
list={list}
listTransaction={listTransaction}
toggleModal={toggleModal}
isAdmin={isAdmin}
deleteTransaction={deleteTransaction}
handleConfirm={handleConfirm}
handleRevoke={handleRevoke}
isReadOnly={isReadOnly}
/>
<AddModal
Expand Down Expand Up @@ -76,6 +85,8 @@ AccountTab.propTypes = {
toggleModal: PropTypes.func.isRequired,
handleAdd: PropTypes.func.isRequired,
handleRemove: PropTypes.func.isRequired,
handleConfirm: PropTypes.func.isRequired,
handleRevoke: PropTypes.func.isRequired,
isAdmin: PropTypes.bool.isRequired,
deleteTransaction: PropTypes.func.isRequired,
isValid: PropTypes.func.isRequired,
Expand Down
7 changes: 5 additions & 2 deletions src/components/AccountTab/EmptyRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { TableCell, TableRow } from '@material-ui/core';
import React from 'react';
// Styles
import styles from './styles.module.scss';
type EmptyRow = {
type: string;

const EmptyRow: React.FC<{}> = () => (
};
const EmptyRow: React.FC<EmptyRow> = ({type}) => (
<TableRow>
<TableCell colSpan={2} className={styles.emptyLine}>
No accounts have been added.
No {type} have been added.
</TableCell>
</TableRow>
);
Expand Down
Loading

0 comments on commit d958906

Please sign in to comment.