-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from Zilliqa/develop
feat: cross chain
- Loading branch information
Showing
66 changed files
with
6,743 additions
and
428 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,6 +1,7 @@ | ||
FROM golang:1.12.9 | ||
FROM golang:1.15.8-alpine | ||
LABEL maintainer="Ren xiaohuo <lulu@zilliqa.com>" | ||
WORKDIR /app | ||
COPY ./ . | ||
RUN apk add build-base | ||
RUN go test -c -o ./test github.com/Zilliqa/gozilliqa-sdk/provider | ||
RUN CI=true go tool test2json -t ./test -test.v |
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 |
---|---|---|
|
@@ -23,4 +23,5 @@ type DeployParams struct { | |
GasPrice string | ||
GasLimit string | ||
SenderPubKey string | ||
Priority bool | ||
} |
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,49 @@ | ||
/* | ||
* Copyright (C) 2021 Zilliqa | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package core | ||
|
||
import ( | ||
protobuf "github.com/Zilliqa/gozilliqa-sdk/protobuf" | ||
"github.com/golang/protobuf/proto" | ||
) | ||
|
||
type AccountBase struct { | ||
Version uint32 | ||
Balance uint64 | ||
Nonce uint64 | ||
StorageRoot []byte | ||
CodeHash []byte | ||
} | ||
|
||
func AccountBaseFromBytes(bytes []byte) (*AccountBase, error) { | ||
var protoAccountBase protobuf.ProtoAccountBase | ||
err := proto.Unmarshal(bytes, &protoAccountBase) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var accountBase AccountBase | ||
accountBase.Version = *protoAccountBase.Version | ||
|
||
balanceNum := ByteArrayToUint(protoAccountBase.Balance.Data, 0, 16) | ||
accountBase.Balance = balanceNum.Uint64() | ||
accountBase.Nonce = *protoAccountBase.Nonce | ||
accountBase.CodeHash = protoAccountBase.Codehash | ||
accountBase.StorageRoot = protoAccountBase.Storageroot | ||
|
||
return &accountBase, 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,32 @@ | ||
/* | ||
* Copyright (C) 2021 Zilliqa | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package core | ||
|
||
import ( | ||
"github.com/Zilliqa/gozilliqa-sdk/util" | ||
"testing" | ||
) | ||
|
||
func TestAccountBaseFromBytes(t *testing.T) { | ||
bytes := util.DecodeHex("080112120a100000000000000000000000000000000018002220f74e858d851b7035161c66546fc183a5b162a8ee187d10324acb1fa8cf1391ea2a20f95d81f1e266a74b57e3bd6ec484ac9c1b2a006a23a6f3a911ce4cfe73ecd335") | ||
accountBase, err := AccountBaseFromBytes(bytes) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
t.Log(util.EncodeHex(accountBase.StorageRoot)) | ||
} |
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,53 @@ | ||
/* | ||
* Copyright (C) 2021 Zilliqa | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package core | ||
|
||
import ( | ||
"math/big" | ||
) | ||
|
||
type BIGNumSerialize struct{} | ||
|
||
func (bn *BIGNumSerialize) SetNumber(dst []byte, offset uint, size uint, value *big.Int) []byte { | ||
// check for offset overflow | ||
if offset+size < size { | ||
// overflow detected | ||
return nil | ||
} | ||
|
||
bytes := value.Bytes() | ||
actualByteNumber := len(bytes) | ||
if actualByteNumber <= int(size) { | ||
if offset+size > uint(len(dst)) { | ||
newDst := make([]byte, int(offset+size)) | ||
copy(newDst, dst) | ||
dst = newDst | ||
} | ||
// pad with zeroes as needed | ||
sizeDiff := size - uint(actualByteNumber) | ||
for i := uint(0); i < sizeDiff; i++ { | ||
dst[offset+i] = 0x00 | ||
} | ||
|
||
for i := 0; i < actualByteNumber; i++ { | ||
dst[offset+sizeDiff+uint(i)] = bytes[i] | ||
} | ||
} else { | ||
// big num size > declared size | ||
} | ||
return dst | ||
} |
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,58 @@ | ||
/* | ||
* Copyright (C) 2021 Zilliqa | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package core | ||
|
||
type BitVector struct{} | ||
|
||
func (b *BitVector) GetBitVectorLengthInBytes(lengthInBits uint) uint { | ||
a := lengthInBits & 0x07 | ||
if a > 0 { | ||
return (lengthInBits >> 3) + 1 | ||
} else { | ||
return lengthInBits >> 3 | ||
} | ||
} | ||
|
||
func (b *BitVector) GetBitVectorSerializedSize(lengthInBits uint) uint { | ||
return 2 + b.GetBitVectorLengthInBytes(lengthInBits) | ||
} | ||
|
||
func (b *BitVector) SetBitVector(dst []byte, offset uint, value []bool) []byte { | ||
lengthNeeded := b.GetBitVectorSerializedSize(uint(len(value))) | ||
if (offset + lengthNeeded) > uint(len(dst)) { | ||
newDst := make([]byte, offset+lengthNeeded) | ||
copy(newDst, dst) | ||
dst = newDst | ||
} | ||
|
||
for i := offset; i < offset+lengthNeeded; i++ { | ||
dst[i] = 0x00 | ||
} | ||
|
||
dst[offset] = byte(len(value) >> 8) | ||
dst[offset+1] = byte(len(value)) | ||
|
||
index := uint(0) | ||
for _, b := range value { | ||
if b { | ||
dst[offset+2+(index>>3)] |= 1 << (7 - (index & 0x07)) | ||
} | ||
index++ | ||
} | ||
|
||
return dst | ||
} |
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,48 @@ | ||
/* | ||
* Copyright (C) 2021 Zilliqa | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package core | ||
|
||
import "github.com/Zilliqa/gozilliqa-sdk/protobuf" | ||
|
||
type BlockBase struct { | ||
BlockHash [32]byte | ||
Cosigs CoSignatures | ||
Timestamp uint64 | ||
} | ||
|
||
func (b *BlockBase) ToProtobuf() *protobuf.ProtoBlockBase { | ||
blockBase := &protobuf.ProtoBlockBase{} | ||
blockBase.Blockhash = b.BlockHash[:] | ||
blockBase.Timestamp = b.Timestamp | ||
|
||
cs1 := make([]byte, 0) | ||
cs2 := make([]byte, 0) | ||
|
||
cosig := &protobuf.ProtoBlockBase_CoSignatures{ | ||
Cs1: &protobuf.ByteArray{ | ||
Data: b.Cosigs.CS1.Serialize(cs1, 0), | ||
}, | ||
B1: b.Cosigs.B1, | ||
Cs2: &protobuf.ByteArray{ | ||
Data: b.Cosigs.CS2.Serialize(cs2, 0), | ||
}, | ||
B2: b.Cosigs.B2, | ||
} | ||
blockBase.Cosigs = cosig | ||
|
||
return blockBase | ||
} |
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,35 @@ | ||
/* | ||
* Copyright (C) 2021 Zilliqa | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package core | ||
|
||
type DSBlockHashSet struct { | ||
// should be 32 bytes | ||
ShardingHash []byte | ||
ReservedField [128]byte | ||
} | ||
|
||
type TxBlockHashSet struct { | ||
// State merkle tree root hash only valid in vacuous epoch | ||
// should be 32 bytes as well | ||
StateRootHash [32]byte | ||
// State Delta Hash on DS | ||
// 32 bytes | ||
DeltaHash [32]byte | ||
// Hash concatenated from all microblock infos | ||
// 32 bytes | ||
MbInfoHash [32]byte | ||
} |
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,34 @@ | ||
/* | ||
* Copyright (C) 2021 Zilliqa | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package core | ||
|
||
import "github.com/Zilliqa/gozilliqa-sdk/protobuf" | ||
|
||
type BlockHeaderBase struct { | ||
Version uint32 | ||
// Hash for the committee that generated the block | ||
CommitteeHash [32]byte | ||
PrevHash [32]byte | ||
} | ||
|
||
func (b *BlockHeaderBase) ToProtobuf() *protobuf.ProtoBlockHeaderBase { | ||
protoBlockHeaderBase := &protobuf.ProtoBlockHeaderBase{} | ||
protoBlockHeaderBase.Version = b.Version | ||
protoBlockHeaderBase.Committeehash = b.CommitteeHash[:] | ||
protoBlockHeaderBase.Prevhash = b.PrevHash[:] | ||
return protoBlockHeaderBase | ||
} |
Oops, something went wrong.