import { BigNumber } from "@joincivil/typescript-types" ; import { EthAddress , TwoStepEthTransaction } from "../../types" ; import { EthApi } from "@joincivil/ethapi" ; import { MultiSigWalletContract } from "../generated/wrappers/multi_sig_wallet" ; import { createTwoStepTransaction } from "../utils/contracts" ; export class MultisigTransaction { public static async fromId ( ethApi , instance , id ) { const data = await instance . transactions . callAsync ( ethApi . toBigNumber ( id ) . toString ( ) ) ; return new MultisigTransaction ( ethApi , instance , id , { destination : data [ 0 ] , value : new BigNumber ( data [ 1 ] ) , data : data [ 2 ] , executed : data [ 3 ] , } ) ; } public readonly id : number ; public readonly information : Readonly < MultisigTransactionStruct > ; private readonly ethApi : EthApi ; private readonly instance : MultiSigWalletContract ; private constructor ( ethApi , instance , id , transactionData ) { this . ethApi = ethApi ; this . instance = instance ; this . id = id ; this . information = transactionData ; } /**
     * Returns whether this transaction can be executed:
     *  - Wasn't executed beforehand
     *  - Has enough confirmations
     */ public async canBeExecuted ( ) { return ! this . information . executed && this . instance . isConfirmed . callAsync ( this . ethApi . toBigNumber ( this . id ) ) ; } /**
     * Returns how many confirmations this Transaction needs to be executed
     * This is a sugar function, which is the same as the one in the main Multisig wrapper
     */ public async requiredConfirmations ( ) { return new BigNumber ( await this . instance . required . callAsync ( ) ) . toNumber ( ) ; } /**
     * How many owners (and who) have confirmed this transaction
     */ public async confirmations ( ) { return this . instance . getConfirmations . callAsync ( this . ethApi . toBigNumber ( this . id ) ) ; } returns public async execute ( ) { return createTwoStepTransaction ( this . ethApi , await this . instance . executeTransaction . sendTransactionAsync ( this . ethApi . toBigNumber ( this . id ) ) , async ( receipt ) => MultisigTransaction . fromId ( this . ethApi , this . instance , this . id ) ) ; } returns public async confirmTransaction ( ) { return createTwoStepTransaction ( this . ethApi , await this . instance . confirmTransaction . sendTransactionAsync ( this . ethApi . toBigNumber ( this . id ) ) , receipt => this ) ; } returns public async revokeConfirmation ( ) { return createTwoStepTransaction ( this . ethApi , await this . instance . revokeConfirmation . sendTransactionAsync ( this . ethApi . toBigNumber ( this . id ) ) , receipt => this ) ; } } export interface MultisigTransactionStruct { destination : EthAddress ; value : BigNumber ; data : string ; executed : boolean ; }