@helios-lang/ledger
Advanced tools
Comparing version 0.1.28 to 0.1.29
{ | ||
"name": "@helios-lang/ledger", | ||
"version": "0.1.28", | ||
"version": "0.1.29", | ||
"description": "Ledger types (eg. for building transactions)", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -10,3 +10,3 @@ import { | ||
import { Assets } from "./Assets.js" | ||
import { ByteStream } from "@helios-lang/codec-utils" | ||
import { ByteStream, hexToBytes } from "@helios-lang/codec-utils" | ||
import { | ||
@@ -101,2 +101,23 @@ ByteArrayData, | ||
/** | ||
* Blockfrost has a special format for Value | ||
* @param {{unit: string, quantity: string}[]} list | ||
* @returns {Value} | ||
*/ | ||
static fromBlockfrost(list) { | ||
return list.reduce((sum, { unit, quantity }) => { | ||
const qty = BigInt(quantity) | ||
if (unit == "lovelace") { | ||
return sum.add(new Value(qty)) | ||
} else { | ||
const mph = unit.substring(0, 56) | ||
const tokenName = unit.substring(56) | ||
return sum.add( | ||
new Value(0n, new Assets([[mph, [[tokenName, qty]]]])) | ||
) | ||
} | ||
}, new Value()) | ||
} | ||
/** | ||
* @param {ByteArrayLike} bytes | ||
@@ -103,0 +124,0 @@ * @returns {Value} |
@@ -34,2 +34,11 @@ /** | ||
/** | ||
* Blockfrost has a special format for Value | ||
* @param {{unit: string, quantity: string}[]} list | ||
* @returns {Value} | ||
*/ | ||
static fromBlockfrost(list: { | ||
unit: string; | ||
quantity: string; | ||
}[]): Value; | ||
/** | ||
* @param {ByteArrayLike} bytes | ||
@@ -36,0 +45,0 @@ * @returns {Value} |
Sorry, the diff of this file is not supported yet
690419
19850