UNPKG

@hashgraph/sdk

Version:
3 lines (2 loc) 1.74 kB
import n from"../Timestamp.js";import e from"./TopicMessageChunk.js";import s from"long";import u from"../transaction/TransactionId.js";class t{constructor(n){this.consensusTimestamp=n.consensusTimestamp,this.contents=n.contents,this.runningHash=n.runningHash,this.sequenceNumber=n.sequenceNumber,this.chunks=n.chunks,this.initialTransactionId=n.initialTransactionId,Object.freeze(this)}static _ofSingle(o){return new t({consensusTimestamp:n._fromProtobuf(o.consensusTimestamp),contents:null!=o.message?o.message:new Uint8Array,runningHash:null!=o.runningHash?o.runningHash:new Uint8Array,sequenceNumber:null!=o.sequenceNumber?o.sequenceNumber instanceof s?o.sequenceNumber:s.fromNumber(o.sequenceNumber):s.ZERO,initialTransactionId:null!=o.chunkInfo&&null!=o.chunkInfo.initialTransactionID?u._fromProtobuf(o.chunkInfo.initialTransactionID):null,chunks:[e._fromProtobuf(o)]})}static _ofMany(o){const r=o[o.length-1],i=n._fromProtobuf(r.consensusTimestamp),a=r.runningHash,c=null!=r.sequenceNumber?r.sequenceNumber instanceof s?r.sequenceNumber:s.fromValue(r.sequenceNumber):s.ZERO;o.sort((n,e)=>(null!=n&&null!=n.chunkInfo&&null!=n.chunkInfo.number?n.chunkInfo.number:0)<(null!=e&&null!=e.chunkInfo&&null!=e.chunkInfo.number?e.chunkInfo.number:0)?-1:1);const m=o.map(n=>e._fromProtobuf(n)),l=m.map(n=>n.contents.length).reduce((n,e)=>n+e,0),f=new Uint8Array(l);let h=0;o.forEach(n=>{f.set(n.message,h),h+=n.message.length});let b=null;return o.length>0&&null!=o[0].chunkInfo&&null!=o[0].chunkInfo.initialTransactionID&&(b=u._fromProtobuf(o[0].chunkInfo.initialTransactionID)),new t({consensusTimestamp:i,contents:f,runningHash:a,sequenceNumber:c,chunks:m,initialTransactionId:b})}}export{t as default}; //# sourceMappingURL=TopicMessage.js.map