This repository has been archived by the owner on Oct 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stable version to replace the shadow service in darwinia.js (#7)
* update: adapt lowercase request method with slash * add: double node with merkle proof format * add: basic scale lib * add: proof encode * update: adapt darwinia ethereum header * update: support scale codec for darwinia ethereum header * update: README * update: add homebrew guide
- Loading branch information
Showing
14 changed files
with
1,063 additions
and
266 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.DS_Store | ||
target | ||
go.sum |
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
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,70 @@ | ||
package core | ||
|
||
import ( | ||
"encoding/binary" | ||
"encoding/hex" | ||
"strings" | ||
|
||
"github.com/darwinia-network/darwinia.go/util" | ||
) | ||
|
||
// Pack encode proof | ||
func encodeProofArray(arr []util.DoubleNodeWithMerkleProof) string { | ||
hex := "0x0101" | ||
for _, v := range arr { | ||
hex += encodeProof(v) | ||
} | ||
|
||
return hex | ||
} | ||
|
||
// Encode proof to hex with exist hex | ||
func encodeProof(dnmp util.DoubleNodeWithMerkleProof) string { | ||
hex := "" | ||
for _, v := range dnmp.DagNodes { | ||
hex += v[2:] | ||
} | ||
|
||
// pad the length | ||
hex += "64" | ||
for _, v := range dnmp.Proof { | ||
hex += v[2:] | ||
} | ||
|
||
return hex | ||
} | ||
|
||
// Encode Darwinia Eth Header | ||
func encodeDarwiniaEthHeader(header util.DarwiniaEthHeader) string { | ||
hex := "0x" | ||
hex += header.ParentHash[2:] | ||
hex += encodeUint(header.TimeStamp, 64) | ||
hex += encodeUint(header.Number, 64) | ||
hex += strings.ToLower(header.Author[2:]) | ||
hex += header.TransactionsRoot[2:] | ||
hex += header.UnclesHash[2:] | ||
hex += "7c" | ||
hex += header.ExtraData[2:] | ||
hex += header.StateRoot[2:] | ||
hex += header.ReceiptsRoot[2:] | ||
hex += header.LogBloom[2:] | ||
hex += encodeUint(header.GasUsed, 256) | ||
hex += encodeUint(header.GasLimited, 256) | ||
hex += encodeUint(header.Difficulty, 256) | ||
hex += "0884" | ||
hex += header.Seal[0][2:] | ||
hex += "24" | ||
hex += header.Seal[1][2:] | ||
hex += "01" | ||
hex += header.Hash[2:] | ||
|
||
return hex | ||
} | ||
|
||
// Encode uint to hex | ||
func encodeUint(n uint64, d int16) string { | ||
b := make([]byte, d/8) | ||
binary.LittleEndian.PutUint64(b, n) | ||
|
||
return hex.EncodeToString(b) | ||
} |
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
Oops, something went wrong.