Skip to content

Add all missing ewasm methods #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 76 additions & 8 deletions assembly/lib/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,90 @@

import "allocator/arena";

export declare function useGas(amount: i64): void;

export declare function getGasLeft(): i64;

export declare function getAddress(resultOffset: usize): void;

export declare function getBalance(addressOffset: usize, resultOffset: usize): void;

export declare function getBlockCoinbase(resultOffset: usize): void;

export declare function getBlockDifficulty(resultOffset: usize): void;

export declare function getBlockGasLimit(): i64;

export declare function getBlockHash(number: i64, resultOffset: usize): void;

export declare function getBlockNumber(): i64;

export declare function getBlockTimestamp(): i64;

export declare function getTxGasPrice(valueOffset: usize): void;

export declare function getTxOrigin(resultOffset: usize): void;

export declare function log(dataOffset: usize, length: i32, numberOfTopics: i32, topic1: i32, topic2: i32, topic3: i32, topic4: i32): void;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export declare function log(dataOffset: usize, length: i32, numberOfTopics: i32, topic1: usize, topic2: usize, topic3: usize, topic4: usize): void;


export declare function call(gas: i64, addressOffset: usize, valueOffset: usize, dataOffset: usize, dataLength: i32): i32;

export declare function callCode(gas: i64, addressOffset: usize, valueOffset: usize, dataOffset: usize, dataLength: i32): i32;

export declare function callDelegate(gas: i64, addressOffset: usize, dataOffset: usize, dataLength: i32): i32;

export declare function callStatic(gas: i64, addressOffset: usize, dataOffset: usize, dataLength: i32): i32;

export declare function create(valueOffset: usize, dataOffset: usize, length: i32, resultOffset: usize): i32;

export declare function returnDataCopy(resultOffset: usize, dataOffset: usize, length: i32): void;

export declare function getReturnDataSize(): i32;

@external("return")
export declare function finish(dataOffset: i32, length: i32): void;
export declare function finish(dataOffset: usize, length: i32): void;

export declare function revert(dataOffset: i32, length: i32): void;
export declare function revert(dataOffset: usize, length: i32): void;

export declare function callDataCopy(resultOffset: i32, dataOffset: i32, length: i32): void;
export declare function callDataCopy(resultOffset: usize, dataOffset: usize, length: i32): void;

export declare function getCallDataSize(): i32;

export declare function getCaller(dataOffset: i32): void;
export declare function getCaller(resultOffset: usize): void;

export declare function getCallValue(resultOffset: usize): void;

export declare function codeCopy(resultOffset: usize, codeOffset: usize, length: i32): void;

export declare function getCodeSize(): i32;

export declare function externalCodeCopy(addressOffset: usize, resultOffset: usize, codeOffset: usize, lengh: i32): void;

export declare function storageStore(pathOffset: i32, valueOffset: i32): void;
export declare function getExternalCodeSize(addressOffset: usize): i32;

export declare function storageLoad(pathOffset: i32, resultOffset: i32): void;
export declare function storageStore(pathOffset: usize, valueOffset: usize): void;

export declare function storageLoad(pathOffset: usize, resultOffset: usize): void;

export declare function selfDestruct(addressOffset: usize): void;

@external("debug", "print32")
export declare function print32(value: i32): void;
Copy link

@MaxGraey MaxGraey Jun 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just note

instead repeated @external("debug", "...") you can simplified and grouped this to:

export declare namespace debug {
  function print32(value: i32): void;
  function print64(value: i64): void;
  function printMem(dataOffset: usize, length: i32): void;
  function printMemHex(dataOffset: usize, length: i32): void;
  ...
}

this behave and generate exactly the same as "atomic" external decorator.

But required call like this: debug.print32(0x80). So if this not what you want leave this as is

Copy link
Collaborator

@dcodeIO dcodeIO Jun 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option could be to move all of the debug functions to a file named debug.ts, and rexport its elements from lib/ethereum.ts. By default, the file name without extension is used as the import's module name. If debug.ts resides within lib/, it's not necessary to re-export its elements because standard library exports become globals by default.


@external("debug", "print64")
export declare function print64(value: i64): void;

@external("debug", "printMem")
export declare function printMem(dataOffset: usize, length: i32): void;

@external("debug", "printMemHex")
export declare function printMemHex(dataOffset: i32, length: i32): void;
export declare function printMemHex(dataOffset: usize, length: i32): void;

@external("debug", "printStorage")
export declare function printStorage(pathOffset: usize): void;

@external("debug", "printStorageHex")
export declare function printStorageHex(pathOffset: usize): void;

// TODO: need to implement a nice wrapper over the native functions which use native types and handles the memory.
@external("debug", "evmTrace")
export declare function evmTrace(pc: i32, opcode: i32, cost: i32, sp: i32): void;