-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement encode/decode 1inch extension (#75)
* Add encode/decode 1inch extension * Fix lint * Add interaction * Implement interaction * Implement encode/decode auction details * Implement encode/decode settlement post interaction data * Add fusion extension decode * Convert auction details to use primitive types * Convert settlement post interaction data to use primitive types * Replace extension fields by byte arrays * Convert string to []byte * Sink some packages * Shorten function encode * Make lint happy * Remove trim0x function * Remove ZX global constant * Use math.PaddedBigBytes instead * Check data length before get it from bytes * Add next function at decode package * Implement bytes iterator * Remove completely zx * Remove unused assert in test * Add check less than 0 when create auction details * Remove big package in bytes iterator * Add assert for some tests * Return offset is a common.Hash
- Loading branch information
Showing
16 changed files
with
1,130 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package decode | ||
|
||
import ( | ||
"encoding/binary" | ||
"errors" | ||
) | ||
|
||
var ErrOutOfData = errors.New("out of data") | ||
|
||
type BytesIterator struct { | ||
data []byte | ||
} | ||
|
||
func NewBytesIterator(data []byte) *BytesIterator { | ||
return &BytesIterator{data: data} | ||
} | ||
|
||
func (bi *BytesIterator) RemainingData() []byte { | ||
return bi.data | ||
} | ||
|
||
func (bi *BytesIterator) HasMore() bool { | ||
return len(bi.data) > 0 | ||
} | ||
|
||
func (bi *BytesIterator) NextBytes(length int) ([]byte, error) { | ||
if len(bi.data) < length { | ||
return nil, ErrOutOfData | ||
} | ||
|
||
result := bi.data[:length] | ||
bi.data = bi.data[length:] | ||
|
||
return result, nil | ||
} | ||
|
||
func (bi *BytesIterator) NextUint8() (uint8, error) { | ||
result, err := bi.NextBytes(1) // nolint: gomnd | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return result[0], nil | ||
} | ||
|
||
func (bi *BytesIterator) NextUint16() (uint16, error) { | ||
result, err := bi.NextBytes(2) // nolint: gomnd | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return binary.BigEndian.Uint16(result), nil | ||
} | ||
|
||
func (bi *BytesIterator) NextUint24() (uint32, error) { | ||
result, err := bi.NextBytes(3) // nolint: gomnd | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return binary.BigEndian.Uint32(append([]byte{0}, result...)), nil | ||
} | ||
|
||
func (bi *BytesIterator) NextUint32() (uint32, error) { | ||
result, err := bi.NextBytes(4) // nolint: gomnd | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return binary.BigEndian.Uint32(result), nil | ||
} | ||
|
||
func (bi *BytesIterator) NextUint64() (uint64, error) { | ||
result, err := bi.NextBytes(8) // nolint: gomnd | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return binary.BigEndian.Uint64(result), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package fusionorder | ||
|
||
import "github.com/ethereum/go-ethereum/common" | ||
|
||
const ( | ||
addressHalfLength = common.AddressLength / 2 | ||
) | ||
|
||
type AddressHalf [addressHalfLength]byte | ||
|
||
func HalfAddressFromAddress(a common.Address) AddressHalf { | ||
var addressHalf AddressHalf | ||
copy(addressHalf[:], a.Bytes()[common.AddressLength-addressHalfLength:]) // take the last 10 bytes | ||
return addressHalf | ||
} | ||
|
||
func AddressFromFirstBytes(s []byte) common.Address { | ||
return common.BytesToAddress(s[:common.AddressLength]) | ||
} |
Oops, something went wrong.