accounts/abi: added a parsing file and added some notes and building blocks. Might be slightly inaccurate, needs testing.

Signed-off-by: RJ Catalano <rj@monax.io>
This commit is contained in:
RJ Catalano 2017-06-11 12:20:05 -05:00
parent 2615dc3887
commit e4dce0b131
No known key found for this signature in database
GPG key ID: D4AB109D9B5D6386
3 changed files with 50 additions and 1 deletions

48
accounts/abi/parsing.go Normal file
View file

@ -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 <http://www.gnu.org/licenses/>.
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)
}

View file

@ -33,7 +33,7 @@ const (
FixedBytesTy
BytesTy
HashTy
FixedpointTy
FixedPointTy
FunctionTy
)

View file

@ -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 {