---
# System prepended metadata

title: multisighandlermodule
tags: [strunfun]

---

###### tags: `strunfun`

# multisighandlermodule

## Description
The module which knows about the specific MultiSig Contracts - thus also knows how to treat them. It should know all the types and has the capability to deploy new and manages our known contracts to choose from.

## Expectation to the Environment
- `allModules.contractmanagermodule` - dependency [contractmanagermodule](https://hackmd.io/quCugmQvS_eMIj6L19LvpQ?view)
- `allModules.ethershandlermodule` - dependency [ethershandlermodule](https://hackmd.io/tEuEIpJmTFKPnJP3Ds9OrQ?view)
- `allModules.statemodule` - dependency [pwa-sources-statemodule](https://hackmd.io/nn708ujuRLeo0crmfr2X_Q?view)
- `byteCodes° = require "./multisigbytecodes"`
- `abis° = require "./multisigabis"`

## Structure
- `byteCodes°`
- `abis°`
- `contractManager°`
- `ethersHandler°`
- `state°`
- `currentContract°`
- `knownContracts°`
- `loadCurrentContract§`
- `addNewContract§` `chainId"`, `address"`, `type"`
- `probeUnknownContract§` `chainId"`, `address"`
- `.initialize§`
- `addKnownContracts§`
- `onContractChange§`
- `onAccountChange§`
- `setCorrectStatusMessage§`
- `.deployMultiSig2of3§` `owners["`

## Specification
- `byteCodes°` = map `type"` -> `byteCode"` where `byteCode` is the specific compiled byte code used for deployment
- `abis°` = map `type"` -> `ABI°`
- `contractManager°` = reference to the external [contractmanagermodule](https://hackmd.io/quCugmQvS_eMIj6L19LvpQ?view)
- `ethersHandler°` = reference to the external [ethershandlermodule](https://hackmd.io/tEuEIpJmTFKPnJP3Ds9OrQ?view)
- `state°` = reference to the external [pwa-sources-statemodule](https://hackmd.io/nn708ujuRLeo0crmfr2X_Q?view)
- `currentContract°` = the currently active `contract°` where `contract` is a [`MultiSigContract°`](https://hackmd.io/yFCXiF_wTJKgNT90uY7_Tg)
- `knownContracts°` = map of `contractId"` -> `contract°` of all known [`MultiSigContract°`](https://hackmd.io/yFCXiF_wTJKgNT90uY7_Tg)
- `loadCurrentContract>§` = 
    - retrieves contract for currently defined `contractAddress"` in our `state` accordingly to our current `chainId"`
    - also checks our contract type and calls `§>addNewContract` if it is a valid contract but was unknown
- `addNewContract>§` `chainId"`, `address"`, `type"` = 
    - creates the `contract°` as [`MultiSigContract°`](https://hackmd.io/yFCXiF_wTJKgNT90uY7_Tg)
    - adds the `contract` to the `knownContracts`
    - saves the `knownContracts` to the `state`
    - retrieves ABI and adds the contract to the `contractManager`
- `probeUnknownContract>§` `chainId"`, `address"` =
    - uses the `"NoType"` ABI to request the contract type
    - for add the contract as `"Probe"+chainId"+address"` to the `contractManager`
    - we return `"NoType"` if any error occurs in the call.
- `addKnownContracts>§`
    - go through all `contract°` of `knownContracts°`
        - add them to the `contractManager`
- `onContractChange§` = called when the `contractAddress` changes in the `state`
    - checks if the contract is valid sets type and status accordingly if it is not
    - if it is valid calls `§loadCurrentContract`
    - if we have a `currentContract` then call `§checkCurrentContract`
- `onAccountChange§` = called when the `account` changes in the `state`
    - calls `§checkCurrentContract`
- `checkCurrentContract§` = retrieves the `account` from the `state` and uses the `currentContract` 
    - to set the `type` in our `state`
    - to check if it is complete - then sets `isComplete` accordingly in our `state`
    - to check if our account is authorized - then sets `currentWalletIsOwner` accordingly in our `state`
    - then sets the `statusMessage` appropriately or calls `§setCorrectStatusMessage`
- `setCorrectStatusMessage§` = sets the `statusMessage` appropriately according to our`state`
- `.initialize§`
    - wires up our `contractManager`, `ethersHandler` and `state` to referencing the external module
    - loads `knownContracts` from the `state` or intializes it if it does not exist yet
    - sets an appropriate change detection function on our `state` for `knownContracts`
    - `§>addKNownContracts`
    - `§>loadCurrentContract`
    - wires up our onChange listeners on our `state` for `contractAddress` and `account`
- `.deployMultiSig2of3§` `owners["`
    - uses the `abi` and `code` for `"MultiSig2of3"` to then call`§ethersHandler.getNewDeployedContract abi,code,owners`
    - creates a new `contract°` and saves it to `knownContracts`
    - saves the `contract.address` to our `state` as `contractAddress`
