diff --git a/src/Lib/Serialization.js b/src/Lib/Serialization.js index a78f699f7a..150b43b20f 100644 --- a/src/Lib/Serialization.js +++ b/src/Lib/Serialization.js @@ -19,16 +19,15 @@ exports._utxoFromBytes = (helper) => (buf) => { }, output: { address: mkAddress(utxo.output().address()), - // TODO - value: undefined, - // This very well might be `undefined`, so we need to wrap it in a `Maybe` + value: helper.decodeValue( + mkValue(helper.fromString, utxo.output().amount()) + ), data_hash: maybe(helper.just, helper.nothing, utxo.data_hash()), }, }; }; -const mkTransactionId = (input) => - Buffer.from(input.transaction_id().to_bytes()).toString("hex"); +const mkTransactionId = (input) => toHex(input.transaction_id().to_bytes()); const mkAddress = (addr) => { const baseAddr = serLib.BaseAddress.from_address(addr); @@ -41,4 +40,11 @@ const mkAddress = (addr) => { }; }; +// TODO handle multi-assets +const mkValue = (fromString, val) => { + [["", [["", fromString(val.coin().to_str())]]]]; +}; + +const toHex = (bytes) => Buffer.from(bytes).toString("hex"); + const maybe = (just, nothing, x) => (x ? just(x) : nothing); diff --git a/src/Lib/Serialization.purs b/src/Lib/Serialization.purs index c1cbdda358..8b3a6d28a7 100644 --- a/src/Lib/Serialization.purs +++ b/src/Lib/Serialization.purs @@ -7,10 +7,15 @@ module Lib.Serialization ) where import Prelude +import Undefined +import Data.Argonaut (Json) import Data.BigInt (BigInt) import Data.Maybe (Maybe(..)) -import Types.Transaction (Address, TransactionUnspentOutput) -import Undefined +import Types.Transaction + ( Address + , TransactionUnspentOutput + , Value(..) + ) newtype Hex = Hex String @@ -22,6 +27,7 @@ utxoFromHex = _utxoFromBytes helper <<< _hexToBytes { just: Just , nothing: Nothing , fromString: undefined -- TODO + , decodeValue: undefined -- TODO } foreign import data Buffer :: Type @@ -41,4 +47,5 @@ type UtxoHelper = { just :: String -> Maybe String , nothing :: Maybe String , fromString :: String -> BigInt + , decodeValue :: Json -> Value }