import ChannelManager from './ChannelManager' ; import Payment from './payment' ; import { BigNumber } from 'bignumber.js' ; import Serde from './Serde' ; export interface PaymentChannelJSON { sender : string ; receiver : string ; channelId : string ; value : BigNumber ; spent : BigNumber ; state : number ; tokenContract : string ; settlementPeriod : number ; settlingUntil : BigNumber ; } export interface SerializedPaymentChannel { state : number ; spent : string ; value : string ; channelId : string ; receiver : string ; sender : string ; tokenContract ? : string ; settlementPeriod : number ; settlingUntil : string ; } /**
 * The Payment Channel
 */ export class PaymentChannel { sender : string ; receiver : string ; channelId : string ; value : BigNumber ; spent : BigNumber ; state : number ; tokenContract : string ; settlementPeriod : number ; settlingUntil : BigNumber ; param sender param receiver param channelId param value param spent param state param tokenContract param settlementPeriod param settlingUntil constructor ( sender , receiver , channelId , value , spent , state = 0 , tokenContract ? , settlementPeriod ? , settlingUntil ? ) { this . sender = sender ; this . receiver = receiver ; this . channelId = channelId ; this . value = new BigNumber ( value . toString ( ) ) ; this . spent = new BigNumber ( spent . toString ( ) ) ; this . state = Number ( state ) ; this . tokenContract = tokenContract || '' ; this . settlementPeriod = settlementPeriod || ChannelManager . DEFAULT_SETTLEMENT_PERIOD ; this . settlingUntil = settlingUntil || new BigNumber ( 0 ) ; } static fromPayment ( payment ) { return new PaymentChannel ( payment . sender , payment . receiver , payment . channelId , payment . channelValue , payment . value , undefined , payment . tokenContract || '' ) ; } static fromDocument ( document ) { return new PaymentChannel ( document . sender , document . receiver , document . channelId , document . value , document . spent , document . state , document . tokenContract , document . settlementPeriod , document . settlingUntil ) ; } } export class PaymentChannelSerde implements Serde < PaymentChannel > { static instance = new PaymentChannelSerde ( ) ; serialize ( obj ) { return { state : obj . state , spent : obj . spent . toString ( ) , value : obj . value . toString ( ) , channelId : obj . channelId . toString ( ) , receiver : obj . receiver , sender : obj . sender , tokenContract : obj . tokenContract , settlementPeriod : obj . settlementPeriod , settlingUntil : obj . settlingUntil . toString ( ) } ; } deserialize ( data ) { return new PaymentChannel ( data . sender , data . receiver , data . channelId , data . value , data . spent , data . state , data . tokenContract , data . settlementPeriod , data . settlingUntil ) ; } }