From e4dce0b1312f88b9cc496f2481f946d5dbfd5154 Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Sun, 11 Jun 2017 12:20:05 -0500 Subject: [PATCH] accounts/abi: added a parsing file and added some notes and building blocks. Might be slightly inaccurate, needs testing. Signed-off-by: RJ Catalano --- accounts/abi/parsing.go | 48 +++++++++++++++++++++++++++++++++++++++ accounts/abi/type.go | 2 +- accounts/abi/unpacking.go | 1 + 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 accounts/abi/parsing.go diff --git a/accounts/abi/parsing.go b/accounts/abi/parsing.go new file mode 100644 index 0000000000..66911154c6 --- /dev/null +++ b/accounts/abi/parsing.go @@ -0,0 +1,48 @@ +// Copyright 2016 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +package abi + +import ( + "encoding/binary" + "fmt" +) + +// separates byte slice into a slice of 32 byte slices. +func chunkBytes(output []byte) (chunked [][32]byte) { + for i, j := 0, 0; i < len(output); i, j = i+32, j+1 { + chunked[j] = output[i : i+32] + } + return +} + +// check to see that the bytes are correctly formatted to 32 byte slices +func bytesAreProper(output []byte) error { + if len(output)%32 != 0 { + return fmt.Errorf("abi: improper length of byte slice detected in output.") + } + return nil +} + +// interprets a 32 byte slice as an offset and then determines which indice to look to decode the type. +func offsetPointsTo(offset [32]byte) uint { + return uint(binary.BigEndian.Uint64(offset[24:32])) / 32 +} + +// gives the starting and ending indices in the chunked byte slice for the values of an array +func parseSliceSize(size [32]byte, currentLength uint) (start uint, end uint) { + return currentLength + 1, currentLength + uint(binary.BigEndian.Uint64(size[24:32])/32) +} diff --git a/accounts/abi/type.go b/accounts/abi/type.go index f2832aef56..a9b26e0cae 100644 --- a/accounts/abi/type.go +++ b/accounts/abi/type.go @@ -33,7 +33,7 @@ const ( FixedBytesTy BytesTy HashTy - FixedpointTy + FixedPointTy FunctionTy ) diff --git a/accounts/abi/unpacking.go b/accounts/abi/unpacking.go index a617b48199..d2c7b0802f 100644 --- a/accounts/abi/unpacking.go +++ b/accounts/abi/unpacking.go @@ -139,6 +139,7 @@ func readInteger(kind reflect.Kind, b []byte) interface{} { } } +// todo: this is inefficient for a bool, just look at the last cell, save yourself 32 iterations func allZero(b []byte) bool { for _, byte := range b { if byte != 0 {