This repository has been archived by the owner on May 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1487 from hyperledger/solts
Pull solts into Burrow
- Loading branch information
Showing
59 changed files
with
3,738 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
### Changed | ||
- [Execution] CallErrors no longer emit very long rather pointless (since there is no tooling to help interpret them currently) EVM call traces | ||
- [JS] Return byte arrays as Buffers from decode (only return fixed-width byteNN types as hex strings) | ||
- [JS] Changed Burrow interface and renamed Burrow client object to to Client (merging in features needed for solts support) | ||
|
||
### Fixed | ||
- [JS] Fixed RLP encoding extra leading zeros on uint64 (thanks Matthieu Vachon!) | ||
- [JS] Improved compatibility with legacy Solidity bytes types and padding conventions | ||
- [Events] Fixed Burrow event stream wrongly switching to streaming mode for block ranges that are available in state (when the latest block is an empty block - so not stored in state) | ||
|
||
### Added | ||
- [JS] Added Solidity-to-Typescript code generation support (merging in solts) - this provides helpers (build.ts, api.ts) to compile Solidity files into corresponding .abi.ts files that include types for functions, events, the ABI, and EVM bytecode, and includes bindings into Burrow JS to deploy and interact with contracts via Typescript/Javascript with strong static types | ||
- [JS] Improved interactions with events which can now be queried over any range and with strong types, see the listenerFor, reduceEvents, readEvents, and iterateEvents functions. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { EventFragment, Fragment, FunctionFragment, Interface } from 'ethers/lib/utils'; | ||
import { postDecodeResult, preEncodeResult, prefixedHexString, toBuffer } from './convert'; | ||
|
||
export type ContractCodec = { | ||
encodeDeploy(...args: unknown[]): Buffer; | ||
encodeFunctionData(signature: string, ...args: unknown[]): Buffer; | ||
decodeFunctionResult(signature: string, data: Uint8Array | undefined): any; | ||
decodeEventLog(signature: string, data: Uint8Array | undefined, topics?: Uint8Array[]): any; | ||
}; | ||
|
||
export function getContractCodec(iface: Interface): ContractCodec { | ||
return { | ||
encodeDeploy(...args: unknown[]): Buffer { | ||
const frag = iface.deploy; | ||
try { | ||
return toBuffer(iface.encodeDeploy(preEncodeResult(args, frag.inputs))); | ||
} catch (err) { | ||
throwErr(err, 'encode deploy', 'constructor', args, frag); | ||
} | ||
}, | ||
|
||
encodeFunctionData(signature: string, ...args: unknown[]): Buffer { | ||
let frag: FunctionFragment | undefined; | ||
try { | ||
frag = iface.getFunction(formatSignature(signature)); | ||
return toBuffer(iface.encodeFunctionData(frag, preEncodeResult(args, frag.inputs))); | ||
} catch (err) { | ||
throwErr(err, 'encode function data', signature, args, frag); | ||
} | ||
}, | ||
|
||
decodeFunctionResult(signature: string, data: Uint8Array = new Uint8Array()): any { | ||
let frag: FunctionFragment | undefined; | ||
try { | ||
frag = iface.getFunction(formatSignature(signature)); | ||
return postDecodeResult(iface.decodeFunctionResult(frag, data), frag.outputs); | ||
} catch (err) { | ||
throwErr(err, 'decode function result', signature, { data }, frag); | ||
} | ||
}, | ||
|
||
decodeEventLog(signature: string, data: Uint8Array = new Uint8Array(), topics?: Uint8Array[]): any { | ||
let frag: EventFragment | undefined; | ||
try { | ||
frag = iface.getEvent(formatSignature(signature)); | ||
return postDecodeResult( | ||
iface.decodeEventLog( | ||
frag, | ||
prefixedHexString(data), | ||
topics?.map((topic) => prefixedHexString(topic)), | ||
), | ||
frag.inputs, | ||
); | ||
} catch (err) { | ||
throwErr(err, 'decode event log', signature, { data, topics }, frag); | ||
} | ||
}, | ||
}; | ||
} | ||
|
||
function formatSignature(signature: string): string { | ||
return prefixedHexString(signature); | ||
} | ||
|
||
function throwErr( | ||
err: unknown, | ||
action: string, | ||
signature: string, | ||
args: Record<string, unknown> | unknown[], | ||
frag?: Fragment, | ||
): never { | ||
const name = frag ? frag.name : `member with signature '${signature}'`; | ||
const inputs = frag?.inputs ? ` (inputs: ${JSON.stringify(frag.inputs)})` : ''; | ||
throw new Error(`ContractCodec could not ${action} for ${name} with args ${JSON.stringify(args)}${inputs}: ${err}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.