Skip to content

Latest commit

 

History

History
879 lines (694 loc) · 24 KB

MultiSigKeyHolders.md

File metadata and controls

879 lines (694 loc) · 24 KB

Multi Signature Key Holders contract.

  • This contract contains the implementation of functions to add and remove key holders w/ rBTC and BTC addresses. (MultiSigKeyHolders.sol)

View Source: contracts/multisig/MultiSigKeyHolders.sol

↗ Extends: Ownable

MultiSigKeyHolders contract

Structs

Data

struct Data {
 bool added,
 uint248 index
}

Contract Members

Constants & Variables

//public members
uint256 public constant MAX_OWNER_COUNT;
uint256 public ethereumRequired;
uint256 public bitcoinRequired;

//private members
string private constant ERROR_INVALID_ADDRESS;
string private constant ERROR_INVALID_REQUIRED;
mapping(address => struct MultiSigKeyHolders.Data) private isEthereumAddressAdded;
address[] private ethereumAddresses;
mapping(string => struct MultiSigKeyHolders.Data) private isBitcoinAddressAdded;
string[] private bitcoinAddresses;

Events

event EthereumAddressAdded(address indexed account);
event EthereumAddressRemoved(address indexed account);
event EthereumRequirementChanged(uint256  required);
event BitcoinAddressAdded(string  account);
event BitcoinAddressRemoved(string  account);
event BitcoinRequirementChanged(uint256  required);

Modifiers

validRequirement

modifier validRequirement(uint256 ownerCount, uint256 _required) internal

Arguments

Name Type Description
ownerCount uint256
_required uint256

Functions


addEthereumAddress

Add rBTC address to the key holders.

function addEthereumAddress(address _address) public nonpayable onlyOwner 

Arguments

Name Type Description
_address address The address to be added.
Source Code
function addEthereumAddress(address _address) public onlyOwner {
        _addEthereumAddress(_address);
    }

addEthereumAddresses

Add rBTC addresses to the key holders.

function addEthereumAddresses(address[] _address) public nonpayable onlyOwner 

Arguments

Name Type Description
_address address[] The addresses to be added.
Source Code
function addEthereumAddresses(address[] memory _address) public onlyOwner {
        for (uint256 i = 0; i < _address.length; i++) {
            _addEthereumAddress(_address[i]);
        }
    }

_addEthereumAddress

Internal function to add rBTC address to the key holders.

function _addEthereumAddress(address _address) internal nonpayable

Arguments

Name Type Description
_address address The address to be added.
Source Code
function _addEthereumAddress(address _address) internal {
        require(_address != address(0), ERROR_INVALID_ADDRESS);

        if (!isEthereumAddressAdded[_address].added) {
            isEthereumAddressAdded[_address] = Data({
                added: true,
                index: uint248(ethereumAddresses.length)
            });
            ethereumAddresses.push(_address);
        }

        emit EthereumAddressAdded(_address);
    }

removeEthereumAddress

Remove rBTC address to the key holders.

function removeEthereumAddress(address _address) public nonpayable onlyOwner 

Arguments

Name Type Description
_address address The address to be removed.
Source Code
function removeEthereumAddress(address _address) public onlyOwner {
        _removeEthereumAddress(_address);
    }

removeEthereumAddresses

Remove rBTC addresses to the key holders.

function removeEthereumAddresses(address[] _address) public nonpayable onlyOwner 

Arguments

Name Type Description
_address address[] The addresses to be removed.
Source Code
function removeEthereumAddresses(address[] memory _address) public onlyOwner {
        for (uint256 i = 0; i < _address.length; i++) {
            _removeEthereumAddress(_address[i]);
        }
    }

_removeEthereumAddress

Internal function to remove rBTC address to the key holders.

function _removeEthereumAddress(address _address) internal nonpayable

Arguments

Name Type Description
_address address The address to be removed.
Source Code
function _removeEthereumAddress(address _address) internal {
        require(_address != address(0), ERROR_INVALID_ADDRESS);

        if (isEthereumAddressAdded[_address].added) {
            uint248 index = isEthereumAddressAdded[_address].index;
            if (index != ethereumAddresses.length - 1) {
                ethereumAddresses[index] = ethereumAddresses[ethereumAddresses.length - 1];
                isEthereumAddressAdded[ethereumAddresses[index]].index = index;
            }
            ethereumAddresses.length--;
            delete isEthereumAddressAdded[_address];
        }

        emit EthereumAddressRemoved(_address);
    }

isEthereumAddressOwner

Get whether rBTC address is a key holder.

function isEthereumAddressOwner(address _address) public view
returns(bool)

Arguments

Name Type Description
_address address The rBTC address to be checked.
Source Code
function isEthereumAddressOwner(address _address) public view returns (bool) {
        return isEthereumAddressAdded[_address].added;
    }

getEthereumAddresses

Get array of rBTC key holders.

function getEthereumAddresses() public view
returns(address[])
Source Code
function getEthereumAddresses() public view returns (address[] memory) {
        return ethereumAddresses;
    }

changeEthereumRequirement

Set flag ethereumRequired to true/false.

function changeEthereumRequirement(uint256 _required) public nonpayable onlyOwner validRequirement 

Arguments

Name Type Description
_required uint256 The new value of the ethereumRequired flag.
Source Code
function changeEthereumRequirement(uint256 _required)
        public
        onlyOwner
        validRequirement(ethereumAddresses.length, _required)
    {
        ethereumRequired = _required;
        emit EthereumRequirementChanged(_required);
    }

addBitcoinAddress

Add bitcoin address to the key holders.

function addBitcoinAddress(string _address) public nonpayable onlyOwner 

Arguments

Name Type Description
_address string The address to be added.
Source Code
function addBitcoinAddress(string memory _address) public onlyOwner {
        _addBitcoinAddress(_address);
    }

addBitcoinAddresses

Add bitcoin addresses to the key holders.

function addBitcoinAddresses(string[] _address) public nonpayable onlyOwner 

Arguments

Name Type Description
_address string[] The addresses to be added.
Source Code
function addBitcoinAddresses(string[] memory _address) public onlyOwner {
        for (uint256 i = 0; i < _address.length; i++) {
            _addBitcoinAddress(_address[i]);
        }
    }

_addBitcoinAddress

Internal function to add bitcoin address to the key holders.

function _addBitcoinAddress(string _address) internal nonpayable

Arguments

Name Type Description
_address string The address to be added.
Source Code
function _addBitcoinAddress(string memory _address) internal {
        require(bytes(_address).length != 0, ERROR_INVALID_ADDRESS);

        if (!isBitcoinAddressAdded[_address].added) {
            isBitcoinAddressAdded[_address] = Data({
                added: true,
                index: uint248(bitcoinAddresses.length)
            });
            bitcoinAddresses.push(_address);
        }

        emit BitcoinAddressAdded(_address);
    }

removeBitcoinAddress

Remove bitcoin address to the key holders.

function removeBitcoinAddress(string _address) public nonpayable onlyOwner 

Arguments

Name Type Description
_address string The address to be removed.
Source Code
function removeBitcoinAddress(string memory _address) public onlyOwner {
        _removeBitcoinAddress(_address);
    }

removeBitcoinAddresses

Remove bitcoin addresses to the key holders.

function removeBitcoinAddresses(string[] _address) public nonpayable onlyOwner 

Arguments

Name Type Description
_address string[] The addresses to be removed.
Source Code
function removeBitcoinAddresses(string[] memory _address) public onlyOwner {
        for (uint256 i = 0; i < _address.length; i++) {
            _removeBitcoinAddress(_address[i]);
        }
    }

_removeBitcoinAddress

Internal function to remove bitcoin address to the key holders.

function _removeBitcoinAddress(string _address) internal nonpayable

Arguments

Name Type Description
_address string The address to be removed.
Source Code
function _removeBitcoinAddress(string memory _address) internal {
        require(bytes(_address).length != 0, ERROR_INVALID_ADDRESS);

        if (isBitcoinAddressAdded[_address].added) {
            uint248 index = isBitcoinAddressAdded[_address].index;
            if (index != bitcoinAddresses.length - 1) {
                bitcoinAddresses[index] = bitcoinAddresses[bitcoinAddresses.length - 1];
                isBitcoinAddressAdded[bitcoinAddresses[index]].index = index;
            }
            bitcoinAddresses.length--;
            delete isBitcoinAddressAdded[_address];
        }

        emit BitcoinAddressRemoved(_address);
    }

isBitcoinAddressOwner

Get whether bitcoin address is a key holder.

function isBitcoinAddressOwner(string _address) public view
returns(bool)

Arguments

Name Type Description
_address string The bitcoin address to be checked.
Source Code
function isBitcoinAddressOwner(string memory _address) public view returns (bool) {
        return isBitcoinAddressAdded[_address].added;
    }

getBitcoinAddresses

Get array of bitcoin key holders.

function getBitcoinAddresses() public view
returns(string[])
Source Code
function getBitcoinAddresses() public view returns (string[] memory) {
        return bitcoinAddresses;
    }

changeBitcoinRequirement

Set flag bitcoinRequired to true/false.

function changeBitcoinRequirement(uint256 _required) public nonpayable onlyOwner validRequirement 

Arguments

Name Type Description
_required uint256 The new value of the bitcoinRequired flag.
Source Code
function changeBitcoinRequirement(uint256 _required)
        public
        onlyOwner
        validRequirement(bitcoinAddresses.length, _required)
    {
        bitcoinRequired = _required;
        emit BitcoinRequirementChanged(_required);
    }

addEthereumAndBitcoinAddresses

Add rBTC and bitcoin addresses to the key holders.

function addEthereumAndBitcoinAddresses(address[] _ethereumAddress, string[] _bitcoinAddress) public nonpayable onlyOwner 

Arguments

Name Type Description
_ethereumAddress address[] the rBTC addresses to be added.
_bitcoinAddress string[] the bitcoin addresses to be added.
Source Code
function addEthereumAndBitcoinAddresses(
        address[] memory _ethereumAddress,
        string[] memory _bitcoinAddress
    ) public onlyOwner {
        for (uint256 i = 0; i < _ethereumAddress.length; i++) {
            _addEthereumAddress(_ethereumAddress[i]);
        }
        for (uint256 i = 0; i < _bitcoinAddress.length; i++) {
            _addBitcoinAddress(_bitcoinAddress[i]);
        }
    }

removeEthereumAndBitcoinAddresses

Remove rBTC and bitcoin addresses to the key holders.

function removeEthereumAndBitcoinAddresses(address[] _ethereumAddress, string[] _bitcoinAddress) public nonpayable onlyOwner 

Arguments

Name Type Description
_ethereumAddress address[] The rBTC addresses to be removed.
_bitcoinAddress string[] The bitcoin addresses to be removed.
Source Code
function removeEthereumAndBitcoinAddresses(
        address[] memory _ethereumAddress,
        string[] memory _bitcoinAddress
    ) public onlyOwner {
        for (uint256 i = 0; i < _ethereumAddress.length; i++) {
            _removeEthereumAddress(_ethereumAddress[i]);
        }
        for (uint256 i = 0; i < _bitcoinAddress.length; i++) {
            _removeBitcoinAddress(_bitcoinAddress[i]);
        }
    }

Contracts