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

docs(zetaclient): add more function and package documentation #2321

Merged
merged 18 commits into from
Jun 26, 2024
Merged
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
* [2191](https://github.com/zeta-chain/node/pull/2191) - Fixed conditional logic for the docker build step for non release builds to not overwrite the github tag.
* [2192](https://github.com/zeta-chain/node/pull/2192) - Added release status checker and updater pipeline that will update release statuses when they go live on network.

### Documentation

* [2321](https://github.com/zeta-chain/node/pull/2321) - improve documentation for ZetaClient functions and packages

## v17.0.0

### Fixes
Expand Down
7 changes: 7 additions & 0 deletions zetaclient/authz/authz_signer.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package authz provides a signer object for transactions using grants
lumtis marked this conversation as resolved.
Show resolved Hide resolved
package authz

import (
Expand All @@ -7,18 +8,22 @@ import (
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

// Signer represents a signer for a grantee key
type Signer struct {
KeyType authz.KeyType
GranterAddress string
GranteeAddress sdk.AccAddress
}

// String returns a string representation of a Signer
lumtis marked this conversation as resolved.
Show resolved Hide resolved
func (a Signer) String() string {
return a.KeyType.String() + " " + a.GranterAddress + " " + a.GranteeAddress.String()
}

// signers is a map of all the signers for the different tx types
var signers map[string]Signer

// init initializes the signers map with all the crosschain tx types using the ZetaClientGranteeKey
lumtis marked this conversation as resolved.
Show resolved Hide resolved
lumtis marked this conversation as resolved.
Show resolved Hide resolved
func init() {
signersList := make(map[string]Signer)
for _, tx := range crosschaintypes.GetAllAuthzZetaclientTxTypes() {
Expand All @@ -27,6 +32,7 @@ func init() {
signers = signersList
}

// SetupAuthZSignerList sets the granter and grantee for all the signers
lumtis marked this conversation as resolved.
Show resolved Hide resolved
lumtis marked this conversation as resolved.
Show resolved Hide resolved
func SetupAuthZSignerList(granter string, grantee sdk.AccAddress) {
for k, v := range signers {
v.GranterAddress = granter
Expand All @@ -35,6 +41,7 @@ func SetupAuthZSignerList(granter string, grantee sdk.AccAddress) {
}
}

// GetSigner returns the signer for a given msgURL
lumtis marked this conversation as resolved.
Show resolved Hide resolved
func GetSigner(msgURL string) Signer {
return signers[msgURL]
}
2 changes: 2 additions & 0 deletions zetaclient/authz/authz_signer_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
package authz_test

// NOTE: test file currently created empty to add the package in the test coverage scope
12 changes: 11 additions & 1 deletion zetaclient/chains/bitcoin/observer/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (
"github.com/zeta-chain/zetacore/zetaclient/zetacore"
)

// WatchInbound watches Bitcoin chain for incoming txs and post votes to zetacore
// WatchInbound watches Bitcoin chain for inbounds
// It starts a ticker and run ObserveInbound
// TODO(revamp): move all ticker related methods in the same file
lumtis marked this conversation as resolved.
Show resolved Hide resolved
lumtis marked this conversation as resolved.
Show resolved Hide resolved
func (ob *Observer) WatchInbound() {
ticker, err := types.NewDynamicTicker("Bitcoin_WatchInbound", ob.GetChainParams().InboundTicker)
if err != nil {
Expand All @@ -37,6 +39,7 @@ func (ob *Observer) WatchInbound() {
ob.logger.Inbound.Info().Msgf("WatchInbound started for chain %d", ob.chain.ChainId)
sampledLogger := ob.logger.Inbound.Sample(&zerolog.BasicSampler{N: 10})

// ticker loop
for {
select {
case <-ticker.C():
Expand All @@ -57,6 +60,8 @@ func (ob *Observer) WatchInbound() {
}
}

// ObserveInbound observes Bitcoin chain for inbounds and post votes to zetacore
lumtis marked this conversation as resolved.
Show resolved Hide resolved
// TODO(revamp): simplify this function into smaller functions
lumtis marked this conversation as resolved.
Show resolved Hide resolved
func (ob *Observer) ObserveInbound() error {
// get and update latest block height
cnt, err := ob.rpcClient.GetBlockCount()
Expand Down Expand Up @@ -171,6 +176,7 @@ func (ob *Observer) ObserveInbound() error {
}

// WatchInboundTracker watches zetacore for bitcoin inbound trackers
// TODO(revamp): move all ticker related methods in the same file
func (ob *Observer) WatchInboundTracker() {
ticker, err := types.NewDynamicTicker("Bitcoin_WatchInboundTracker", ob.GetChainParams().InboundTicker)
if err != nil {
Expand Down Expand Up @@ -200,6 +206,7 @@ func (ob *Observer) WatchInboundTracker() {
}

// ProcessInboundTrackers processes inbound trackers
// TODO(revamp): move inbound tracker logic in a specific file
lumtis marked this conversation as resolved.
Show resolved Hide resolved
lumtis marked this conversation as resolved.
Show resolved Hide resolved
lumtis marked this conversation as resolved.
Show resolved Hide resolved
func (ob *Observer) ProcessInboundTrackers() error {
trackers, err := ob.zetacoreClient.GetInboundTrackersForChain(ob.chain.ChainId)
if err != nil {
Expand Down Expand Up @@ -328,6 +335,7 @@ func FilterAndParseIncomingTx(
return inbounds, nil
}

// GetInboundVoteMessageFromBtcEvent converts a BTCInboundEvent to a MsgVoteInbound to enable voting on the inbound on zetacore
func (ob *Observer) GetInboundVoteMessageFromBtcEvent(inbound *BTCInboundEvent) *crosschaintypes.MsgVoteInbound {
ob.logger.Inbound.Debug().Msgf("Processing inbound: %s", inbound.TxHash)
amount := big.NewFloat(inbound.Value)
Expand Down Expand Up @@ -360,6 +368,7 @@ func (ob *Observer) GetInboundVoteMessageFromBtcEvent(inbound *BTCInboundEvent)
}

// DoesInboundContainsRestrictedAddress returns true if the inbound contains restricted addresses
// TODO(revamp): move all compliance related functions in a specific file
lumtis marked this conversation as resolved.
Show resolved Hide resolved
lumtis marked this conversation as resolved.
Show resolved Hide resolved
func (ob *Observer) DoesInboundContainsRestrictedAddress(inTx *BTCInboundEvent) bool {
receiver := ""
parsedAddress, _, err := chains.ParseAddressAndData(hex.EncodeToString(inTx.MemoBytes))
Expand All @@ -376,6 +385,7 @@ func (ob *Observer) DoesInboundContainsRestrictedAddress(inTx *BTCInboundEvent)

// GetBtcEvent either returns a valid BTCInboundEvent or nil
// Note: the caller should retry the tx on error (e.g., GetSenderAddressByVin failed)
// TODO(revamp): simplify this function
lumtis marked this conversation as resolved.
Show resolved Hide resolved
lumtis marked this conversation as resolved.
Show resolved Hide resolved
func GetBtcEvent(
rpcClient interfaces.BTCRPCClient,
tx btcjson.TxRawResult,
Expand Down
Loading
Loading