From 17af9f812f7e69af1afadb3a3917fffd6e5e49f1 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Wed, 23 Jun 2021 23:40:50 -0400 Subject: [PATCH] docs: fixed typos and updated examples --- docs.wrm/api/utils/abi/fragments.wrm | 11 +++-- docs.wrm/api/utils/abi/interface.wrm | 62 ++++++++++++++++++++++++++-- docs.wrm/config.js | 10 ++++- 3 files changed, 74 insertions(+), 9 deletions(-) diff --git a/docs.wrm/api/utils/abi/fragments.wrm b/docs.wrm/api/utils/abi/fragments.wrm index 795b55ece..85218bc83 100644 --- a/docs.wrm/api/utils/abi/fragments.wrm +++ b/docs.wrm/api/utils/abi/fragments.wrm @@ -52,21 +52,21 @@ _heading: Output Formats @ @SRC string +_property: ethers.utils.FormatTypes.full => string This is a full human-readable string, including all parameter names, any optional modifiers (e.g. ``indexed``, ``public``, etc) and white-space to aid in human readability. -_property: ethers.utils.FragmentTypes.minimal => string +_property: ethers.utils.FormatTypes.minimal => string This is similar to ``full``, except with no unnecessary whitespace or parameter names. This is useful for storing a minimal string which can still fully reconstruct the original Fragment using [Fragment . from](Fragment-from). -_property: ethers.utils.FragmentTypes.json => string +_property: ethers.utils.FormatTypes.json => string This returns a JavaScript Object which is safe to call ``JSON.stringify`` on to create a JSON string. -_property: ethers.utils.FragmentTypes.sighash => string +_property: ethers.utils.FormatTypes.sighash => string This is a minimal output format, which is used by Solidity when computing a signature hash or an event topic hash. @@ -74,6 +74,9 @@ _warning: Note The ``sighash`` format is **insufficient** to re-create the original [[Fragment]], since it discards modifiers such as indexed, anonymous, stateMutability, etc. +It is only useful for computing the selector for a Fragment, and cannot +be used to format an Interface. + _subsection: Fragment @ @SRC An ABI is a collection of **Fragments**, where each fragment specifies: diff --git a/docs.wrm/api/utils/abi/interface.wrm b/docs.wrm/api/utils/abi/interface.wrm index ea841670a..c163b5399 100644 --- a/docs.wrm/api/utils/abi/interface.wrm +++ b/docs.wrm/api/utils/abi/interface.wrm @@ -33,12 +33,28 @@ _code: Creating an Interface instance @lang // This interface is used for the below examples const iface = new Interface([ + // Constructor "constructor(string symbol, string name)", + + // State mutating method "function transferFrom(address from, address to, uint amount)", - "function balanceOf(address owner) view returns (uint)", + + // State mutating method, which is payable "function mint(uint amount) payable", + + // Constant method (i.e. "view" or "pure") + "function balanceOf(address owner) view returns (uint)", + + // An Event "event Transfer(address indexed from, address indexed to, uint256 amount)", - "error AccountLocked(address owner, uint256 balance)" + + // A Custom Solidity Error + "error AccountLocked(address owner, uint256 balance)", + + // Examples with structured types + "function addUser(tuple(string name, address addr) user) returns (uint id)", + "function addUsers(tuple(string name, address addr)[] user) returns (uint[] id)", + "function getUser(uint id) view returns (tuple(string name, address addr) user)" ]); //_hide: _page.iface = iface; @@ -263,6 +279,25 @@ iface.encodeFunctionData("transferFrom", [ ]) //_log: +// Encoding structured data (using positional Array) +user = [ + "Richard Moore", + "0x8ba1f109551bD432803012645Ac136ddd64DBA72" +]; +//_result: +iface.encodeFunctionData("addUser", [ user ]); +//_log: + +// Encoding structured data, using objects. Only available +// if paramters are named. +user = { + name: "Richard Moore", + addr: "0x8ba1f109551bD432803012645Ac136ddd64DBA72" +}; +//_result: +iface.encodeFunctionData("addUser", [ user ]); +//_log: + _property: interface.encodeFunctionResult(fragment [ , values ]) => string<[[DataHexString]]> @SRC Returns the encoded result, which would normally be the response from a call for //fragment// (see [[Interface--specifying-fragments]]) for the given //values//. @@ -342,18 +377,37 @@ _code: @lang //_hide: const iface = _page.iface; // Decoding result data (e.g. from an eth_call) -const resultData = "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000"; +resultData = "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000"; //_result: iface.decodeFunctionResult("balanceOf", resultData) //_log: // Decoding result data which was caused by a revert // Throws a CALL_EXCEPTION, with extra details -const errorData = "0xf7c3865a0000000000000000000000008ba1f109551bd432803012645ac136ddd64dba720000000000000000000000000000000000000000000000000de0b6b3a7640000"; +errorData = "0xf7c3865a0000000000000000000000008ba1f109551bd432803012645ac136ddd64dba720000000000000000000000000000000000000000000000000de0b6b3a7640000"; //_throws: iface.decodeFunctionResult("balanceOf", errorData) //_log: +// Decoding structured data returns a Result object, which +// will include all values positionally and if the ABI +// included names, values will additionally be available +// by their name. +resultData = "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000400000000000000000000000008ba1f109551bd432803012645ac136ddd64dba72000000000000000000000000000000000000000000000000000000000000000d52696368617264204d6f6f726500000000000000000000000000000000000000"; +//_result: +result = iface.decodeFunctionResult("getUser", resultData); +//_log: + +// Access positionally: +// The 0th output parameter, the 0th proerty of the structure +//_result: +result[0][0]; +//_log: + +// Access by name: (only avilable because parameters were named) +//_result: +result.user.name +//_log: _subsection: Parsing @ diff --git a/docs.wrm/config.js b/docs.wrm/config.js index e50fe57ba..254ed343e 100644 --- a/docs.wrm/config.js +++ b/docs.wrm/config.js @@ -179,12 +179,20 @@ function codeContextify(context) { sorted: true, }); } + + context._startup = function() { + console.log("Startup"); + } + + context._shutdown = function() { + console.log("Shutdown"); + } } module.exports = { title: "ethers", - subtitle: "v5.2", + subtitle: "v5.3", description: "Documentation for ethers, a complete, tiny and simple Ethereum library.", logo: "logo.svg",