Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Improve request typing
Browse files Browse the repository at this point in the history
  • Loading branch information
haltman-at committed Apr 10, 2019
1 parent 4da769c commit 65967b4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
4 changes: 3 additions & 1 deletion packages/truffle-debugger/lib/data/sagas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ export function* decode(definition, ref) {
while (!result.done) {
let request = result.value;
let response;
switch (request.requesting) {
switch (request.type) {
//yes, this is a little silly right now
case "storage":
//the debugger supplies all storage it knows at the beginning.
//any storage it does not know is presumed to be zero.
response = ZERO_WORD;
break;
default:
debug("unrecognized request type!");
}
result = decoder.next(response);
}
Expand Down
21 changes: 10 additions & 11 deletions packages/truffle-decoder/lib/interface/contract-decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as storage from "../allocate/storage";
import { StoragePointer, isStoragePointer } from "../types/pointer";
import { StorageAllocations, StorageMemberAllocations, StorageMemberAllocation } from "../types/allocation";
import { Slot, isWordsLength } from "../types/storage";
import { DecoderRequest } from "../types/request";
import { DecoderRequest, isStorageRequest } from "../types/request";
import decode from "../decode";
import { Definition as DefinitionUtils, EVM, AstDefinition, AstReferences } from "truffle-decode-utils";
import { BlockType, Transaction } from "web3/eth/types";
Expand Down Expand Up @@ -178,17 +178,16 @@ export default class TruffleContractDecoder extends AsyncEventEmitter {
while(!result.done) {
let request = <DecoderRequest>(result.value);
let response: any
switch(request.requesting) {
//yes, this is a little silly right now
case "storage":
response = DecodeUtils.Conversion.toBytes(
await this.web3.eth.getStorageAt(
this.contractAddress,
request.slot,
block),
DecodeUtils.EVM.WORD_SIZE);
break;
if(isStorageRequest(request)) {
response = DecodeUtils.Conversion.toBytes(
await this.web3.eth.getStorageAt(
this.contractAddress,
request.slot,
block),
DecodeUtils.EVM.WORD_SIZE);
}
//note: one of the above conditionals *must* be true by the type system.
//yes, right now there's only one such conditional.
result = decoder.next(response);
}
//at this point, result.value holds the final value
Expand Down
2 changes: 1 addition & 1 deletion packages/truffle-decoder/lib/read/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function* read(storage: WordMapping, slot: Slot): IterableIterator<Uint8A
//say 0)
if(word === undefined) {
word = yield {
requesting: "storage",
type: "storage",
slot: address
};
}
Expand Down
12 changes: 9 additions & 3 deletions packages/truffle-decoder/lib/types/request.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import BN from "bn.js";

export interface DecoderRequest {
requesting: "storage";
slot?: BN; //will add more fields as needed
export type DecoderRequest = StorageRequest; //will add more later

export interface StorageRequest {
type: "storage";
slot: BN; //will add more fields as needed
}

export function isStorageRequest(request: DecoderRequest): request is StorageRequest {
return request.type === "storage";
}

0 comments on commit 65967b4

Please sign in to comment.