Skip to content
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

Godwoken Web3 RPC兼容讨论 #6

Open
bitrocks opened this issue Mar 17, 2021 · 1 comment
Open

Godwoken Web3 RPC兼容讨论 #6

bitrocks opened this issue Mar 17, 2021 · 1 comment

Comments

@bitrocks
Copy link
Owner

bitrocks commented Mar 17, 2021

接口进展:https://docs.google.com/spreadsheets/d/1I6n8siwklm3lKz7PO57B0Hf7v9P_FStgmPip30Eyqlc/edit#gid=0

eth_syncing

  1. 功能:查询节点同步信息

  2. 参数:null

  3. 返回值

    false:不在同步
    {
       startBlock: import启动时的高度
       currentBlock: 当前块高,eth_blockNumber一样
       highestBlock: 估计的最高块
    }
    
  4. API server

    1. 读取indexer同步的信息
    2. 直接读取Godwoken接口
  5. Godwoken提供接口

    lastSynced(): Promise<HexString> 只提供currentBlock信息
    syncing(): Promise<SyncStatus>
    

eth_gasPrice

  1. 功能:查询gasPrice

  2. 参数:null

  3. 返回值

    gasPrice: hex num in wei
    
  4. API server

    1. 参考geth,通过过去N个块的gasPrice中位数
    2. 参考gasNow,读取txpool里面pendingTransaction的gasPrice
  5. Godwoken提供接口

    gasPrice(): Promise<HexNumber>;
    

eth_getBalance

  1. 功能:查询地址的原生代币的额度

  2. 参数

    address: hex string,
    blockParameter: hex num, or {"latest","earliest", "pending"},默认latest,指定块高需要archive mode支持
    
  3. 返回值

    balance: hex num in wei
    
  4. API server

    将ethAddress转换成accountId: address -> script -> scriptHash -> accountId;

    根据accountId和sudtId读取balance;

  5. Godwoken提供接口

    getAccountIdByScriptHash(scriptHash): Promise<number>
    
    getBalance(accountId, sudtId, [blockParameter]): Promise<HexNumer>
    

eth_getStorageAt

  1. 功能:查询合约的状态存储

  2. 参数

    address: hex string,
    storagePosition: hex string,
    blockParameter: hex num, or {"latest","earliest", "pending"},默认latest,指定块高需要archive mode支持
    
  3. 返回值

    storageValue: hex string
    
  4. API server

    将ethAddress转换成accountId: address -> script -> scriptHash -> accountId;

    storagePosition计算规则:

    1. ethereum中,分为基础类型/map类型,计算key
    2. godwoken中,状态的rawKey计算
  5. Godwoken提供接口

    getAccountIdByScriptHash(scriptHash): Promise<number>
    
    getStorageAt(accountId, rawKey, [blockParameter]): Promise<Hash>
    

eth_getTransactionCount

  1. 功能:查询地址发送出的交易数量(nonce)

  2. 参数

    address: hex string,
    blockParameter: hex num, or {"latest","earliest", "pending"},默认latest,指定块高需要archive mode支持
    
  3. 返回值

    count: hex num
    
  4. API server

    将ethAddress转换成accountId: address -> script -> scriptHash -> accountId;

  5. Godwoken提供接口

    getAccountIdByScriptHash(scriptHash): Promise<number>
    
    getTransactionCount(accountId, [blockParameter]): Promise<number>
    

eth_getCode

  1. 功能:读取合约代码

  2. 参数

    address: hex string,
    blockParameter: hex num, or {"latest","earliest", "pending"},默认latest,指定块高需要archive mode支持
    
  3. 返回值

    code: hex string, EOA账户返回"0x"
    
  4. API server

    将ethAddress转换成accountId: address -> script -> scriptHash -> accountId;

  5. Godwoken提供接口

    getAccountIdByScriptHash(scriptHash): Promise<number>;
    
    getCode(accountId, [blockParameter]): Promise<HexString>
    

eth_call

  1. 功能:节点执行message call,交易不上链

  2. 参数

    from: hex string,
    to: hex string,
    gas: hex number,
    gasPrice: hex number,
    value: hex number,
    data: hex string,
    blockParameter: hex num, or {"latest","earliest", "pending"},默认latest,指定块高需要archive mode支持
    
  3. 返回值

    returnValue: hex string
    errorMsg: REVERT
    
  4. API server

    构造RawL2Transaction;

    从RunResult中提取returnValue;

  5. Godwoken提供接口

    call(RawL2Transaction): Promise<RunResult>
    

eth_estimateGas

  1. 功能:节点执行message call,估计花费的gas

  2. 参数

    from: hex string,
    to: hex string,
    gas: hex number,
    gasPrice: hex number,
    value: hex number,
    data: hex string,
    blockParameter: hex num, or {"latest","earliest", "pending"},默认latest,指定块高需要archive mode支持
    
  3. 返回值

    returnValue: hex string
    errorMsg: REVERT
    
  4. API server

    构造RawL2Transaction;

    从RunResult中提取estimateGas;

  5. Godwoken提供接口

    call(RawL2Transaction): Promise<RunResult>
    

Filter过滤器

eth_newBlockFilter

eth_newPendingTransactionFilter

WSS subscribe

subscribe

unsubscribe

@bitrocks
Copy link
Owner Author

#27

classicalliu pushed a commit to classicalliu/godwoken-web3-old that referenced this issue Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant