Got the crazy ABI working
This commit is contained in:
@@ -89,6 +89,10 @@ class Memblock {
|
|||||||
public getSection(): CalldataSection {
|
public getSection(): CalldataSection {
|
||||||
return this.location.calldataSection;
|
return this.location.calldataSection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getName(): string {
|
||||||
|
return this.dataType.getDataItem().name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BindList {
|
interface BindList {
|
||||||
@@ -120,13 +124,18 @@ export class Calldata {
|
|||||||
throw `Rebind on ${dataType.getId()}`;
|
throw `Rebind on ${dataType.getId()}`;
|
||||||
}
|
}
|
||||||
const memblock = new Memblock(dataType);
|
const memblock = new Memblock(dataType);
|
||||||
switch (section) {
|
|
||||||
case CalldataSection.PARAMS:
|
|
||||||
this.params.push(memblock);
|
this.params.push(memblock);
|
||||||
memblock.assignLocation(section, new BigNumber(0), this.currentParamOffset);
|
memblock.assignLocation(section, new BigNumber(0), this.currentParamOffset);
|
||||||
|
|
||||||
console.log(`Binding ${dataType.getDataItem().name} to PARAMS at ${this.currentParamOffset}`);
|
console.log(`Binding ${dataType.getDataItem().name} to PARAMS at ${this.currentParamOffset}`);
|
||||||
this.currentParamOffset = this.currentParamOffset.plus(memblock.getSize());
|
this.currentParamOffset = this.currentParamOffset.plus(memblock.getSize());
|
||||||
|
console.log("CURRENT PARAM OFFSET -------- 0x", this.currentParamOffset.toString(16));
|
||||||
|
|
||||||
|
/*
|
||||||
|
switch (section) {
|
||||||
|
case CalldataSection.PARAMS:
|
||||||
|
;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CalldataSection.DATA:
|
case CalldataSection.DATA:
|
||||||
@@ -143,7 +152,7 @@ export class Calldata {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
throw `Unrecognized calldata section: ${section}`;
|
throw `Unrecognized calldata section: ${section}`;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
this.bindList[dataType.getId()] = memblock;
|
this.bindList[dataType.getId()] = memblock;
|
||||||
dataType.rbind(memblock);
|
dataType.rbind(memblock);
|
||||||
@@ -160,6 +169,26 @@ export class Calldata {
|
|||||||
|
|
||||||
return hexValue;
|
return hexValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public printAnnotated() {
|
||||||
|
let hexValue = `${this.selector}`;
|
||||||
|
console.log(hexValue);
|
||||||
|
let offset = new BigNumber(0);
|
||||||
|
_.each(this.params, (memblock: Memblock) => {
|
||||||
|
const offsetStr = `0x${offset.toString(16)}`;
|
||||||
|
const hexValue = memblock.get();
|
||||||
|
const annotation = memblock.getName();
|
||||||
|
|
||||||
|
console.log(`${offsetStr} ${hexValue} ${annotation}`);
|
||||||
|
});
|
||||||
|
_.each(this.data, (memblock: Memblock) => {
|
||||||
|
const offsetStr = `0x${offset.toString(16)}`;
|
||||||
|
const hexValue = memblock.get();
|
||||||
|
const annotation = memblock.getName();
|
||||||
|
|
||||||
|
console.log(`${offsetStr} ${hexValue} ${annotation}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class DataType {
|
export abstract class DataType {
|
||||||
@@ -793,7 +822,7 @@ export class Tuple extends DynamicDataType {
|
|||||||
name: `${this.getDataItem().name}.${dataItem.name}`,
|
name: `${this.getDataItem().name}.${dataItem.name}`,
|
||||||
} as DataItem;
|
} as DataItem;
|
||||||
const child = DataTypeFactory.create(childDataItem, this);
|
const child = DataTypeFactory.create(childDataItem, this);
|
||||||
this.childMap[dataItem.name] = this.children.length;
|
this.childMap[dataItem.name] = this.members.length;
|
||||||
|
|
||||||
if (child instanceof Pointer) {
|
if (child instanceof Pointer) {
|
||||||
this.children.push(child.getChildren()[0]);
|
this.children.push(child.getChildren()[0]);
|
||||||
@@ -1065,6 +1094,7 @@ export class Method extends DataType {
|
|||||||
public encode(args: any[]): string {
|
public encode(args: any[]): string {
|
||||||
this.assignValue(args);
|
this.assignValue(args);
|
||||||
const calldata = new Calldata(this.selector, this.params.length);
|
const calldata = new Calldata(this.selector, this.params.length);
|
||||||
|
calldata.printAnnotated();
|
||||||
this.bind(calldata, CalldataSection.PARAMS);
|
this.bind(calldata, CalldataSection.PARAMS);
|
||||||
|
|
||||||
return calldata.getHexValue();
|
return calldata.getHexValue();
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ describe.only('ABI Encoder', () => {
|
|||||||
describe.only('Just a Greg, Eh', () => {
|
describe.only('Just a Greg, Eh', () => {
|
||||||
|
|
||||||
|
|
||||||
it.skip('Crazy ABI', async () => {
|
it('Crazy ABI', async () => {
|
||||||
const method = new AbiEncoder.Method(AbiSamples.crazyAbi);
|
const method = new AbiEncoder.Method(AbiSamples.crazyAbi);
|
||||||
console.log(method.getSignature());
|
console.log(method.getSignature());
|
||||||
|
|
||||||
@@ -211,7 +211,7 @@ describe.only('ABI Encoder', () => {
|
|||||||
expect(calldata).to.be.equal(expectedCalldata);
|
expect(calldata).to.be.equal(expectedCalldata);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.only('Static Tuple', async () => {
|
it('Static Tuple', async () => {
|
||||||
// This is dynamic because it has dynamic members
|
// This is dynamic because it has dynamic members
|
||||||
const method = new AbiEncoder.Method(AbiSamples.staticTupleAbi);
|
const method = new AbiEncoder.Method(AbiSamples.staticTupleAbi);
|
||||||
const calldata = method.encode([[new BigNumber(5), new BigNumber(10), new BigNumber(15), false]]);
|
const calldata = method.encode([[new BigNumber(5), new BigNumber(10), new BigNumber(15), false]]);
|
||||||
|
|||||||
Reference in New Issue
Block a user