@findeth/abi
Version:
A tiny Solidity ABI encoder and decoder
44 lines (38 loc) • 926 B
JavaScript
import { getParser, isDynamicParser, pack, unpack } from '../packer';
const TUPLE_REGEX = /^\((.*)\)$/;
export const getTupleElements = type => {
return type.slice(1, -1).split(',').map(type => type.trim());
};
export const tuple = {
isDynamic(type) {
const elements = getTupleElements(type);
return elements.some(element => {
const parser = getParser(element);
return isDynamicParser(parser, element);
});
},
isType(type) {
return TUPLE_REGEX.test(type);
},
encode({
type,
buffer,
value
}) {
const elements = getTupleElements(type);
return pack(elements, value, buffer);
},
decode({
type,
value,
skip
}) {
const elements = getTupleElements(type);
const length = elements.length * 32 - 32;
if (!isDynamicParser(this, type)) {
skip(length);
}
return unpack(elements, value);
}
};
//# sourceMappingURL=tuple.js.map