import { MerkleTree } from './merkle-tree' ; import { Hash , Hashable } from '@uniqys/signature' ; import { Serializable , BufferWriter , BufferReader , SizedBuffer , List } from '@uniqys/serialize' ; export class Transaction implements Hashable , Serializable { public readonly hash : Hash ; constructor ( public readonly data ) { this . hash = Hash . fromData ( this . data ) ; } public static deserialize ( reader ) { return new Transaction ( SizedBuffer . deserialize ( reader ) ) ; } public serialize ( writer ) { SizedBuffer . serialize ( this . data , writer ) ; } public equals ( other ) { return this . data . equals ( other . data ) ; } } export class TransactionList implements Hashable , Serializable , Iterable < Transaction > { public get hash ( ) { return MerkleTree . root ( this . transactions ) ; } constructor ( public readonly transactions ) { } public static deserialize ( reader ) { return new TransactionList ( List . deserialize ( Transaction . deserialize ) ( reader ) ) ; } public serialize ( writer ) { List . serialize < Transaction > ( ( t , w ) => t . serialize ( w ) ) ( this . transactions , writer ) ; } public [ Symbol . iterator ] ( ) { return this . transactions [ Symbol . iterator ] ( ) ; } }