UNPKG

@hashgraph/sdk

Version:
3 lines (2 loc) 5.42 kB
import e from"./AccountId.js";import o from"../StakingInfo.js";import t from"./LiveHash.js";import i from"../Hbar.js";import n from"../Timestamp.js";import r from"long";import s from"./TokenRelationshipMap.js";import*as c from"@hashgraph/proto";import l from"../Duration.js";import a from"../Key.js";import u from"../PublicKey.js";import h from"../LedgerId.js";class d{constructor(e){this.accountId=e.accountId,this.contractAccountId=e.contractAccountId,this.isDeleted=e.isDeleted,this.proxyAccountId=e.proxyAccountId,this.proxyReceived=e.proxyReceived,this.key=e.key,this.balance=e.balance,this.sendRecordThreshold=e.sendRecordThreshold,this.receiveRecordThreshold=e.receiveRecordThreshold,this.isReceiverSignatureRequired=e.isReceiverSignatureRequired,this.expirationTime=e.expirationTime,this.autoRenewPeriod=e.autoRenewPeriod,this.liveHashes=e.liveHashes,this.tokenRelationships=e.tokenRelationships,this.accountMemo=e.accountMemo,this.ownedNfts=e.ownedNfts,this.maxAutomaticTokenAssociations=e.maxAutomaticTokenAssociations,this.aliasKey=e.aliasKey,this.ledgerId=e.ledgerId,this.hbarAllowances=e.hbarAllowances,this.tokenAllowances=e.tokenAllowances,this.nftAllowances=e.nftAllowances,this.ethereumNonce=e.ethereumNonce,this.stakingInfo=e.stakingInfo,Object.freeze(this)}static _fromProtobuf(m){let f=null!=m.alias&&m.alias.length>0?a._fromProtobufKey(c.proto.Key.decode(m.alias)):null;f instanceof u||(f=null);const p=e._fromProtobuf(m.accountID);return new d({accountId:p,contractAccountId:null!=m.contractAccountID?m.contractAccountID:null,isDeleted:null!=m.deleted&&m.deleted,key:a._fromProtobufKey(m.key),balance:i.fromTinybars(null!=m.balance?m.balance:0),sendRecordThreshold:i.fromTinybars(null!=m.generateSendRecordThreshold?m.generateSendRecordThreshold:0),receiveRecordThreshold:i.fromTinybars(null!=m.generateReceiveRecordThreshold?m.generateReceiveRecordThreshold:0),isReceiverSignatureRequired:null!=m.receiverSigRequired&&m.receiverSigRequired,expirationTime:n._fromProtobuf(m.expirationTime),autoRenewPeriod:null!=m.autoRenewPeriod?new l(m.autoRenewPeriod.seconds):new l(0),proxyAccountId:null!=m.proxyAccountID&&0!==r.fromValue(m.proxyAccountID.shardNum).toInt()&&0!==r.fromValue(m.proxyAccountID.realmNum).toInt()&&0!==r.fromValue(m.proxyAccountID.accountNum).toInt()?e._fromProtobuf(m.proxyAccountID):null,proxyReceived:i.fromTinybars(null!=m.proxyReceived?m.proxyReceived:0),liveHashes:(null!=m.liveHashes?m.liveHashes:[]).map((e=>t._fromProtobuf(e))),tokenRelationships:s._fromProtobuf(null!=m.tokenRelationships?m.tokenRelationships:[]),accountMemo:null!=m.memo?m.memo:"",ownedNfts:m.ownedNfts?m.ownedNfts:r.ZERO,maxAutomaticTokenAssociations:m.maxAutomaticTokenAssociations?r.fromNumber(m.maxAutomaticTokenAssociations):r.ZERO,aliasKey:f,ledgerId:null!=m.ledgerId?h.fromBytes(m.ledgerId):null,hbarAllowances:[],tokenAllowances:[],nftAllowances:[],ethereumNonce:null!=m.ethereumNonce?m.ethereumNonce:null,stakingInfo:null!=m.stakingInfo?o._fromProtobuf(m.stakingInfo):null})}_toProtobuf(){return{accountID:this.accountId._toProtobuf(),contractAccountID:this.contractAccountId,deleted:this.isDeleted,proxyAccountID:null!=this.proxyAccountId?this.proxyAccountId._toProtobuf():null,proxyReceived:this.proxyReceived.toTinybars(),key:this.key._toProtobufKey(),balance:this.balance.toTinybars(),generateSendRecordThreshold:this.sendRecordThreshold.toTinybars(),generateReceiveRecordThreshold:this.receiveRecordThreshold.toTinybars(),receiverSigRequired:this.isReceiverSignatureRequired,expirationTime:this.expirationTime._toProtobuf(),autoRenewPeriod:this.autoRenewPeriod._toProtobuf(),liveHashes:this.liveHashes.map((e=>e._toProtobuf())),tokenRelationships:null!=this.tokenRelationships?this.tokenRelationships._toProtobuf():null,memo:this.accountMemo,ownedNfts:this.ownedNfts,maxAutomaticTokenAssociations:this.maxAutomaticTokenAssociations.toInt(),alias:null!=this.aliasKey?c.proto.Key.encode(this.aliasKey._toProtobufKey()).finish():null,ledgerId:null!=this.ledgerId?this.ledgerId.toBytes():null,ethereumNonce:this.ethereumNonce,stakingInfo:null!=this.stakingInfo?this.stakingInfo._toProtobuf():null}}static fromBytes(e){return d._fromProtobuf(c.proto.CryptoGetInfoResponse.AccountInfo.decode(e))}toBytes(){return c.proto.CryptoGetInfoResponse.AccountInfo.encode(this._toProtobuf()).finish()}toString(){return JSON.stringify(this.toJSON())}toJSON(){return{balance:this.balance.toString(),accountId:this.accountId.toString(),contractAccountId:this.contractAccountId,isDeleted:this.isDeleted,proxyAccountId:null!=this.proxyAccountId?this.proxyAccountId.toString():null,proxyReceived:this.proxyReceived.toString(),key:null!=this.key?this.key.toString():null,sendRecordThreshold:this.sendRecordThreshold.toString(),receiveRecordThreshold:this.receiveRecordThreshold.toString(),isReceiverSignatureRequired:this.isReceiverSignatureRequired,expirationTime:this.expirationTime.toString(),autoRenewPeriod:this.autoRenewPeriod.toString(),accountMemo:this.accountMemo,ownedNfts:this.ownedNfts.toString(),maxAutomaticTokenAssociations:this.maxAutomaticTokenAssociations.toString(),aliasKey:null!=this.aliasKey?this.aliasKey.toString():null,ledgerId:null!=this.ledgerId?this.ledgerId.toString():null,ethereumNonce:null!=this.ethereumNonce?this.ethereumNonce.toString():null,stakingInfo:null!=this.stakingInfo?this.stakingInfo.toJSON():null}}}export{d as default}; //# sourceMappingURL=AccountInfo.js.map