Coder Social home page Coder Social logo

aiken-stringify's Introduction

Aiken Stringify

Converting anything to a String

Motivation

Debugging in Aiken is not a happy part, because the only way to log a value is converting it to a String and then passing it to a trace. For example:

trace @"here" // directly from a string
trace string.from_int(my_int) // convert to string
trace cbor.diagnostic(any_value) // diagnostic the value

The cbor.diagnostic helper works well, but not really readable for many cases, specially with encoded data. So this is why this library was born. For example, let's debug an output:

  • With cbor.diagnostic:
let input = Input {
  output_reference: OutputReference(TransactionId("tx_0"), 0),
  output: Output {
    value: value.from_lovelace(111_000_000) |> value.add("pid", "name", 1),
    address: Address {
      payment_credential: ScriptCredential("script_hash"),
      stake_credential: None,
    },
    datum: NoDatum,
    reference_script: None,
  },
}
trace cbor.diagnostic(input)

We get:

121([_ 121([_ 121([_ h'74785F30']), 0]), 121([_ 121([_ 122([_ h'7363726970745F68617368']), 122([])]), {_ h'': {_ h'': 111000000 }, h'706964': {_ h'6E616D65': 1 } }, 121([]), 122([])])])
  • With stringify.input
// ...
trace stringify.input(input)

We get:

Input {
     output_reference: OutputReference(TransactionId('tx_0'), 0),
     output: Output {
       address: Address {
         payment_credential: ScriptCredential('script_hash')
         stake_credential: None
       },
       value: Value ([
           h'',
           h'',
           111000000
       ],[
           h'706964', # pid
           h'6E616D65', # name
           1
       ]),
       datum: NoDatum
    }
}

Usage

More handy when wrapped by a custom logger. For example:

fn log(self: a, serializer: fn(a) -> String) {
  trace serializer(self)
  self
}

So we can attach it to anywhere like this:

let input = Input {
  output_reference: OutputReference(TransactionId("tx_0"), 0),
  output: Output {
    value: value.from_lovelace(111_000_000) |> value.add("pid", "name", 1),
    address: Address {
      payment_credential: ScriptCredential("script_hash"),
      stake_credential: None,
    },
    datum: NoDatum,
    reference_script: None,
  },
}
+ |> log(stringify.input)

You can use defined loggers inside the debug module

Supported serializers

  • input
  • output
  • credential
  • address
  • value
  • minted_value
  • data
  • out_ref
  • tx
  • redeemers
  • bytearray

License

MIT

aiken-stringify's People

Contributors

t0anhh avatar

Watchers

Nguyễn Tuấn Anh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.