Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const q_identity = _identityProto.SerializedIdentity.decode(q_peer.identity);
peer.mspid = q_identity.mspid;
// MEMBERSHIP
const q_membership_message = _gossipProto.GossipMessage.decode(q_peer.membership_info.payload);
peer.endpoint = q_membership_message.alive_msg.membership.endpoint;
logger.debug('%s - found peer :%s', method, peer.endpoint);
// STATE
if (q_peer.state_info) {
const message_s = _gossipProto.GossipMessage.decode(q_peer.state_info.payload);
if (message_s && message_s.state_info && message_s.state_info.properties && message_s.state_info.properties.ledger_height) {
peer.ledger_height = Long.fromValue(message_s.state_info.properties.ledger_height);
} else {
logger.debug('%s - did not find ledger_height', method);
peer.ledger_height = Long.fromValue(0);
}
logger.debug('%s - found ledger_height :%s', method, peer.ledger_height);
peer.chaincodes = [];
for (const index in message_s.state_info.properties.chaincodes) {
const q_chaincode = message_s.state_info.properties.chaincodes[index];
const chaincode = {};
chaincode.name = q_chaincode.getName();
chaincode.version = q_chaincode.getVersion();
//TODO metadata ?
logger.debug('%s - found chaincode :%j', method, chaincode);
peer.chaincodes.push(chaincode);
}
}
//all done with this peer
peers.push(peer);
/value parameter is missing/,
'Check that we able to see an error with a bad value on the convert'
);
converted = utils.convertToLong(1);
if(converted.equals(Long.fromValue(1))) {
t.pass('Successfully utils.convertToLong integer to long');
} else {
t.fail('utils.convertToLong did not work for integer');
}
let some_long = Long.fromValue(2);
converted = utils.convertToLong(some_long);
if(converted.equals(Long.fromValue(2))) {
t.pass('Successfully utils.convertToLong a long');
} else {
t.fail('utils.convertToLong did not work for long');
}
some_long = Long.fromValue(0);
converted = utils.convertToLong(some_long);
if(converted.equals(Long.fromValue(0))) {
t.pass('Successfully utils.convertToLong a long');
} else {
t.fail('utils.convertToLong did not work for long');
}
some_long = Long.fromValue('0');
converted = utils.convertToLong(some_long);
if(converted.equals(Long.fromValue(0))) {
const orderToProto = (o: IOrder & { chainId: number }): wavesProto.waves.IOrder => ({
chainId: o.chainId,
senderPublicKey: base58Decode(o.senderPublicKey),
matcherPublicKey: base58Decode(o.matcherPublicKey),
assetPair: {
amountAssetId: o.assetPair.amountAsset == null ? null : base58Decode(o.assetPair.amountAsset),
priceAssetId: o.assetPair.priceAsset == null ? null : base58Decode(o.assetPair.priceAsset)
},
orderSide: o.orderType === "buy" ? undefined : wavesProto.waves.Order.Side.SELL,
amount: Long.fromValue(o.amount),
price: Long.fromValue(o.price),
timestamp: Long.fromValue(o.timestamp),
expiration: Long.fromValue(o.expiration),
matcherFee: amountToProto(o.matcherFee, null),
version: o.version,
proofs: o.proofs.map(base58Decode),
})
return committedOffset === '-1'
? resolvedOffsetLong
: resolvedOffsetLong.subtract(Long.fromValue(committedOffset))
}
const subtractPartitionOffsets = (topic, partition) =>
subtractOffsets(
this.resolvedOffsets[topic][partition],
this.committedOffsets()[topic][partition]
)
const subtractTopicOffsets = topic =>
toPartitions(topic).map(partition => subtractPartitionOffsets(topic, partition))
const offsetsDiff = this.topics.map(subtractTopicOffsets)
return flatten(offsetsDiff).reduce((sum, offset) => sum.add(offset), Long.fromValue(0))
}
_findHighest(peers) {
let highest = Long.fromValue(0);
for (const peer of peers) {
try {
if (peer.ledger_height.greaterThan(highest)) {
highest = peer.ledger_height;
}
} catch (error) {
logger.warn('problem finding highest block:%s', error);
}
}
return highest;
}
export const longToInt = (d: number | Long) =>
Long.fromValue(FixLong(d)).toInt();
const clamp = (i: number) => (i < 0 ? 0 : i);
_findHighest(peers) {
let highest = Long.fromValue(0);
for (const peer of peers) {
try {
if (peer.ledger_height.greaterThan(highest)) {
highest = peer.ledger_height;
}
} catch (error) {
logger.error('problem finding highest block with %s', error);
throw Error(`Unable to find highest block value :: ${error.toString()}`);
}
}
return highest;
}
const isSameOffset = (offsetA, offsetB) => Long.fromValue(offsetA).equals(Long.fromValue(offsetB))
Kval.messageToSign = function (_) {
var ns = new TextEncoder().encode(_.namespace);
var b = new Uint8Array(_.key.byteLength + _.value.byteLength + ns.byteLength + 8);
var offset = 0;
b.set(_.key, offset);
offset += _.key.byteLength;
b.set(_.value, offset);
offset += _.value.byteLength;
b.set(ns, offset);
offset += ns.byteLength;
var created = Long.fromValue(_.created);
var high = created.getHighBits();
b[offset++] = (high >>> 24) & 0xff;
b[offset++] = (high >>> 16) & 0xff;
b[offset++] = (high >>> 8) & 0xff;
b[offset++] = high & 0xff;
var low = created.getLowBits();
b[offset++] = (low >>> 24) & 0xff;
b[offset++] = (low >>> 16) & 0xff;
b[offset++] = (low >>> 8) & 0xff;
b[offset++] = low & 0xff;
return b;
};
return Kval;
const subtractOffsets = (resolvedOffset, committedOffset) => {
const resolvedOffsetLong = Long.fromValue(resolvedOffset)
return committedOffset === '-1'
? resolvedOffsetLong
: resolvedOffsetLong.subtract(Long.fromValue(committedOffset))
}