more buffer fix

This commit is contained in:
boufni95 2024-12-18 17:32:31 +00:00
parent 2334aa8a01
commit 0bf7a37b6c

View file

@ -5,11 +5,11 @@ export const utf8Encoder: TextEncoder = new TextEncoder()
export const usageMetricsToTlv = (metric: Types.UsageMetric): TLV => { export const usageMetricsToTlv = (metric: Types.UsageMetric): TLV => {
const tlv: TLV = {} const tlv: TLV = {}
tlv[2] = [integerToUint8Array(metric.processed_at_ms / 1000)] // 6 -> 6 tlv[2] = [integerToUint8Array(Math.ceil(metric.processed_at_ms / 1000))] // 6 -> 6
tlv[3] = [integerToUint8Array(metric.parsed_in_nano)] // 6 -> 12 tlv[3] = [integerToUint8Array(Math.ceil(metric.parsed_in_nano / 1000))] // 6 -> 12
tlv[4] = [integerToUint8Array(metric.auth_in_nano)] // 6 -> 18 tlv[4] = [integerToUint8Array(Math.ceil(metric.auth_in_nano / 1000))] // 6 -> 18
tlv[5] = [integerToUint8Array(metric.validate_in_nano)] // 6 -> 24 tlv[5] = [integerToUint8Array(Math.ceil(metric.validate_in_nano / 1000))] // 6 -> 24
tlv[6] = [integerToUint8Array(metric.handle_in_nano)] // 6 -> 30 tlv[6] = [integerToUint8Array(Math.ceil(metric.handle_in_nano / 1000))] // 6 -> 30
tlv[7] = [integerToUint8Array(metric.batch_size)] // 6 -> 36 tlv[7] = [integerToUint8Array(metric.batch_size)] // 6 -> 36
tlv[8] = [new Uint8Array([metric.batch ? 1 : 0])] // 3 -> 39 tlv[8] = [new Uint8Array([metric.batch ? 1 : 0])] // 3 -> 39
tlv[9] = [new Uint8Array([metric.nostr ? 1 : 0])] // 3 -> 42 tlv[9] = [new Uint8Array([metric.nostr ? 1 : 0])] // 3 -> 42
@ -21,10 +21,10 @@ export const tlvToUsageMetrics = (rpcName: string, tlv: TLV): Types.UsageMetric
const metric: Types.UsageMetric = { const metric: Types.UsageMetric = {
rpc_name: rpcName, rpc_name: rpcName,
processed_at_ms: parseInt(bytesToHex(tlv[2][0]), 16) * 1000, processed_at_ms: parseInt(bytesToHex(tlv[2][0]), 16) * 1000,
parsed_in_nano: parseInt(bytesToHex(tlv[3][0]), 16), parsed_in_nano: parseInt(bytesToHex(tlv[3][0]), 16) * 1000,
auth_in_nano: parseInt(bytesToHex(tlv[4][0]), 16), auth_in_nano: parseInt(bytesToHex(tlv[4][0]), 16) * 1000,
validate_in_nano: parseInt(bytesToHex(tlv[5][0]), 16), validate_in_nano: parseInt(bytesToHex(tlv[5][0]), 16) * 1000,
handle_in_nano: parseInt(bytesToHex(tlv[6][0]), 16), handle_in_nano: parseInt(bytesToHex(tlv[6][0]), 16) * 1000,
batch_size: parseInt(bytesToHex(tlv[7][0]), 16), batch_size: parseInt(bytesToHex(tlv[7][0]), 16),
batch: tlv[8][0][0] === 1, batch: tlv[8][0][0] === 1,
nostr: tlv[9][0][0] === 1, nostr: tlv[9][0][0] === 1,