HeliosLang / compiler

Helios is a DSL for writing Cardano smart contracts. This library lets you compile Helios scripts and build Cardano transactions.
https://www.hyperion-bt.org/helios-book
BSD 3-Clause "New" or "Revised" License
139 stars 30 forks source link

Inaccurate Value generated in offchain code datum #93

Open arressaye opened 1 year ago

arressaye commented 1 year ago

I have datum defined in my contract as such

struct Datum {
    sender: PubKeyHash
    recipient: PubKeyHash
    exchange_for: Value
}

When I generate the datum in offchain code like so:

const heliosDatum = new EscrowProgram.types.Datum(
    helios.hexToBytes(helios.Address.fromBech32(sender).pubKeyHash.hex),
    helios.hexToBytes(helios.Address.fromBech32(recipient).pubKeyHash.hex),
    helios.Value.fromCbor(helios.hexToBytes(recipientValue))
  );

Note that recipientValue above is a CBOR hex string of a Value created from Cardano Serialization Library and not a Helios Value therefore it had to be converted.

The resulting Value of the datum contains only the non-ADA assets even though the recipientValue is the CBOR hex string of the full value I'm interested in, including ADA. Indeed if I run console.log(helios.Value.fromCbor(helios.hexToBytes(recipientValue)).lovelace.toString()); I do get the full value including ADA and native tokens printed to console. The ADA portion just doesn't get included in the datum somehow.

I've tested a few different scenarios and it seems like if recipientValue contained only ADA or only native tokens, the Datum will be correct. However if it included both ADA and native tokens, the Value in the Datum will ignore the ADA portion.

christianschmitz commented 1 year ago

I'm unable to replicate this using just the _toUplcData() method, so that part seems to be correct.

Do you have a more complete case with which I can replicate this?