import { Injectable } from '@angular/core' ; import { Web3Service } from '../../web3.service' ; import { SmartContract } from '../smart-contract.abstract' ; interface OwnableConstants { owner : string ; } interface OwnableActions { transferOwnership : void ; } interface OwnableEvents { OwnershipTransferred : { previousOwner : string ; newOwner : string ; } ; } export type Ownable = OwnableActions & OwnableConstants & OwnableEvents ; @ Injectable ( ) export class OwnableMixin extends SmartContract < OwnableConstants , { } , OwnableActions , OwnableEvents > { get OwnershipTransferred$ ( ) { return this . generateEventObservable ( 'OwnershipTransferred' ) ; } get owner ( ) { return ( ) => this . generateConstant ( 'owner' ) ( ) ; } get transferOwnership ( ) { return ( newOwner ) => this . generateAction ( 'transferOwnership' ) ( newOwner ) ; } constructor ( protected web3Service ) { super ( web3Service , undefined ) ; } async isOwner ( account ) { const owner = await this . owner ( ) ; return owner . toLowerCase ( ) === account . toLowerCase ( ) ; } async imOwner ( ) { return this . isOwner ( await this . web3Service . getAccount ( ) . toPromise ( ) ) ; } }