-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement encode/decode 1inch extension #75
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
944e670
Add encode/decode 1inch extension
chrisngyn 2510fc7
Fix lint
chrisngyn b22fe84
Add interaction
chrisngyn b696b9a
Implement interaction
chrisngyn dbaf2c7
Implement encode/decode auction details
chrisngyn 13856ba
Implement encode/decode settlement post interaction data
chrisngyn 2e6c529
Add fusion extension decode
chrisngyn fe2282c
Convert auction details to use primitive types
chrisngyn 6af0e34
Convert settlement post interaction data to use primitive types
chrisngyn cef15ad
Replace extension fields by byte arrays
chrisngyn abbc9a8
Convert string to []byte
chrisngyn 769b990
Sink some packages
chrisngyn 80a4d48
Shorten function encode
chrisngyn 8879836
Make lint happy
chrisngyn 18a5b09
Remove trim0x function
chrisngyn e1921b0
Remove ZX global constant
chrisngyn 4f62e68
Use math.PaddedBigBytes instead
chrisngyn d3b99ca
Check data length before get it from bytes
chrisngyn c2cc714
Add next function at decode package
chrisngyn 4ea1f6b
Implement bytes iterator
chrisngyn 88cb698
Remove completely zx
chrisngyn 1fcc00b
Remove unused assert in test
chrisngyn d520732
Add check less than 0 when create auction details
chrisngyn 61cd33e
Remove big package in bytes iterator
chrisngyn 0bcd9a9
Add assert for some tests
chrisngyn e6fbfe5
Return offset is a common.Hash
chrisngyn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly we never modify an address, I think get a slice of bytes will save some allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because
AddressHalf
is a static slice of bytes, same ascommon.Address
. So I decided still keep it.