How to use the @truffle/codec/utils.Definition function in @truffle/codec

To help you get started, we’ve selected a few @truffle/codec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github trufflesuite / truffle / packages / codec / lib / read / constant.ts View on Github external
export function readDefinition(definition: AstDefinition): Uint8Array {

  debug("definition %o", definition);

  switch(CodecUtils.Definition.typeClass(definition))
  {
    case "rational":
      let numericalValue: BN = CodecUtils.Definition.rationalValue(definition);
      return CodecUtils.Conversion.toBytes(numericalValue, CodecUtils.EVM.WORD_SIZE);
      //you may be wondering, why do we not just use definition.value here,
      //like we do below? answer: because if this isn't a literal, that may not
      //exist
    case "stringliteral":
      return CodecUtils.Conversion.toBytes(definition.hexValue);
    default:
      //unfortunately, other types of constants are just too complicated to
      //handle right now.  sorry.
      debug("unsupported constant definition type");
      throw new DecodingError(
        {
          kind: "UnsupportedConstantError",
          definition
        }
      );
github trufflesuite / truffle / packages / codec / lib / read / constant.ts View on Github external
export function readDefinition(definition: AstDefinition): Uint8Array {

  debug("definition %o", definition);

  switch(CodecUtils.Definition.typeClass(definition))
  {
    case "rational":
      let numericalValue: BN = CodecUtils.Definition.rationalValue(definition);
      return CodecUtils.Conversion.toBytes(numericalValue, CodecUtils.EVM.WORD_SIZE);
      //you may be wondering, why do we not just use definition.value here,
      //like we do below? answer: because if this isn't a literal, that may not
      //exist
    case "stringliteral":
      return CodecUtils.Conversion.toBytes(definition.hexValue);
    default:
      //unfortunately, other types of constants are just too complicated to
      //handle right now.  sorry.
      debug("unsupported constant definition type");
      throw new DecodingError(
        {
          kind: "UnsupportedConstantError",