oracle

package
v0.0.0-...-36c47eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2020 License: BSD-3-Clause Imports: 33 Imported by: 0

README

Gamechain Oracle

The code is mostly based on loomchain's Oracle. The upstream is Plasmachain which runs multiple Ethereum contracts using loomchain binary. The downstream is Gamechain which is a Go contracts.

The idea of this Oracle is to fetch all the events related to open pack and sycn to Gamechain. Ideally, we should have all of our cards we open on loom.games to Gamehchain to actually play the Zombie Battleground.

ABI

To fetch data from Plasmachain we need contract's abi to generate ethcontracts. Currently the only contract that is called when we open a pack is CardFaucet. The event generated from this contract is called GeneratedCard.

run this to generate ehtcontract

make oracle-abigen

Also, there is loomchainbackend which is a client for theh ethcontract. Some of the methods are not implemented yet because we don't use them. Please make sure you implement it if needed.

Latest Plasma Block Number

We need to set latest plasma block number using zb-cli so that the oracle can start from the block where we already have the contract deployed. If not set, it will poll the data from block number 1

# start from block 200
./bin/zb-cli -k priv set_last_plasma_block_num -n 200

Starting blocks

Dev: the valid block starts from block number 196492

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = errors.New("not implememented")

Functions

func LoadDappChainPrivateKey

func LoadDappChainPrivateKey(privKeyB64 string) ([]byte, error)

func LoadDappChainPrivateKeyFile

func LoadDappChainPrivateKeyFile(path string) ([]byte, error)

func NewLoomchainBackend

func NewLoomchainBackend(cli *client.DAppChainRPCClient, signer auth.Signer) bind.ContractBackend

Types

type Config

type Config struct {
	// Plasmachain
	PlasmachainPrivateKey                string
	PlasmachainChainID                   string
	PlasmachainReadURI                   string
	PlasmachainWriteURI                  string
	PlasmachainEventsURI                 string
	PlasmachainZbgCardContractHexAddress string
	PlasmachainPollInterval              int // in second
	PlasmachainMaxBlockRange             int
	// Gamechain
	GamechainPrivateKey   string
	GamechainChainID      string
	GamechainReadURI      string
	GamechainWriteURI     string
	GamechainEventsURI    string
	GamechainContractName string
	// Oracle log verbosity (debug, info, error, etc.)
	OracleLogLevel       string
	OracleLogDestination string
	// Number of seconds to wait before starting the Oracle.
	OracleStartupDelay int32
	// Number of seconds to wait between reconnection attempts.
	OracleReconnectInterval int32
	// Address on from which the out-of-process Oracle should expose the status & metrics endpoints.
	OracleQueryAddress string
}

func DefaultConfig

func DefaultConfig() *Config

type GamechainGateway

type GamechainGateway struct {
	Address loom.Address
	// Timestamp of the last successful response from the DAppChain
	LastResponseTime time.Time
	// contains filtered or unexported fields
}

func ConnectToGamechainGateway

func ConnectToGamechainGateway(
	loomClient *client.DAppChainRPCClient, caller loom.Address, contractName string, signer auth.Signer,
	logger *loom.Logger,
) (*GamechainGateway, error)

func (*GamechainGateway) GetLastPlasmaBlockNumber

func (gw *GamechainGateway) GetLastPlasmaBlockNumber() (uint64, error)

func (*GamechainGateway) GetOracleCommandRequestList

func (gw *GamechainGateway) GetOracleCommandRequestList() ([]*orctype.OracleCommandRequest, error)

func (*GamechainGateway) ProcessOracleCommandResponseBatch

func (gw *GamechainGateway) ProcessOracleCommandResponseBatch(commandResponses []*orctype.OracleCommandResponse) error

func (*GamechainGateway) ProcessOracleEventBatch

func (gw *GamechainGateway) ProcessOracleEventBatch(events []*orctype.PlasmachainEvent, endBlock uint64, zbgCardContractAddress loom.Address) error

func (*GamechainGateway) SetLastPlasmaBlockNumber

func (gw *GamechainGateway) SetLastPlasmaBlockNumber(lastBlock uint64) error

type LoomchainBackend

type LoomchainBackend struct {
	*client.DAppChainRPCClient
	// contains filtered or unexported fields
}

func (*LoomchainBackend) CallContract

func (l *LoomchainBackend) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)

func (*LoomchainBackend) CodeAt

func (l *LoomchainBackend) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)

func (*LoomchainBackend) EstimateGas

func (l *LoomchainBackend) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error)

func (*LoomchainBackend) FilterLogs

func (l *LoomchainBackend) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error)

func (*LoomchainBackend) PendingCallContract

func (l *LoomchainBackend) PendingCallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error)

func (*LoomchainBackend) PendingCodeAt

func (l *LoomchainBackend) PendingCodeAt(ctx context.Context, contract common.Address) ([]byte, error)

func (*LoomchainBackend) PendingNonceAt

func (l *LoomchainBackend) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

func (*LoomchainBackend) SendTransaction

func (l *LoomchainBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error

func (*LoomchainBackend) SubscribeFilterLogs

func (l *LoomchainBackend) SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)

func (*LoomchainBackend) SuggestGasPrice

func (l *LoomchainBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error)

func (*LoomchainBackend) TransactionReceipt

func (l *LoomchainBackend) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

type Metrics

type Metrics struct {
	// contains filtered or unexported fields
}

func NewMetrics

func NewMetrics(subsystem string) *Metrics

func (*Metrics) FetchedPlasmachainEvents

func (m *Metrics) FetchedPlasmachainEvents(numEvents int, kind string)

func (*Metrics) MethodCalled

func (m *Metrics) MethodCalled(begin time.Time, method string, err error)

func (*Metrics) SubmittedPlasmachainEvents

func (m *Metrics) SubmittedPlasmachainEvents(numEvents int)

type Oracle

type Oracle struct {
	// contains filtered or unexported fields
}

func CreateOracle

func CreateOracle(cfg *Config, metricSubsystem string) (*Oracle, error)

func (*Oracle) Run

func (orc *Oracle) Run()

TODO: Graceful shutdown

func (*Oracle) RunWithRecovery

func (orc *Oracle) RunWithRecovery()

RunWithRecovery should run in a goroutine, it will ensure the oracle keeps on running as long as it doesn't panic due to a runtime error.

func (*Oracle) Status

func (orc *Oracle) Status() *Status

Status returns some basic info about the current state of the Oracle.

type PlasmachainGateway

type PlasmachainGateway struct {
	Address loom.Address
	// Timestamp of the last successful response from the DAppChain
	LastResponseTime time.Time
	// contains filtered or unexported fields
}

func ConnectToPlasmachainGateway

func ConnectToPlasmachainGateway(
	loomClient *client.DAppChainRPCClient,
	caller loom.Address,
	zbgCardContractAddress loom.Address,
	signer auth.Signer,
	logger *loom.Logger,
) (*PlasmachainGateway, error)

func (*PlasmachainGateway) GetTokensOwned

func (gw *PlasmachainGateway) GetTokensOwned(owner loom.LocalAddress) ([]tokensOwnedResponseItem, error)

func (*PlasmachainGateway) LastBlockNumber

func (gw *PlasmachainGateway) LastBlockNumber() (uint64, error)

type Status

type Status struct {
	Version                    string
	OracleAddress              string
	GamechainGatewayAddress    string
	GamechainGatewayLastSeen   time.Time
	PlasmachainGatewayAddress  string
	PlasmachainGatewayLastSeen time.Time
	NextPlasmachainBlockNumber uint64 `json:",string"`
	// Number of Plamachain events submitted to the DAppChain Gateway successfully
	PlasmachainEventsFetchedCount uint64 `json:",string"`
	// Total number of Plamachain events fetched
	PlasmachainEventsSubmittedCount uint64 `json:",string"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL