import { Injectable } from '@angular/core' ; import { Observable } from 'rxjs/Observable' ; import { Web3Service } from '../../web3.service' ; import { SmartContract } from '../smart-contract.abstract' ; interface MembershipConstants { isMember : boolean ; memberIndex ? : number ; getMembers : string [ ] ; getMember : string ; membersNumber : number ; } interface MembershipActions { addMember : boolean ; addMembers ? : boolean ; removeMember ? : boolean ; } interface MembershipEvents { AddMember : { member : string ; } ; RemoveMember ? : { member : string ; } ; } export type Membership = MembershipActions & MembershipConstants & MembershipEvents ; @ Injectable ( ) export class MembershipMixin extends SmartContract < MembershipConstants , { } , MembershipActions , MembershipEvents > { get AddMember$ ( ) { return this . generateEventObservable ( 'AddMember' ) ; } get RemoveMember$ ( ) { return this . generateEventObservable ( 'RemoveMember' ) ; } get isMember ( ) { return ( address ) => this . generateConstant ( 'isMember' ) ( address ) ; } get memberIndex ( ) { return ( address ) => this . generateConstant ( 'memberIndex' , this . n ) ( address ) ; } get getMembers ( ) { return ( ) => this . generateConstant ( 'getMembers' ) ( ) ; } get getMember ( ) { return ( index ) => this . generateConstant ( 'getMember' ) ( index ) ; } get membersNumber ( ) { return ( ) => this . generateConstant ( 'membersNumber' , this . n ) ( ) ; } get addMember ( ) { return ( member , name ) => this . generateAction ( 'addMember' ) ( member , name ) ; } get addMembers ( ) { return ( members ) => this . generateAction ( 'addMembers' ) ( members ) ; } get removeMember ( ) { return ( address ) => this . generateAction ( 'removeMember' ) ( address ) ; } constructor ( protected web3Service ) { super ( web3Service , undefined ) ; } async imMember ( ) { const account = await this . web3Service . getAccount ( ) . toPromise ( ) ; return await this . isMember ( account ) ; } }