okc

package module
v0.0.0-...-a05b099 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 16 Imported by: 0

README

OKC smart contract Connector

Listen events from OKC smart contracts

How to Build a Connector

Prerequisites

  1. Golang 1.20+
  2. Docker
  3. protoc
  4. protoc-gen-go
  5. abigen
  6. solc

Overview

Listen events from OKC smart contracts

Code of a Connector
1. Getting the ABI files for a smart contract

For now we just support only one ABI smart contract

3. Creating the contract handling files

First, enter the <contract_name>/ directory. Create the <contract_name>.abi file in <contract_name>/ and paste the ABI source code you copied earlier.

Next, generate the <contract_name>.abi.go file using abigen (you should have abigen installed from the above step) .

Need to add abigen and protogen installation guide links here

abigen --abi <contract_name>.abi --pkg <contract_name> --out <contract_name>.abi.go

Next, generate the <contract_name>.pb.go file using protoc(you should have protoc installed from the above step) .

protoc --go_out=. --go_opt=paths=source_relative ./<contract_name>.proto
go mod init

go mod tidy

This automatically creates the go.mod and go.sum files that tell go to fetch which modules and dependencies your program depends on.

Next, spin up kafka by running:

docker compose up -d

You can update rpc in file local.yaml and update manifest.yaml for kafka transaction id

Now start the connector locally by running the main.go file. (If you are running to “connection refused” error, make sure docker is running). OKC connector support backfill event log with some flag

--from-block(uint64): Start backfill from specific block (For the first time run backfill. It should be the block when deploy smart contract)

--num-blocks(uint64): Number of blocks you want to backfill. If you want to crawl to the newest block you can skip this flag

Listening new event log

go run cmd/okc/main.go

Backfill mode You can use either or both flags

go run cmd/okc/main.go --from-block <blockNumber> --num-blocks <number>

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ABIs = map[string]string{
	"cOKC": cOKC.COKCABI,
}
View Source
var ContractAddresses = map[string]string{
	"cOKC": "0x1cC4D981e897A3D2E7785093A648c0a75fAd0453",
}

Functions

func GetAddresses

func GetAddresses(addresses map[string]string) []common.Address

func GetContracts

func GetContracts(addresses map[string]string) map[string]*Contract

Types

type Config

type Config struct {
	BlockchainName string
	FromBlock      uint64
	NumBlocks      uint64
}

type Connector

type Connector struct {
	*ethereum.Connector
	*Config
	// contains filtered or unexported fields
}

func New

func New(conf *Config) *Connector

func (*Connector) Start

func (c *Connector) Start()

type Contract

type Contract struct {
	ABI           *abi.ABI
	Name          string
	MessageParser ISmartContract
}

type ISmartContract

type ISmartContract interface {
	Message(eventName string, contractAbi *abi.ABI, vLog types.Log, timestamp *timestamppb.Timestamp) protoreflect.ProtoMessage
}

Directories

Path Synopsis
cmd
okc
smart-contracts

Jump to

Keyboard shortcuts

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