Skip to content

Commit

Permalink
Get ada from serialization-lib utxo
Browse files Browse the repository at this point in the history
  • Loading branch information
ngua committed Jan 18, 2022
1 parent e7399ff commit 975d709
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/Lib/Serialization.js
Expand Up @@ -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);
Expand All @@ -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);
11 changes: 9 additions & 2 deletions src/Lib/Serialization.purs
Expand Up @@ -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
Expand All @@ -22,6 +27,7 @@ utxoFromHex = _utxoFromBytes helper <<< _hexToBytes
{ just: Just
, nothing: Nothing
, fromString: undefined -- TODO
, decodeValue: undefined -- TODO
}

foreign import data Buffer :: Type
Expand All @@ -41,4 +47,5 @@ type UtxoHelper
= { just :: String -> Maybe String
, nothing :: Maybe String
, fromString :: String -> BigInt
, decodeValue :: Json -> Value
}

0 comments on commit 975d709

Please sign in to comment.