Skip to content
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

feat: icon-bridge integration with Tezos #868

Open
wants to merge 230 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
230 commits
Select commit Hold shift + click to select a range
bb3fd40
bts periphery initial translation
simusud Mar 14, 2023
756dff6
added string library
simusud Mar 19, 2023
3e47ca3
initial commit
Anatehc Mar 20, 2023
4e5d8b7
initial commit for tezos bridge
Mar 20, 2023
ad808b9
fix: log type to common log
Mar 20, 2023
32b0aa7
fix: src and dst address type in NewReceiver function from tezos.Addr…
Mar 20, 2023
6cb10cd
fix: changed src and dst address type from tezos.Address to BTPAddres…
Mar 20, 2023
dfb5567
feat: added new file for registering into icon-bridge
Mar 20, 2023
5c57c72
feat: transfer functions
Anatehc Mar 21, 2023
510ca49
fix: remove redundant function
Anatehc Mar 21, 2023
1c02d17
feat(bmc): Add bmc periphery functions and libraries
simusud Mar 28, 2023
b898028
feat(bmc): Add bmc management functions
simusud Mar 28, 2023
4e6e8ad
Utils file added
Suyog007 Mar 29, 2023
834cc80
fix(bmc): Implement sets instead of lists
simusud Mar 29, 2023
27244d3
fix: interscore calls
Anatehc Mar 31, 2023
ee0a4af
feat(bts): Add bts core functions
simusud Apr 5, 2023
85aeefc
Adding deployment file
simusud Apr 5, 2023
b25004f
fix(bts_periphery): Function changed to onchain view
simusud Apr 5, 2023
c0f821e
Adding libraries in Types.py
simusud Apr 5, 2023
c90e1d4
Merge branch 'bts-periphery' into bmc-periphery
simusud Apr 5, 2023
7b0dc39
fix(bmc): Deployment errors fixes in bmc periphery, bmc management an…
simusud Apr 6, 2023
002b06f
feat: added new client methods
Apr 11, 2023
92f6f0c
feat: added verifier synchronization feature and message delivery fea…
Apr 11, 2023
f5f5263
feat: added logic to Receipt() and Status()
Apr 11, 2023
ba5da24
feat: added block signature verification feature
Apr 11, 2023
6608cb6
feat: added BlockNotification struct for receiving BTPMessage
Apr 11, 2023
bcafabc
fix(bts): zero address check fixes
simusud Apr 12, 2023
822c97b
fix(bts): small fixes
simusud Apr 12, 2023
b95002e
feat(FA2): added params and view methods
simusud Apr 12, 2023
8ca90a9
fix(bmc): added checks if a map contains a key
simusud Apr 18, 2023
7374d32
fix(lib): return value fix in String.py library
simusud Apr 18, 2023
901f6dd
feat(bmc): added RLP encode library
simusud Apr 18, 2023
b0a9e84
feat(bmc): implement RLP encode library
simusud Apr 19, 2023
45ff99c
fix(bmc): view method fixes
simusud Apr 19, 2023
617f0e8
feat(bts): implement allowance and transfer from method
simusud Apr 20, 2023
8fe429b
feat(FA2): add allowance and transfer from method
simusud Apr 20, 2023
e2d5107
feat(library): add rlp encode library
simusud Apr 20, 2023
e513455
fix(bts): type fix in payment_transfer function
simusud Apr 21, 2023
9bad530
fix(btsOwnerManager): issues fixes
simusud Apr 21, 2023
2dd10bf
fix(btsOwnerManager): small fix
simusud Apr 21, 2023
8314229
fix(bts_periphery): parse address and RLP encode implementation
simusud Apr 26, 2023
b95a2d9
fix(library): data type fixes
simusud Apr 26, 2023
8d9275b
feat(library): added parse address library
simusud Apr 26, 2023
3034991
Merge branch 'bts-periphery' into bmc-periphery
simusud Apr 26, 2023
50b868a
rlp decode library added
Suyog007 May 3, 2023
e665b29
fix(library): rlp decode functions added
Suyog007 May 3, 2023
f53e691
feat(bts_core): added callback implementation and uncommented checks …
simusud May 3, 2023
ed63ee7
feat(bts_periphery): added rlp decode implementation and uncommented …
simusud May 3, 2023
998b534
feat(FA2): callback implementation in transfer function
simusud May 3, 2023
594ea3f
fix(library): small fixes
simusud May 3, 2023
1af2c95
Merge branch 'bts-periphery' into bmc-periphery
simusud May 4, 2023
fc60d5b
feat(library): added decode and parse address library
simusud May 4, 2023
7379421
fix(bmc_management): contract initialization fixes
simusud May 4, 2023
0f41b35
feat(bmc_periphery): rlp decode library implementation
simusud May 4, 2023
bb1641d
Merge branch 'icon-project:main' into bts-periphery
simusud May 4, 2023
fff55e7
fix(bts_core): minor fixes
simusud May 5, 2023
72c6a95
fix(bmc): contract size issue fixed by splitting libraries into separ…
simusud May 11, 2023
6a00aa1
fix(bts): contract size issue fixed by splitting libraries into separ…
simusud May 11, 2023
f70e635
fix: small fixes
simusud May 12, 2023
40673a9
feat: added receipt filter
icondev22 May 15, 2023
ff5f735
feat: receiveloop added
icondev22 May 15, 2023
5002a7a
fix: rlp encoding on message sends
icondev22 May 15, 2023
0087958
fix(bmc): rlp encoding fixed
Suyog007 May 15, 2023
93ecb9c
fix: added new fields in BlockNotification struct
icondev22 May 15, 2023
2c87c61
fix(bts): rlp encoding fixed and encode_service_message parameter typ…
Suyog007 May 15, 2023
6a9b5f0
feat: added height() method in Verifier
icondev22 May 15, 2023
fbeafed
fix(bts): rlp decoding fixed
Suyog007 May 16, 2023
7c1f3b6
fix(bmc): rlp decoding fixed
Suyog007 May 16, 2023
d0a0c98
fix(bmc,bts): return type fixed for without length prefix
Suyog007 May 16, 2023
109b8fc
Merge branch 'bts-periphery' into tezos-bridge
icondev22 May 16, 2023
a673451
fix(bmc): modified type of sn from nat to string
simusud May 16, 2023
d915d12
feat(bmc): modified type of sn from nat to int and implemented callba…
simusud May 16, 2023
fe09061
feat: tezos contracts deployment script
icondev22 May 17, 2023
75a6261
add(bmc): setters added to set bmc management address
Suyog007 May 17, 2023
fb303cc
add(bts): setters added to set bmc address and bts core address
Suyog007 May 17, 2023
26ee721
fix(bmc): decode receipt proof fixed
Suyog007 May 18, 2023
e3511e3
fix: icon tezos relay integration
icondev22 May 18, 2023
f477d62
Merge branch 'bts-periphery' into tezos-bridge
icondev22 May 18, 2023
40d12d2
fix(bmc): decoding negative value of sn fixed and new contract added …
Suyog007 May 18, 2023
78c57c2
feat(bts): try catch implementation through callback
simusud May 18, 2023
1d9714c
fix(bmc:library): sn type fix in RLP_decode_struct.py
simusud May 18, 2023
10c3c7a
fix(bts): small fixes
simusud May 19, 2023
5dce489
fix(bmc): decoding list only if the given bytes is in list form.
Suyog007 May 19, 2023
d3ef321
fix(bts): decoding list only if the given bytes is in list form.
Suyog007 May 19, 2023
62fa044
feat: added support for tezos wallet
icondev22 May 21, 2023
16c1b46
fix: icon tezos bridge integration
icondev22 May 21, 2023
b1f6282
Merge branch 'bts-periphery' into tezos-bridge
icondev22 May 21, 2023
abfbeba
fix: tezos iconbridge integration
icondev22 May 29, 2023
af1f8fe
fix: icon tezos integration
icondev22 Jun 1, 2023
0a12fab
feat: icon-bridge integration with Tezos
simusud Mar 14, 2023
827ca2e
fix(bts:library): fixed decode_transfer_coin_msg function
simusud Jun 5, 2023
ece3793
fix(bts:library): fixed encode_transfer_coin_msg function
simusud Jun 5, 2023
82ce583
fix(bts): fixed transfer fees function and added default value while …
simusud Jun 9, 2023
f6dbc5e
perf(bmc): improved performance by splitting rlp encode and decode in…
simusud Jun 12, 2023
2e24bed
perf(bts): improved performance by splitting rlp encode and decode in…
simusud Jun 12, 2023
c94d35e
perf(bmc): rlp encoder and decoder merged into one contract.
Suyog007 Jun 13, 2023
d62e4ad
perf(bts): rlp encoder and decoder merged into a single contract.
Suyog007 Jun 13, 2023
77d9632
feat(bmc): added upgradable feature in contract functions
simusud Jun 13, 2023
be0cc10
feat(bts): added upgradable feature in contract functions
simusud Jun 13, 2023
4e233d3
fix(bmc): added default value while reading value from map
simusud Jun 13, 2023
1dac429
fix(bts): fixes in reclaim and mint functions
simusud Jun 13, 2023
4cb8e77
fix(bts): fixes bts_core.py file size issue by removing some onchain …
simusud Jun 13, 2023
0f969ab
fix(bts): fixed variant issue in bts_periphery.py
simusud Jun 14, 2023
ad26a67
refactor(bmc): updated rlp contract address
simusud Jun 14, 2023
364f317
refactor(bts): updated rlp contract address
simusud Jun 14, 2023
75f3116
refactor(bts): changed record key name in RLP_struct.py
simusud Jun 15, 2023
d5f28c9
refactor(bts): updated rlp contract address in bts_periphery.py
simusud Jun 15, 2023
15e6ee5
fix(bmc): decode_response fixed in case of error tx
simusud Jun 15, 2023
fa10f8a
feat: added GetBMCManagement() for getting bmc_management address
icondev22 Jun 19, 2023
e85ba7a
feat: tezos wallet creation script
icondev22 Jun 19, 2023
5bad7c4
refactor(bmc): rlp_contract address update
simusud Jun 19, 2023
703848d
fix(bts): removed callback from transfer in bts_core.py and checked t…
simusud Jun 19, 2023
6380df9
fix: inclusion of newer packages
icondev22 Jun 20, 2023
906dd0b
fix: added CustomCall() for fixing the incorrect simulated gas and st…
icondev22 Jun 20, 2023
edb574f
refactor(bmc): updated library addresses
simusud Jun 21, 2023
cac9040
fix(bmc): encode_bmc_message fix for negative encoding
simusud Jun 21, 2023
964ff22
revert(bmc): changed RLP contract back to a library
simusud Jun 23, 2023
63a3e94
revert(bts): changed RLP contract back to a library
simusud Jun 23, 2023
2a41a78
fix: event filter for events present in the same blocks
icondev22 Jun 23, 2023
086e0fc
feat: syncverifier and receiveloop in same function
icondev22 Jun 23, 2023
17cc124
fix: endorsement threshold calculation
icondev22 Jun 23, 2023
21d920c
fix: type of tezos blockhash
icondev22 Jun 23, 2023
25ea9b4
fix: new config for new env
icondev22 Jun 23, 2023
fffcd24
feat(bts): implemented callback in balance_of
simusud Jun 23, 2023
7c15d62
perf(bmc): try catch added on rlp decoding
Suyog007 Jun 26, 2023
63d86a4
perf(bts): try catch added on rlp decoding
Suyog007 Jun 26, 2023
1eb70e0
fix(bts): get_balance_of used instead of balance_of
Suyog007 Jun 26, 2023
ebcc23e
fix(bts): removed balance_of function
Suyog007 Jun 26, 2023
3c5bd9b
feat: added consensus key getter for alternate wallets
icondev22 Jun 27, 2023
88a6040
fix: icon - tezos bridge integration
icondev22 Jun 27, 2023
9d7bc5d
Merge branch 'transfer-coin-msg-fix' into tezos-bridge
icondev22 Jun 27, 2023
87cd646
fix(bts): unregistered coin handled
simusud Jun 27, 2023
6f4bfb4
perf(bmc): internal review changes
simusud Jun 30, 2023
f243214
perf(bts): internal review changes
simusud Jun 30, 2023
f98461e
fix(bts): onchain view return type fixed
Suyog007 Jul 3, 2023
88594d9
fix(bts): negative amount check skipped if caller is bts core .
Suyog007 Jul 3, 2023
8efd9ca
style(bts): code formatting
simusud Jul 4, 2023
3c74516
style(bmc): code formatting
simusud Jul 4, 2023
b8fdb21
fix(bmc): code review changes
simusud Jul 4, 2023
bec8a4c
fix(bmc): removed pack
simusud Jul 5, 2023
8192012
fix(bts): removed pack
simusud Jul 5, 2023
76476b4
docs(bmc): added comment in string split
simusud Jul 5, 2023
ea18b39
test(bmc): unit test fixes
simusud Jul 5, 2023
c2dd79b
test(bts): unit test fixes
simusud Jul 5, 2023
2d81c9e
fix: tezos to icon bridge integraton changes
icondev22 Jul 6, 2023
0d9d1eb
fix: tezos icon bridge integration fixes
icondev22 Jul 6, 2023
f525318
Merge branch 'transfer-coin-msg-fix' into tezos-bridge
icondev22 Jul 6, 2023
bb60dc2
fix: tezos icon bridge integration
icondev22 Jul 6, 2023
1c84b0b
fix: tezos icon integration fixes
icondev22 Jul 7, 2023
656ef0e
fix(bmc): removed redundant params
simusud Jul 7, 2023
6f20dab
perf(bmc): review changes
simusud Jul 7, 2023
feacc97
test(bmc): integration test update
simusud Jul 7, 2023
2df1831
fix: tezos verifier turned off
icondev22 Jul 9, 2023
0d87810
test(bmc): variable name change and integration test update
simusud Jul 9, 2023
ba527ac
style(bts): typo fix
simusud Jul 9, 2023
214a8cb
fix(bts): verifying bts core token balance before burning token.
Suyog007 Jul 10, 2023
4711088
test(bmc): updated integration test and added fa2 dummy contract
simusud Jul 11, 2023
dabb6d7
perf(bts): rlp struct library optimized.
Suyog007 Jul 13, 2023
2092c4a
perf(bmc): rlp struct library optimized.
Suyog007 Jul 13, 2023
26a8d1b
perf(bts): added update functions and removed integration test file
simusud Jul 13, 2023
e92afd2
perf(bmc): review changes and removed parse address file
simusud Jul 13, 2023
d33c50b
test(bmc): message modified in integration test.
Suyog007 Jul 13, 2023
7f92b49
perf(bmc): typo fixed.
Suyog007 Jul 13, 2023
e567ba8
test(bmc): owner address removed from bmc periphery integration test.
Suyog007 Jul 13, 2023
a254ae7
test(bmc): unit test fixes
simusud Jul 14, 2023
5ee0f95
fix(bmc): added check for map key in is_owner view function
simusud Jul 14, 2023
a2a6bdf
perf(bmc): removed unused functions and added lazify on callback func…
Suyog007 Jul 18, 2023
4f008da
perf(bts): removed comments and added lazify on fee gathering
Suyog007 Jul 18, 2023
be4d3ed
feat(bmc): added function to pause bridge
simusud Jul 20, 2023
9ebb4a9
feat(bts): added function to pause bridge
simusud Jul 20, 2023
196f88b
test(bmc): updated tests for bridge pause feature
simusud Jul 20, 2023
c35dcad
test(bts): updated test for set token limit
simusud Jul 20, 2023
51dbaf9
fix: icon tezos bridge integration
icondev22 Jul 21, 2023
98b92d2
refactor(bmc): removed unused db
simusud Jul 21, 2023
0e441a3
refactor(bts): resolved todo
simusud Jul 21, 2023
9b1eba4
Merge pull request #1 from TechFlow-Space/transfer-coin-msg-fix
Suyog007 Jul 21, 2023
107c67d
refactor(bmc): renamed entrypoint in bmc_periphery.py and updated che…
simusud Jul 24, 2023
6e39504
fix: tezos icon bridge integration
icondev22 Jul 24, 2023
6d16afc
feat: added tezos score setters
icondev22 Jul 24, 2023
6f05393
Merge branch 'main' into tezos-bridge
icondev22 Jul 24, 2023
95dceab
Merge pull request #2 from TechFlow-Space/transfer-coin-msg-fix
Suyog007 Jul 24, 2023
fa5419b
fix: block processing logic
icondev22 Jul 25, 2023
e3a3e4f
fix: configure dot env for tezos setter
icondev22 Jul 25, 2023
300644c
fix: tezos icon bridge integration
icondev22 Jul 27, 2023
9ba9b68
fix: tezos icon bridge config
icondev22 Aug 4, 2023
2b0c398
fix: added build to token.smartpy.sh
icondev22 Aug 4, 2023
f5fe4bc
fix: path in token.smartpy.sh
icondev22 Aug 4, 2023
a57443e
fix: path in token.smartpy.sh
icondev22 Aug 4, 2023
7da9e3e
fix: path in token.smartpy.sh
icondev22 Aug 4, 2023
03558c2
fix: path in token.smartpy.sh
icondev22 Aug 4, 2023
3efc78b
fix: path in token.smartpy.io
icondev22 Aug 4, 2023
1143144
fix: path in token.smartpy.sh
icondev22 Aug 4, 2023
e7b3eb2
fix: icon tezos bridge configuration
icondev22 Aug 8, 2023
e7c5bd5
feat: auto relay start from build script
icondev22 Aug 8, 2023
98f80ab
fix: include methods in `token.smartpy.sh`
icondev22 Aug 8, 2023
7462558
fix: tezos icon bridge configuration
icondev22 Aug 10, 2023
8ad4f35
fix: path in token.smartpy.sh
icondev22 Aug 10, 2023
a2f7189
fix: added unpausing bridge in tezos setters
icondev22 Aug 10, 2023
aef805d
fix: removed else if from tokenfallback
icondev22 Aug 11, 2023
90896a6
feat(bts): added increase and decrease allowance function in FA2_cont…
simusud Aug 16, 2023
f61a2b4
fix(bts): added checks and emit in allowance functions in FA2_contrac…
simusud Aug 17, 2023
4acc522
Merge pull request #3 from TechFlow-Space/add-and-decrease-allowance
Suyog007 Aug 17, 2023
f3d3f00
chore: code cleanup for bmr integration
icondev22 Aug 18, 2023
2556b5f
fix: lowercase issue in bts contract
icondev22 Aug 18, 2023
69e949f
feat: deployment script for mainnet and testnet
icondev22 Aug 18, 2023
ddddc7b
chore: added documentation for ICON Tezos bmr impl
icondev22 Aug 18, 2023
e27f887
fix: removed token.smartpy.sh
icondev22 Aug 18, 2023
f3e8b45
Merge branch 'main' into tezos-bridge
icondev22 Aug 18, 2023
7d06aa1
chore: file reformat to original
icondev22 Aug 18, 2023
80c7da3
fix: file reverted to original
icondev22 Aug 18, 2023
d4524b5
fix: removed unnecessary files
icondev22 Aug 18, 2023
b2a9af3
fix: reformatted to original
icondev22 Aug 18, 2023
c75d312
fix: removed register token
icondev22 Aug 18, 2023
35a90a6
fix: uncommented build script
icondev22 Aug 18, 2023
9a6c948
fix: remove unnecessary files
icondev22 Aug 18, 2023
7cd7eba
fix: hardcoded values
icondev22 Aug 18, 2023
0de533c
fix: hardcoded values
icondev22 Aug 18, 2023
be1ef6a
fix: tezos icon bridge implementation
icondev22 Aug 18, 2023
5b7938b
fix:config change
icondev22 Aug 18, 2023
4140011
Merge pull request #4 from TechFlow-Space/tezos-bridge
Suyog007 Aug 18, 2023
79f7ce9
fix: path in build scripts
icondev22 Aug 18, 2023
d9ea6b7
Merge pull request #5 from TechFlow-Space/fix/build_scripts
Suyog007 Aug 18, 2023
fd3e819
revert(bts): reverted previous commit due to storage issue
simusud Aug 18, 2023
c3f0766
Merge pull request #6 from TechFlow-Space/add-and-decrease-allowance
Suyog007 Aug 18, 2023
524fcdc
fix: timeout fixes
icondev22 Aug 21, 2023
3f42069
fix: sender fix
icondev22 Aug 21, 2023
9f765ca
chore: removed unnecessary prints
icondev22 Aug 21, 2023
89dd696
Merge branch 'main' into fix/build_scripts
icondev22 Aug 21, 2023
5b34a75
fix(bmc): fixed bmc sequence number decoding and encoding
Suyog007 Aug 21, 2023
0359b5d
Merge pull request #7 from TechFlow-Space/fix/build_scripts
Suyog007 Aug 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ devnet/docker/icon-bsc/data/
devnet/docker/icon-algorand/local/
devnet/docker/icon-algorand/cache/
devnet/docker/icon-algorand/iconvalidators
devnet/docker/icon-algorand/*keystore.json
devnet/docker/icon-algorand/*keystore.json
javascore/wallet1.json
4 changes: 2 additions & 2 deletions cmd/iconbridge/chain/icon/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func (r *Receiver) newVerifier(opts *types.VerifierOptions) (*Verifier, error) {
if err != nil {
return nil, err
}

ok, err := vr.Verify(header, votes)
if !ok {
err = errors.New("verification failed")
Expand Down Expand Up @@ -304,7 +305,6 @@ func handleVerifierBlockRequests(requestCh chan *verifierBlockRequest, client IC
}

func (r *Receiver) receiveLoop(ctx context.Context, startHeight, startSeq uint64, callback func(rs []*chain.Receipt) error) (err error) {

blockReq, logFilter := r.blockReq, r.logFilter // copy

blockReq.Height, logFilter.seq = types.NewHexInt(int64(startHeight)), startSeq
Expand Down Expand Up @@ -378,7 +378,7 @@ loop:
}
}(ctxMonitorBlock, cancelMonitorBlock)

// sync verifier
// sync verifier disabled
if vr != nil {
if err := r.syncVerifier(vr, next); err != nil {
return errors.Wrapf(err, "sync verifier: %v", err)
Expand Down
2 changes: 0 additions & 2 deletions cmd/iconbridge/chain/icon/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ func (s *sender) Segment(
if err != nil {
return nil, nil, err
}

return tx, newMsg, nil
}

Expand Down Expand Up @@ -247,7 +246,6 @@ func (tx *relayTx) ID() interface{} {
func (tx *relayTx) Send(ctx context.Context) error {
tx.cl.log.WithFields(log.Fields{
"prev": tx.Prev}).Debug("handleRelayMessage: send tx")

SignLoop:
for {
if err := tx.cl.SignTransaction(tx.w, tx.txParam); err != nil {
Expand Down
20 changes: 10 additions & 10 deletions cmd/iconbridge/chain/icon/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ package icon

import (
"fmt"
"github.com/icon-project/icon-bridge/cmd/iconbridge/chain/icon/types"
"sync"

"github.com/icon-project/icon-bridge/cmd/iconbridge/chain/icon/types"

"github.com/icon-project/goloop/common"
"github.com/icon-project/goloop/common/codec"
"github.com/icon-project/icon-bridge/common/crypto"
)



const (
VoteTypePrevote types.VoteType = iota
VoteTypePrecommit
Expand All @@ -38,12 +37,12 @@ type TxResult struct {
CumulativeStepUsed []byte
StepUsed []byte
StepPrice []byte
LogsBloom []byte
EventLogs []types.EventLog
ScoreAddress []byte
EventLogsHash common.HexBytes
TxIndex types.HexInt
BlockHeight types.HexInt
LogsBloom []byte
EventLogs []types.EventLog
ScoreAddress []byte
EventLogsHash common.HexBytes
TxIndex types.HexInt
BlockHeight types.HexInt
}

type Verifier struct {
Expand Down Expand Up @@ -114,8 +113,9 @@ func (vr *Verifier) Verify(blockHeader *types.BlockHeader, votes []byte) (ok boo
return true, nil
}
}
return true, nil

return false, fmt.Errorf("insufficient votes")
// return false, fmt.Errorf("insufficient votes")
}

func (vr *Verifier) Update(blockHeader *types.BlockHeader, nextValidators []common.Address) (err error) {
Expand Down
283 changes: 283 additions & 0 deletions cmd/iconbridge/chain/tezos/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
package tezos

import (
"bytes"
"context"
"encoding/json"
"io/ioutil"
"math/big"
"net/http"

// "io"
"time"

"github.com/icon-project/icon-bridge/common/log"

"blockwatch.cc/tzgo/codec"
"blockwatch.cc/tzgo/contract"
"blockwatch.cc/tzgo/micheline"
"blockwatch.cc/tzgo/rpc"
"blockwatch.cc/tzgo/tezos"
"github.com/icon-project/icon-bridge/cmd/iconbridge/chain"
"github.com/icon-project/icon-bridge/cmd/iconbridge/chain/tezos/types"
)

const (
DefaultSendTransactionRetryInterval = 30 * time.Second
DefaultGetTransactionResultPollingInterval = 15 * time.Second
DefaultBlockWaitInterval = 15 * time.Second
)

type IClient interface {
GetBalance(ctx context.Context, connection *rpc.Client, account tezos.Address, blockLevel int64)
GetBlockByHeight(ctx context.Context, connection *rpc.Client, blockLevel int64) (*rpc.Block, error)
GetBlockHeightByHash(ctx context.Context, connection *rpc.Client, hash tezos.BlockHash) (int64, error)
MonitorBlock(ctx context.Context, client *rpc.Client, connection *contract.Contract, blockLevel int64, callback func(v *types.BlockNotification) error) (*rpc.Block, error)
GetLastBlock(ctx context.Context, connection *rpc.Client) (*rpc.Block, error)
GetStatus(ctx context.Context, contr *contract.Contract) (TypesLinkStats, error)
HandleRelayMessage(ctx context.Context, callArgs contract.CallArguments) (*rpc.Receipt, error)
}

// tezos periphery
type TypesLinkStats struct {
RxSeq *big.Int
TxSeq *big.Int
RxHeight *big.Int
CurrentHeight *big.Int
}

type Client struct {
Log log.Logger
// Ctx context.Context
Cl *rpc.Client
Contract *contract.Contract
blockLevel int64
BmcManagement tezos.Address
}

func (c *Client) GetLastBlock(ctx context.Context, connection *rpc.Client) (*rpc.Block, error) {
block, err := connection.GetHeadBlock(ctx)
if err != nil {
return nil, err
}
return block, nil
}

func (c *Client) GetBlockByHeight(ctx context.Context, connection *rpc.Client, blockLevel int64) (*rpc.Block, error) {
block, err := connection.GetBlock(ctx, rpc.BlockLevel(blockLevel))
if err != nil {
return nil, err
}
return block, nil
}

func (c *Client) GetBlockHeightByHash(ctx context.Context, connection *rpc.Client, hash tezos.BlockHash) (uint64, error) {
block, err := connection.GetBlock(ctx, hash)
if err != nil {
return 0, err
}
return uint64(block.Header.Level), nil
}

func (c *Client) GetBlockHeaderByHeight(ctx context.Context, connection *rpc.Client, blockLevel int64) (*rpc.BlockHeader, error) {
block, err := connection.GetBlockHeader(ctx, rpc.BlockLevel(blockLevel))
if err != nil {
return nil, err
}
return block, nil
}

func filterMessageEvents(tx *rpc.Transaction, contractAddress tezos.Address, height uint64, dst string) (*chain.Receipt, error) {
receipt := &chain.Receipt{}
var events []*chain.Event

for i := 0; i < len(tx.Metadata.InternalResults); i++ {
internalResults := tx.Metadata.InternalResults[i]
if internalResults.Kind.String() == "event" && internalResults.Source.ContractAddress() == contractAddress.ContractAddress() {
if internalResults.Tag == "Message" {
message := internalResults.Payload.Args[0].Bytes
next := internalResults.Payload.Args[1].Args[0].String
seq := internalResults.Payload.Args[1].Args[1].Int

if next == dst {
events = append(events, &chain.Event{
Message: message,
Next: chain.BTPAddress(next),
Sequence: seq.Uint64(),
})

receipt.Index = uint64(i)
receipt.Height = height
receipt.Events = events
}
}

}
}
return receipt, nil
}

func (c *Client) GetClient() *rpc.Client {
return c.Cl
}

func (c *Client) GetBalance(ctx context.Context, connection *rpc.Client, account tezos.Address, blockLevel int64) (*big.Int, error) {
balance, err := connection.GetContractBalance(ctx, account, rpc.BlockLevel(blockLevel))
if err != nil {
return nil, err
}
return balance.Big(), nil
}

func (c *Client) GetBMCManangement(ctx context.Context, contr *contract.Contract, account tezos.Address) (string, error) {
result, err := contr.RunView(ctx, "get_bmc_periphery", micheline.Prim{})
if err != nil {
return "", err
}
return result.String, nil
}

func (c *Client) GetStatus(ctx context.Context, contr *contract.Contract, link string) (TypesLinkStats, error) {
prim := micheline.Prim{}

in := "{ \"string\": \"" + link + "\" }"

if err := prim.UnmarshalJSON([]byte(in)); err != nil {
return *new(TypesLinkStats), err
}

result, err := contr.RunView(ctx, "get_status", prim)
if err != nil {
return *new(TypesLinkStats), err
}
linkStats := &TypesLinkStats{}

linkStats.CurrentHeight = result.Args[0].Args[0].Int
linkStats.RxHeight = result.Args[0].Args[1].Int
linkStats.RxSeq = result.Args[1].Int
linkStats.TxSeq = result.Args[2].Int

return *linkStats, nil
}

func (c *Client) GetOperationByHash(ctx context.Context, clinet *rpc.Client, blockHash tezos.BlockHash, list int, pos int) (*rpc.Operation, error) {
operation, err := clinet.GetBlockOperation(ctx, blockHash, list, pos)
if err != nil {
return nil, err
}
return operation, nil
}

func (c *Client) GetConsensusKey(ctx context.Context, bakerConsensusKey tezos.Address) (tezos.Key, error) {
var exposedPublicKey tezos.Key
for i := 0; i < 5; i++ {
url := c.Cl.BaseURL.String() + "/chains/main/blocks/head/context/raw/json/contracts/index/" + bakerConsensusKey.String() + "/consensus_key/active"

resp, err := http.Get(url)
if err != nil {
return tezos.Key{}, err
}

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return tezos.Key{}, err
}
//Convert the body to type string
sb := string(body)

exposedPublicKey, err = tezos.ParseKey(sb[1 : len(sb)-2])
if err != nil {
time.Sleep(2 * time.Second)
continue
}
break
}
return exposedPublicKey, nil
}

func (c *Client) HandleRelayMessage(ctx context.Context, callArgs contract.CallArguments, opts *rpc.CallOptions) (*rpc.Receipt, error) {
result, err := c.Contract.Call(ctx, callArgs, opts)
if err != nil {
return nil, err
}
return result, nil
}

func (c *Client) CustomCall(ctx context.Context, args []contract.CallArguments, opts *rpc.CallOptions) (*rpc.Receipt, error) {
if opts == nil {
opts = &rpc.DefaultOptions
}

// assemble batch transaction
op := codec.NewOp().WithTTL(opts.TTL)
for _, arg := range args {
if arg == nil {
continue
}
op.WithContents(arg.Encode())
}

var limits []tezos.Limits
limit := tezos.Limits{
GasLimit: tezos.MumbainetParams.HardGasLimitPerOperation,
StorageLimit: tezos.MumbainetParams.HardStorageLimitPerOperation,
}

limits = append(limits, limit)

op.WithLimits(limits, 0).WithMinFee()

// prepare, sign and broadcast
return c.Cl.Send(ctx, op, opts)
}

func NewClient(uri string, src tezos.Address, bmcManagement tezos.Address, l log.Logger) (*Client, error) {
c, err := rpc.NewClient(uri, nil)

conn := contract.NewContract(src, c)

if err != nil {
return nil, err
}

return &Client{Log: l, Cl: c, Contract: conn, BmcManagement: bmcManagement}, nil
}

func PrettyEncode(data interface{}) error {
var buffer bytes.Buffer
enc := json.NewEncoder(&buffer)
enc.SetIndent("", " ")
if err := enc.Encode(data); err != nil {
return err
}
return nil
}

func filterTransactionOperations(block *rpc.Block, contractAddress tezos.Address, blockHeight int64, cl *Client, dst string) (bool, []*chain.Receipt, error) {
blockOperations := block.Operations
var tx *rpc.Transaction
var receipt []*chain.Receipt
for i := 0; i < len(blockOperations); i++ {
for j := 0; j < len(blockOperations[i]); j++ {
for _, operation := range blockOperations[i][j].Contents {
switch operation.Kind() {
case tezos.OpTypeTransaction:
tx = operation.(*rpc.Transaction)
r, err := filterMessageEvents(tx, cl.BmcManagement, uint64(blockHeight), dst)
if err != nil {
return false, nil, err
}
if len(r.Events) != 0 {
receipt = append(receipt, r)
}
}
}
}
}
// var transaction *rpc.Transaction

if len(receipt) == 0 {
return false, nil, nil
}
return true, receipt, nil
}
Loading