bsc

package
v0.0.0-...-03146ae Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NOTIFY_TYPE_NONE = iota
	NOTIFY_TYPE_TX
	NOTIFY_TYPE_ADMIN
)
View Source
const (
	TYPE_BLOCK_HASH = iota
	TYPE_TXN_HASH
)

Variables

View Source
var DEBUG = false
View Source
var MainABI = MainMetaData.ABI

MainABI is the input ABI used to generate the binding from. Deprecated: Use MainMetaData.ABI instead.

View Source
var MainMetaData = &bind.MetaData{
	ABI: "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[],\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"},{\"name\":\"_extraData\",\"type\":\"bytes\"}],\"name\":\"approveAndCall\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"address\"}],\"name\":\"spentAllowance\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialSupply\",\"type\":\"uint256\"},{\"name\":\"tokenName\",\"type\":\"string\"},{\"name\":\"decimalUnits\",\"type\":\"uint8\"},{\"name\":\"tokenSymbol\",\"type\":\"string\"}],\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"}]",
}

MainMetaData contains all meta data concerning the Main contract.

Functions

func GetAddressBalance

func GetAddressBalance(client *ethclient.Client, address string) (*big.Float, error)

func GetContractDestAddress

func GetContractDestAddress(data []byte) (common.Address, *big.Int, error)
func GetTransactionFrom(tx *types.Transaction) (common.Address, error) {
	var signer types.Signer

	signer = types.HomesteadSigner{}

	v, _, _ := tx.RawSignatureValues()

	if v.Sign() != 0 && tx.Protected() {
		signer = types.NewEIP155Signer(tx.ChainId())
	}

	msg, err := tx.AsMessage(signer)
	if err != nil {
		return common.Address{}, err
	}

	return msg.From(), nil
}

func GetSubscriptionMessage

func GetSubscriptionMessage(messageId int, subscription string) ([]byte, error)

func GetTransactionFrom

func GetTransactionFrom(tx *types.Transaction) (common.Address, error)

func IsAddress

func IsAddress(address string) bool

func Keccak256

func Keccak256(in []byte) []byte

func Prepend

func Prepend(in []byte, size int) []byte

func PrivateHexToAddress

func PrivateHexToAddress(private string) (string, error)

func PrivateKeyToAddress

func PrivateKeyToAddress(key *ecdsa.PrivateKey) (string, string)

func SendEthCoin

func SendEthCoin(client *ethclient.Client, amount *big.Int, private string, address string) (string, error)

func SendMessage

func SendMessage(c *websocket.Conn, messageId int, subscription string) (string, error)

Types

type BlockHeader

type BlockHeader struct {
	ParentHash string `json:"parentHash"`
	Difficulty string `json:"difficulty"`
	Number     string `json:"number"`
	GasLimit   string `json:"gasLimit"`
	GasUsed    string `json:"gasUsed"`
	Timestamp  string `json:"timestamp"`
	Hash       string `json:"hash"`
}

type BscClient

type BscClient struct {
	C        *ethclient.Client
	WSC      *websocket.Conn
	Cfg      *Config
	ABIs     map[string]abi.ABI
	ChStatus bool
	Ch       chan Transaction
	ChObj    chan ObjMessage
	//	ChNotify  chan NotifyMessage
	Mu        *sync.RWMutex
	Contracts map[string]Contract
	Ctx       context.Context
	CancelCtx context.CancelFunc
}

func Client

func Client(cfg *Config) (*BscClient, error)

func (*BscClient) GetContractData

func (c *BscClient) GetContractData(contract string) (*Contract, error)

func (*BscClient) GetERC20Decimals

func (c *BscClient) GetERC20Decimals(contractAddress string) (uint8, error)

func (*BscClient) GetERC20Name

func (c *BscClient) GetERC20Name(contractAddress string) (string, error)

func (*BscClient) GetERC20Symbol

func (c *BscClient) GetERC20Symbol(contractAddress string) (string, error)

func (*BscClient) Listener

func (c *BscClient) Listener()

func (*BscClient) ReadTransaction

func (c *BscClient) ReadTransaction(hashStr string) (NotifyMessage, error)

func (*BscClient) StartListener

func (c *BscClient) StartListener()

func (*BscClient) StartWs

func (c *BscClient) StartWs() error

func (*BscClient) StopListener

func (c *BscClient) StopListener()

type Config

type Config struct {
	BscHost   string
	BscPort   int
	BscWsPort int
	BscWsPath string
}

type Contract

type Contract struct {
	Decimals uint8
	Symbol   string
	Name     string
}

type Main

type Main struct {
	MainCaller     // Read-only binding to the contract
	MainTransactor // Write-only binding to the contract
	MainFilterer   // Log filterer for contract events
}

Main is an auto generated Go binding around an Ethereum contract.

func NewMain

func NewMain(address common.Address, backend bind.ContractBackend) (*Main, error)

NewMain creates a new instance of Main, bound to a specific deployed contract.

type MainCaller

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

MainCaller is an auto generated read-only Go binding around an Ethereum contract.

func NewMainCaller

func NewMainCaller(address common.Address, caller bind.ContractCaller) (*MainCaller, error)

NewMainCaller creates a new read-only instance of Main, bound to a specific deployed contract.

func (*MainCaller) Allowance

func (_Main *MainCaller) Allowance(opts *bind.CallOpts, arg0 common.Address, arg1 common.Address) (*big.Int, error)

Allowance is a free data retrieval call binding the contract method 0xdd62ed3e.

Solidity: function allowance(address , address ) returns(uint256)

func (*MainCaller) BalanceOf

func (_Main *MainCaller) BalanceOf(opts *bind.CallOpts, arg0 common.Address) (*big.Int, error)

BalanceOf is a free data retrieval call binding the contract method 0x70a08231.

Solidity: function balanceOf(address ) returns(uint256)

func (*MainCaller) Decimals

func (_Main *MainCaller) Decimals(opts *bind.CallOpts) (uint8, error)

Decimals is a free data retrieval call binding the contract method 0x313ce567.

Solidity: function decimals() returns(uint8)

func (*MainCaller) Name

func (_Main *MainCaller) Name(opts *bind.CallOpts) (string, error)

Name is a free data retrieval call binding the contract method 0x06fdde03.

Solidity: function name() returns(string)

func (*MainCaller) SpentAllowance

func (_Main *MainCaller) SpentAllowance(opts *bind.CallOpts, arg0 common.Address, arg1 common.Address) (*big.Int, error)

SpentAllowance is a free data retrieval call binding the contract method 0xdc3080f2.

Solidity: function spentAllowance(address , address ) returns(uint256)

func (*MainCaller) Symbol

func (_Main *MainCaller) Symbol(opts *bind.CallOpts) (string, error)

Symbol is a free data retrieval call binding the contract method 0x95d89b41.

Solidity: function symbol() returns(string)

type MainCallerRaw

type MainCallerRaw struct {
	Contract *MainCaller // Generic read-only contract binding to access the raw methods on
}

MainCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.

func (*MainCallerRaw) Call

func (_Main *MainCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error

Call invokes the (constant) contract method with params as input values and sets the output to result. The result type might be a single field for simple returns, a slice of interfaces for anonymous returns and a struct for named returns.

type MainCallerSession

type MainCallerSession struct {
	Contract *MainCaller   // Generic contract caller binding to set the session for
	CallOpts bind.CallOpts // Call options to use throughout this session
}

MainCallerSession is an auto generated read-only Go binding around an Ethereum contract, with pre-set call options.

func (*MainCallerSession) Allowance

func (_Main *MainCallerSession) Allowance(arg0 common.Address, arg1 common.Address) (*big.Int, error)

Allowance is a free data retrieval call binding the contract method 0xdd62ed3e.

Solidity: function allowance(address , address ) returns(uint256)

func (*MainCallerSession) BalanceOf

func (_Main *MainCallerSession) BalanceOf(arg0 common.Address) (*big.Int, error)

BalanceOf is a free data retrieval call binding the contract method 0x70a08231.

Solidity: function balanceOf(address ) returns(uint256)

func (*MainCallerSession) Decimals

func (_Main *MainCallerSession) Decimals() (uint8, error)

Decimals is a free data retrieval call binding the contract method 0x313ce567.

Solidity: function decimals() returns(uint8)

func (*MainCallerSession) Name

func (_Main *MainCallerSession) Name() (string, error)

Name is a free data retrieval call binding the contract method 0x06fdde03.

Solidity: function name() returns(string)

func (*MainCallerSession) SpentAllowance

func (_Main *MainCallerSession) SpentAllowance(arg0 common.Address, arg1 common.Address) (*big.Int, error)

SpentAllowance is a free data retrieval call binding the contract method 0xdc3080f2.

Solidity: function spentAllowance(address , address ) returns(uint256)

func (*MainCallerSession) Symbol

func (_Main *MainCallerSession) Symbol() (string, error)

Symbol is a free data retrieval call binding the contract method 0x95d89b41.

Solidity: function symbol() returns(string)

type MainFilterer

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

MainFilterer is an auto generated log filtering Go binding around an Ethereum contract events.

func NewMainFilterer

func NewMainFilterer(address common.Address, filterer bind.ContractFilterer) (*MainFilterer, error)

NewMainFilterer creates a new log filterer instance of Main, bound to a specific deployed contract.

func (*MainFilterer) FilterTransfer

func (_Main *MainFilterer) FilterTransfer(opts *bind.FilterOpts, from []common.Address, to []common.Address) (*MainTransferIterator, error)

FilterTransfer is a free log retrieval operation binding the contract event 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef.

Solidity: event Transfer(address indexed from, address indexed to, uint256 value)

func (*MainFilterer) ParseTransfer

func (_Main *MainFilterer) ParseTransfer(log types.Log) (*MainTransfer, error)

ParseTransfer is a log parse operation binding the contract event 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef.

Solidity: event Transfer(address indexed from, address indexed to, uint256 value)

func (*MainFilterer) WatchTransfer

func (_Main *MainFilterer) WatchTransfer(opts *bind.WatchOpts, sink chan<- *MainTransfer, from []common.Address, to []common.Address) (event.Subscription, error)

WatchTransfer is a free log subscription operation binding the contract event 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef.

Solidity: event Transfer(address indexed from, address indexed to, uint256 value)

type MainRaw

type MainRaw struct {
	Contract *Main // Generic contract binding to access the raw methods on
}

MainRaw is an auto generated low-level Go binding around an Ethereum contract.

func (*MainRaw) Call

func (_Main *MainRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error

Call invokes the (constant) contract method with params as input values and sets the output to result. The result type might be a single field for simple returns, a slice of interfaces for anonymous returns and a struct for named returns.

func (*MainRaw) Transact

func (_Main *MainRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error)

Transact invokes the (paid) contract method with params as input values.

func (*MainRaw) Transfer

func (_Main *MainRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error)

Transfer initiates a plain transaction to move funds to the contract, calling its default method if one is available.

type MainSession

type MainSession struct {
	Contract     *Main             // Generic contract binding to set the session for
	CallOpts     bind.CallOpts     // Call options to use throughout this session
	TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
}

MainSession is an auto generated Go binding around an Ethereum contract, with pre-set call and transact options.

func (*MainSession) Allowance

func (_Main *MainSession) Allowance(arg0 common.Address, arg1 common.Address) (*big.Int, error)

Allowance is a free data retrieval call binding the contract method 0xdd62ed3e.

Solidity: function allowance(address , address ) returns(uint256)

func (*MainSession) ApproveAndCall

func (_Main *MainSession) ApproveAndCall(_spender common.Address, _value *big.Int, _extraData []byte) (*types.Transaction, error)

ApproveAndCall is a paid mutator transaction binding the contract method 0xcae9ca51.

Solidity: function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns(bool success)

func (*MainSession) BalanceOf

func (_Main *MainSession) BalanceOf(arg0 common.Address) (*big.Int, error)

BalanceOf is a free data retrieval call binding the contract method 0x70a08231.

Solidity: function balanceOf(address ) returns(uint256)

func (*MainSession) Decimals

func (_Main *MainSession) Decimals() (uint8, error)

Decimals is a free data retrieval call binding the contract method 0x313ce567.

Solidity: function decimals() returns(uint8)

func (*MainSession) Name

func (_Main *MainSession) Name() (string, error)

Name is a free data retrieval call binding the contract method 0x06fdde03.

Solidity: function name() returns(string)

func (*MainSession) SpentAllowance

func (_Main *MainSession) SpentAllowance(arg0 common.Address, arg1 common.Address) (*big.Int, error)

SpentAllowance is a free data retrieval call binding the contract method 0xdc3080f2.

Solidity: function spentAllowance(address , address ) returns(uint256)

func (*MainSession) Symbol

func (_Main *MainSession) Symbol() (string, error)

Symbol is a free data retrieval call binding the contract method 0x95d89b41.

Solidity: function symbol() returns(string)

func (*MainSession) Transfer

func (_Main *MainSession) Transfer(_to common.Address, _value *big.Int) (*types.Transaction, error)

Transfer is a paid mutator transaction binding the contract method 0xa9059cbb.

Solidity: function transfer(address _to, uint256 _value) returns()

func (*MainSession) TransferFrom

func (_Main *MainSession) TransferFrom(_from common.Address, _to common.Address, _value *big.Int) (*types.Transaction, error)

TransferFrom is a paid mutator transaction binding the contract method 0x23b872dd.

Solidity: function transferFrom(address _from, address _to, uint256 _value) returns(bool success)

type MainTransactor

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

MainTransactor is an auto generated write-only Go binding around an Ethereum contract.

func NewMainTransactor

func NewMainTransactor(address common.Address, transactor bind.ContractTransactor) (*MainTransactor, error)

NewMainTransactor creates a new write-only instance of Main, bound to a specific deployed contract.

func (*MainTransactor) ApproveAndCall

func (_Main *MainTransactor) ApproveAndCall(opts *bind.TransactOpts, _spender common.Address, _value *big.Int, _extraData []byte) (*types.Transaction, error)

ApproveAndCall is a paid mutator transaction binding the contract method 0xcae9ca51.

Solidity: function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns(bool success)

func (*MainTransactor) Transfer

func (_Main *MainTransactor) Transfer(opts *bind.TransactOpts, _to common.Address, _value *big.Int) (*types.Transaction, error)

Transfer is a paid mutator transaction binding the contract method 0xa9059cbb.

Solidity: function transfer(address _to, uint256 _value) returns()

func (*MainTransactor) TransferFrom

func (_Main *MainTransactor) TransferFrom(opts *bind.TransactOpts, _from common.Address, _to common.Address, _value *big.Int) (*types.Transaction, error)

TransferFrom is a paid mutator transaction binding the contract method 0x23b872dd.

Solidity: function transferFrom(address _from, address _to, uint256 _value) returns(bool success)

type MainTransactorRaw

type MainTransactorRaw struct {
	Contract *MainTransactor // Generic write-only contract binding to access the raw methods on
}

MainTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.

func (*MainTransactorRaw) Transact

func (_Main *MainTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error)

Transact invokes the (paid) contract method with params as input values.

func (*MainTransactorRaw) Transfer

func (_Main *MainTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error)

Transfer initiates a plain transaction to move funds to the contract, calling its default method if one is available.

type MainTransactorSession

type MainTransactorSession struct {
	Contract     *MainTransactor   // Generic contract transactor binding to set the session for
	TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
}

MainTransactorSession is an auto generated write-only Go binding around an Ethereum contract, with pre-set transact options.

func (*MainTransactorSession) ApproveAndCall

func (_Main *MainTransactorSession) ApproveAndCall(_spender common.Address, _value *big.Int, _extraData []byte) (*types.Transaction, error)

ApproveAndCall is a paid mutator transaction binding the contract method 0xcae9ca51.

Solidity: function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns(bool success)

func (*MainTransactorSession) Transfer

func (_Main *MainTransactorSession) Transfer(_to common.Address, _value *big.Int) (*types.Transaction, error)

Transfer is a paid mutator transaction binding the contract method 0xa9059cbb.

Solidity: function transfer(address _to, uint256 _value) returns()

func (*MainTransactorSession) TransferFrom

func (_Main *MainTransactorSession) TransferFrom(_from common.Address, _to common.Address, _value *big.Int) (*types.Transaction, error)

TransferFrom is a paid mutator transaction binding the contract method 0x23b872dd.

Solidity: function transferFrom(address _from, address _to, uint256 _value) returns(bool success)

type MainTransfer

type MainTransfer struct {
	From  common.Address
	To    common.Address
	Value *big.Int
	Raw   types.Log // Blockchain specific contextual infos
}

MainTransfer represents a Transfer event raised by the Main contract.

type MainTransferIterator

type MainTransferIterator struct {
	Event *MainTransfer // Event containing the contract specifics and raw log
	// contains filtered or unexported fields
}

MainTransferIterator is returned from FilterTransfer and is used to iterate over the raw logs and unpacked data for Transfer events raised by the Main contract.

func (*MainTransferIterator) Close

func (it *MainTransferIterator) Close() error

Close terminates the iteration process, releasing any pending underlying resources.

func (*MainTransferIterator) Error

func (it *MainTransferIterator) Error() error

Error returns any retrieval or parsing error occurred during filtering.

func (*MainTransferIterator) Next

func (it *MainTransferIterator) Next() bool

Next advances the iterator to the subsequent event, returning whether there are any more events found. In case of a retrieval or parsing error, false is returned and Error() can be queried for the exact failure.

type NotifyMessage

type NotifyMessage struct {
	MessageType     int
	AddressFrom     string
	AddressTo       string
	Amount          *big.Int
	ContractAddress string
	IsPending       bool
	TxHash          string
}

func ParseTransaction

func ParseTransaction(tx *types.Transaction, isPending bool) (NotifyMessage, error)

func ReadBlock

func ReadBlock(client *ethclient.Client, hashStr string, number *big.Int) (*big.Int, []NotifyMessage, error)

type ObjMessage

type ObjMessage struct {
	Type   int
	Hash   string
	Number *big.Int
}

type Params

type Params struct {
	Subscription string      `json:"subscription"`
	Result       interface{} `json:"result"`
}

type ResponseMessage

type ResponseMessage struct {
	JsonRPC string `json:"jsonrpc"`
	Method  string `json:"method"`
	Params  Params `json:"params"`
}

type SubscriptionMessage

type SubscriptionMessage struct {
	JsonRpc string      `json:"jsonrpc"`
	Id      int         `json:"id"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params"`
}

type SubscriptionResponse

type SubscriptionResponse struct {
	Id     int    `json:"id"`
	Result string `json:"result"`
}

type Transaction

type Transaction struct {
	Type         int
	Raw          NotifyMessage
	TxId         string
	Contract     string
	Address      string
	AddressTo    string
	Amount       decimal.Decimal
	IsPending    bool
	ContractData *Contract
}

Jump to

Keyboard shortcuts

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