How to use the @truffle/codec.Conversion 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 / debugger / lib / evm / selectors / index.js View on Github external
createValue: createLeaf(["./isCreate", state], (isCreate, { stack }) => {
        if (!isCreate) {
          return null;
        }

        //creates have the value as the first argument
        let value = stack[stack.length - 1];
        return Codec.Conversion.toBN(value);
      }),
github trufflesuite / truffle / packages / debugger / lib / data / sagas / index.js View on Github external
function* decodeMappingKeySaga(indexDefinition, keyDefinition) {
  //something of a HACK -- cleans any out-of-range booleans
  //resulting from the main mapping key decoding loop
  let indexValue = yield* decodeMappingKeyCore(indexDefinition, keyDefinition);
  return indexValue ? Codec.Conversion.cleanBool(indexValue) : indexValue;
}
github trufflesuite / truffle / packages / debugger / lib / data / reducers.js View on Github external
//table here are supposed to preserve path information, we'll be
      //replacing a fairly bare-bones Slot object with one with a full path.

      //we do NOT want to distinguish between types with and without "_ptr" on
      //the end here! (or _slice)
      debug("typeIdentifier %s", typeIdentifier);
      typeIdentifier = Codec.Ast.Utils.regularizeTypeIdentifier(typeIdentifier);
      parentType = Codec.Ast.Utils.regularizeTypeIdentifier(parentType);

      debug("slot %o", slot);
      let hexSlotAddress = Codec.Conversion.toHexString(
        Codec.Storage.Utils.slotAddress(slot),
        Codec.Evm.Utils.WORD_SIZE
      );
      let parentAddress = slot.path
        ? Codec.Conversion.toHexString(
            Codec.Storage.Utils.slotAddress(slot.path),
            Codec.Evm.Utils.WORD_SIZE
          )
        : undefined;

      //this is going to be messy and procedural, sorry.  but let's start with
      //the easy stuff: create the new address if needed, clone if not
      let newState = {
        ...state,
        byAddress: {
          ...state.byAddress,
          [address]: {
            byType: {
              ...(state.byAddress[address] || { byType: {} }).byType
            }
          }
github trufflesuite / truffle / packages / debugger / lib / data / sagas / index.js View on Github external
baseNode,
  mappedPaths,
  currentAssignments,
  currentDepth
) {
  let fullId = stableKeccak256({
    astId: baseNode.id,
    stackframe: currentDepth
  });
  debug("astId: %d", baseNode.id);
  debug("stackframe: %d", currentDepth);
  debug("fullId: %s", fullId);
  debug("currentAssignments: %O", currentAssignments);
  //base expression is an expression, and so has a literal assigned to
  //it
  let offset = Codec.Conversion.toBN(
    currentAssignments.byId[fullId].ref.literal
  );
  return { offset };
}
github trufflesuite / truffle / packages / debugger / lib / data / reducers.js View on Github external
//found as the slotAddress of the slot's path object, if it exists -- if
      //it doesn't then we conclude that no the parent does not have a spot in
      //the table).  If the parent has a slot in the table already, then we
      //alter the child slot by replacing its path with the parent slot.  This
      //will keep the slotAddress the same, but since the versions kept in the
      //table here are supposed to preserve path information, we'll be
      //replacing a fairly bare-bones Slot object with one with a full path.

      //we do NOT want to distinguish between types with and without "_ptr" on
      //the end here! (or _slice)
      debug("typeIdentifier %s", typeIdentifier);
      typeIdentifier = Codec.Ast.Utils.regularizeTypeIdentifier(typeIdentifier);
      parentType = Codec.Ast.Utils.regularizeTypeIdentifier(parentType);

      debug("slot %o", slot);
      let hexSlotAddress = Codec.Conversion.toHexString(
        Codec.Storage.Utils.slotAddress(slot),
        Codec.Evm.Utils.WORD_SIZE
      );
      let parentAddress = slot.path
        ? Codec.Conversion.toHexString(
            Codec.Storage.Utils.slotAddress(slot.path),
            Codec.Evm.Utils.WORD_SIZE
          )
        : undefined;

      //this is going to be messy and procedural, sorry.  but let's start with
      //the easy stuff: create the new address if needed, clone if not
      let newState = {
        ...state,
        byAddress: {
          ...state.byAddress,