mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 11:20:45 +00:00
Add XDC contracts, Docker files, genesis, and hooks
Contracts added: - contracts/trc21issuer/ - TRC21 token standard - contracts/multisigwallet/ - Multi-signature wallet - contracts/XDCx/ - DEX contracts and relayer registration - contracts/blocksigner/contract/ - Block signer contract bindings - contracts/validator/contract/ - Validator contract bindings Docker support: - Dockerfile - Main XDC node build - Dockerfile.node - Full node with networking - Dockerfile.bootnode - Bootnode for network discovery - docker/ - Entrypoint scripts and config Genesis files: - genesis/mainnet.json - XDC mainnet genesis - genesis/testnet.json - XDC testnet genesis - genesis/devnet.json - Development network genesis - genesis/XDCxnet.json - XDCx DEX network genesis Infrastructure: - common/constants.go - XDC network constants - common/sort/ - Sorting utilities - eth/hooks/ - Consensus hook stubs - eth/util/ - Reward inflation utilities - contracts/utils.go - Contract utilities All packages compile successfully with go-ethereum v1.17
This commit is contained in:
parent
64defd91ef
commit
ba9854b28f
38 changed files with 19462 additions and 267 deletions
36
Dockerfile
36
Dockerfile
|
|
@ -1,33 +1,21 @@
|
|||
# Support setting various labels on the final image
|
||||
ARG COMMIT=""
|
||||
ARG VERSION=""
|
||||
ARG BUILDNUM=""
|
||||
FROM golang:1.23-alpine AS builder
|
||||
|
||||
# Build Geth in a stock Go builder container
|
||||
FROM golang:1.24-alpine AS builder
|
||||
|
||||
RUN apk add --no-cache gcc musl-dev linux-headers git
|
||||
|
||||
# Get dependencies - will also be cached if we won't change go.mod/go.sum
|
||||
COPY go.mod /go-ethereum/
|
||||
COPY go.sum /go-ethereum/
|
||||
RUN cd /go-ethereum && go mod download
|
||||
RUN apk add --no-cache make gcc musl-dev linux-headers git
|
||||
|
||||
ADD . /go-ethereum
|
||||
RUN cd /go-ethereum && go run build/ci.go install -static ./cmd/geth
|
||||
RUN cd /go-ethereum && make XDC
|
||||
|
||||
# Pull Geth into a second stage deploy alpine container
|
||||
FROM alpine:latest
|
||||
|
||||
RUN apk add --no-cache ca-certificates
|
||||
COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/
|
||||
WORKDIR /xdc
|
||||
|
||||
EXPOSE 8545 8546 30303 30303/udp
|
||||
ENTRYPOINT ["geth"]
|
||||
COPY --from=builder /go-ethereum/build/bin/XDC /usr/local/bin/XDC
|
||||
|
||||
# Add some metadata labels to help programmatic image consumption
|
||||
ARG COMMIT=""
|
||||
ARG VERSION=""
|
||||
ARG BUILDNUM=""
|
||||
RUN chmod +x /usr/local/bin/XDC
|
||||
|
||||
LABEL commit="$COMMIT" version="$VERSION" buildnum="$BUILDNUM"
|
||||
EXPOSE 8545
|
||||
EXPOSE 30303
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/XDC"]
|
||||
|
||||
CMD ["--help"]
|
||||
|
|
|
|||
24
Dockerfile.bootnode
Normal file
24
Dockerfile.bootnode
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
FROM golang:1.23-alpine AS builder
|
||||
|
||||
RUN apk add --no-cache make gcc musl-dev linux-headers
|
||||
|
||||
ADD . /go-ethereum
|
||||
RUN cd /go-ethereum && make bootnode
|
||||
|
||||
RUN chmod +x /go-ethereum/build/bin/bootnode
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
LABEL maintainer="xdc@xinfin.org"
|
||||
|
||||
WORKDIR /xdc
|
||||
|
||||
COPY --from=builder /go-ethereum/build/bin/bootnode /usr/local/bin/bootnode
|
||||
|
||||
COPY docker/bootnode ./
|
||||
|
||||
EXPOSE 30301
|
||||
|
||||
ENTRYPOINT ["./entrypoint.sh"]
|
||||
|
||||
CMD ["-verbosity", "6", "-nodekey", "bootnode.key", "--addr", ":30301"]
|
||||
37
Dockerfile.node
Normal file
37
Dockerfile.node
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
FROM golang:1.23-alpine AS builder
|
||||
|
||||
RUN apk add --no-cache make gcc musl-dev linux-headers git
|
||||
|
||||
ADD . /go-ethereum
|
||||
|
||||
RUN cd /go-ethereum \
|
||||
&& make XDC \
|
||||
&& chmod +x /go-ethereum/build/bin/XDC
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
WORKDIR /xdc
|
||||
|
||||
COPY --from=builder /go-ethereum/build/bin/XDC /usr/local/bin/XDC
|
||||
|
||||
ENV IDENTITY ''
|
||||
ENV PASSWORD ''
|
||||
ENV PRIVATE_KEY ''
|
||||
ENV BOOTNODES ''
|
||||
ENV EXTIP ''
|
||||
ENV VERBOSITY 3
|
||||
ENV SYNC_MODE 'full'
|
||||
ENV NETWORK_ID '50'
|
||||
ENV WS_SECRET ''
|
||||
ENV NETSTATS_HOST 'netstats-server'
|
||||
ENV NETSTATS_PORT '3000'
|
||||
ENV ANNOUNCE_TXS ''
|
||||
|
||||
RUN apk add --no-cache ca-certificates
|
||||
|
||||
COPY docker/XDPoSChain ./
|
||||
COPY genesis/ ./
|
||||
|
||||
EXPOSE 8545 8546 30303 30303/udp
|
||||
|
||||
ENTRYPOINT ["./entrypoint.sh"]
|
||||
23
common/constants.go
Normal file
23
common/constants.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// Notice: this file only saves const variables for all network.
|
||||
// Please run the following commands after modify this file:
|
||||
// cp common/constants.go common/constants/constants.go.testnet
|
||||
// cp common/constants.go common/constants/constants.go.devnet
|
||||
// cp common/constants.go common/constants/constants.go.local
|
||||
|
||||
package common
|
||||
|
||||
// const variables for all network (not redeclared in types.go)
|
||||
const (
|
||||
MaxMasternodes = 18
|
||||
LimitPenaltyEpoch = 4
|
||||
LimitPenaltyEpochV2 = 0
|
||||
LimitThresholdNonceInQueue = 10
|
||||
DefaultMinGasPrice = 250000000
|
||||
RangeReturnSigner = 150
|
||||
MinimunMinerBlockPerEpoch = 1
|
||||
BlocksPerYearTest = uint64(200000)
|
||||
BlocksPerYear = uint64(15768000)
|
||||
OneYear = uint64(365 * 86400)
|
||||
LiquidateLendingTradeBlock = uint64(100)
|
||||
LimitTimeFinality = uint64(30) // limit in 30 block
|
||||
)
|
||||
190
common/sort/slice.go
Normal file
190
common/sort/slice.go
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package sort
|
||||
|
||||
import "reflect"
|
||||
|
||||
// any is an alias for interface{} and is equivalent to interface{} in all ways.
|
||||
type any = interface{}
|
||||
|
||||
// lessSwap is a pair of Less and Swap function for use with the
|
||||
// auto-generated func-optimized variant of sort.go in
|
||||
// zfuncversion.go.
|
||||
type lessSwap struct {
|
||||
Less func(i, j int) bool
|
||||
Swap func(i, j int)
|
||||
}
|
||||
|
||||
// Slice sorts the slice x given the provided less function.
|
||||
// It panics if x is not a slice.
|
||||
//
|
||||
// The sort is not guaranteed to be stable: equal elements
|
||||
// may be reversed from their original order.
|
||||
// For a stable sort, use SliceStable.
|
||||
//
|
||||
// The less function must satisfy the same requirements as
|
||||
// the Interface type's Less method.
|
||||
func Slice(x any, less func(i, j int) bool) {
|
||||
rv := reflect.ValueOf(x)
|
||||
swap := reflect.Swapper(x)
|
||||
length := rv.Len()
|
||||
quickSort_func(lessSwap{less, swap}, 0, length, maxDepth(length))
|
||||
}
|
||||
|
||||
// maxDepth returns a threshold at which quicksort should switch
|
||||
// to heapsort. It returns 2*ceil(lg(n+1)).
|
||||
func maxDepth(n int) int {
|
||||
var depth int
|
||||
for i := n; i > 0; i >>= 1 {
|
||||
depth++
|
||||
}
|
||||
return depth * 2
|
||||
}
|
||||
|
||||
// Auto-generated variant of sort.go:quickSort
|
||||
func quickSort_func(data lessSwap, a, b, maxDepth int) {
|
||||
for b-a > 12 {
|
||||
if maxDepth == 0 {
|
||||
heapSort_func(data, a, b)
|
||||
return
|
||||
}
|
||||
maxDepth--
|
||||
mlo, mhi := doPivot_func(data, a, b)
|
||||
if mlo-a < b-mhi {
|
||||
quickSort_func(data, a, mlo, maxDepth)
|
||||
a = mhi
|
||||
} else {
|
||||
quickSort_func(data, mhi, b, maxDepth)
|
||||
b = mlo
|
||||
}
|
||||
}
|
||||
if b-a > 1 {
|
||||
for i := a + 6; i < b; i++ {
|
||||
if data.Less(i, i-6) {
|
||||
data.Swap(i, i-6)
|
||||
}
|
||||
}
|
||||
insertionSort_func(data, a, b)
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-generated variant of sort.go:heapSort
|
||||
func heapSort_func(data lessSwap, a, b int) {
|
||||
first := a
|
||||
lo := 0
|
||||
hi := b - a
|
||||
for i := (hi - 1) / 2; i >= 0; i-- {
|
||||
siftDown_func(data, i, hi, first)
|
||||
}
|
||||
for i := hi - 1; i >= 0; i-- {
|
||||
data.Swap(first, first+i)
|
||||
siftDown_func(data, lo, i, first)
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-generated variant of sort.go:doPivot
|
||||
func doPivot_func(data lessSwap, lo, hi int) (midlo, midhi int) {
|
||||
m := int(uint(lo+hi) >> 1)
|
||||
if hi-lo > 40 {
|
||||
s := (hi - lo) / 8
|
||||
medianOfThree_func(data, lo, lo+s, lo+2*s)
|
||||
medianOfThree_func(data, m, m-s, m+s)
|
||||
medianOfThree_func(data, hi-1, hi-1-s, hi-1-2*s)
|
||||
}
|
||||
medianOfThree_func(data, lo, m, hi-1)
|
||||
pivot := lo
|
||||
a, c := lo+1, hi-1
|
||||
for ; a < c && data.Less(a, pivot); a++ {
|
||||
}
|
||||
b := a
|
||||
for {
|
||||
for ; b < c && !data.Less(pivot, b); b++ {
|
||||
}
|
||||
for ; b < c && data.Less(pivot, c-1); c-- {
|
||||
}
|
||||
if b >= c {
|
||||
break
|
||||
}
|
||||
data.Swap(b, c-1)
|
||||
b++
|
||||
c--
|
||||
}
|
||||
protect := hi-c < 5
|
||||
if !protect && hi-c < (hi-lo)/4 {
|
||||
dups := 0
|
||||
if !data.Less(pivot, hi-1) {
|
||||
data.Swap(c, hi-1)
|
||||
c++
|
||||
dups++
|
||||
}
|
||||
if !data.Less(b-1, pivot) {
|
||||
b--
|
||||
dups++
|
||||
}
|
||||
if !data.Less(m, pivot) {
|
||||
data.Swap(m, b-1)
|
||||
b--
|
||||
dups++
|
||||
}
|
||||
protect = dups > 1
|
||||
}
|
||||
if protect {
|
||||
for {
|
||||
for ; a < b && !data.Less(b-1, pivot); b-- {
|
||||
}
|
||||
for ; a < b && data.Less(a, pivot); a++ {
|
||||
}
|
||||
if a >= b {
|
||||
break
|
||||
}
|
||||
data.Swap(a, b-1)
|
||||
a++
|
||||
b--
|
||||
}
|
||||
}
|
||||
data.Swap(pivot, b-1)
|
||||
return b - 1, c
|
||||
}
|
||||
|
||||
// Auto-generated variant of sort.go:insertionSort
|
||||
func insertionSort_func(data lessSwap, a, b int) {
|
||||
for i := a + 1; i < b; i++ {
|
||||
for j := i; j > a && data.Less(j, j-1); j-- {
|
||||
data.Swap(j, j-1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-generated variant of sort.go:siftDown
|
||||
func siftDown_func(data lessSwap, lo, hi, first int) {
|
||||
root := lo
|
||||
for {
|
||||
child := 2*root + 1
|
||||
if child >= hi {
|
||||
break
|
||||
}
|
||||
if child+1 < hi && data.Less(first+child, first+child+1) {
|
||||
child++
|
||||
}
|
||||
if !data.Less(first+root, first+child) {
|
||||
return
|
||||
}
|
||||
data.Swap(first+root, first+child)
|
||||
root = child
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-generated variant of sort.go:medianOfThree
|
||||
func medianOfThree_func(data lessSwap, m1, m0, m2 int) {
|
||||
if data.Less(m1, m0) {
|
||||
data.Swap(m1, m0)
|
||||
}
|
||||
if data.Less(m2, m1) {
|
||||
data.Swap(m2, m1)
|
||||
if data.Less(m1, m0) {
|
||||
data.Swap(m1, m0)
|
||||
}
|
||||
}
|
||||
}
|
||||
40
contracts/XDCx/XDCxListing.go
Normal file
40
contracts/XDCx/XDCxListing.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package XDCx
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/contracts/XDCx/contract"
|
||||
)
|
||||
|
||||
type XDCXListing struct {
|
||||
*contract.XDCXListingSession
|
||||
contractBackend bind.ContractBackend
|
||||
}
|
||||
|
||||
func NewMyXDCXListing(transactOpts *bind.TransactOpts, contractAddr common.Address, contractBackend bind.ContractBackend) (*XDCXListing, error) {
|
||||
smartContract, err := contract.NewXDCXListing(contractAddr, contractBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &XDCXListing{
|
||||
&contract.XDCXListingSession{
|
||||
Contract: smartContract,
|
||||
TransactOpts: *transactOpts,
|
||||
},
|
||||
contractBackend,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func DeployXDCXListing(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *XDCXListing, error) {
|
||||
contractAddr, _, _, err := contract.DeployXDCXListing(transactOpts, contractBackend)
|
||||
if err != nil {
|
||||
return contractAddr, nil, err
|
||||
}
|
||||
smartContract, err := NewMyXDCXListing(transactOpts, contractAddr, contractBackend)
|
||||
if err != nil {
|
||||
return contractAddr, nil, err
|
||||
}
|
||||
|
||||
return contractAddr, smartContract, nil
|
||||
}
|
||||
1327
contracts/XDCx/contract/LendingRegistration.go
Normal file
1327
contracts/XDCx/contract/LendingRegistration.go
Normal file
File diff suppressed because one or more lines are too long
2275
contracts/XDCx/contract/Registration.go
Normal file
2275
contracts/XDCx/contract/Registration.go
Normal file
File diff suppressed because one or more lines are too long
4716
contracts/XDCx/contract/TRC21.go
Normal file
4716
contracts/XDCx/contract/TRC21.go
Normal file
File diff suppressed because one or more lines are too long
775
contracts/XDCx/contract/TRC21Issuer.go
Normal file
775
contracts/XDCx/contract/TRC21Issuer.go
Normal file
|
|
@ -0,0 +1,775 @@
|
|||
// Code generated - DO NOT EDIT.
|
||||
// This file is a generated binding and any manual changes will be lost.
|
||||
|
||||
package contract
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"math/big"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// AbstractTokenTRC21ABI is the input ABI used to generate the binding from.
|
||||
const AbstractTokenTRC21ABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"issuer\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]"
|
||||
|
||||
// AbstractTokenTRC21Bin is the compiled bytecode used for deploying new contracts.
|
||||
const AbstractTokenTRC21Bin = `0x`
|
||||
|
||||
// DeployAbstractTokenTRC21 deploys a new Ethereum contract, binding an instance of AbstractTokenTRC21 to it.
|
||||
func DeployAbstractTokenTRC21(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *AbstractTokenTRC21, error) {
|
||||
parsed, err := abi.JSON(strings.NewReader(AbstractTokenTRC21ABI))
|
||||
if err != nil {
|
||||
return common.Address{}, nil, nil, err
|
||||
}
|
||||
address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(AbstractTokenTRC21Bin), backend)
|
||||
if err != nil {
|
||||
return common.Address{}, nil, nil, err
|
||||
}
|
||||
return address, tx, &AbstractTokenTRC21{AbstractTokenTRC21Caller: AbstractTokenTRC21Caller{contract: contract}, AbstractTokenTRC21Transactor: AbstractTokenTRC21Transactor{contract: contract}, AbstractTokenTRC21Filterer: AbstractTokenTRC21Filterer{contract: contract}}, nil
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21 is an auto generated Go binding around an Ethereum contract.
|
||||
type AbstractTokenTRC21 struct {
|
||||
AbstractTokenTRC21Caller // Read-only binding to the contract
|
||||
AbstractTokenTRC21Transactor // Write-only binding to the contract
|
||||
AbstractTokenTRC21Filterer // Log filterer for contract events
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21Caller is an auto generated read-only Go binding around an Ethereum contract.
|
||||
type AbstractTokenTRC21Caller struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21Transactor is an auto generated write-only Go binding around an Ethereum contract.
|
||||
type AbstractTokenTRC21Transactor struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21Filterer is an auto generated log filtering Go binding around an Ethereum contract events.
|
||||
type AbstractTokenTRC21Filterer struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21Session is an auto generated Go binding around an Ethereum contract,
|
||||
// with pre-set call and transact options.
|
||||
type AbstractTokenTRC21Session struct {
|
||||
Contract *AbstractTokenTRC21 // 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
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21CallerSession is an auto generated read-only Go binding around an Ethereum contract,
|
||||
// with pre-set call options.
|
||||
type AbstractTokenTRC21CallerSession struct {
|
||||
Contract *AbstractTokenTRC21Caller // Generic contract caller binding to set the session for
|
||||
CallOpts bind.CallOpts // Call options to use throughout this session
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21TransactorSession is an auto generated write-only Go binding around an Ethereum contract,
|
||||
// with pre-set transact options.
|
||||
type AbstractTokenTRC21TransactorSession struct {
|
||||
Contract *AbstractTokenTRC21Transactor // Generic contract transactor binding to set the session for
|
||||
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21Raw is an auto generated low-level Go binding around an Ethereum contract.
|
||||
type AbstractTokenTRC21Raw struct {
|
||||
Contract *AbstractTokenTRC21 // Generic contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21CallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
|
||||
type AbstractTokenTRC21CallerRaw struct {
|
||||
Contract *AbstractTokenTRC21Caller // Generic read-only contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21TransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
|
||||
type AbstractTokenTRC21TransactorRaw struct {
|
||||
Contract *AbstractTokenTRC21Transactor // Generic write-only contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// NewAbstractTokenTRC21 creates a new instance of AbstractTokenTRC21, bound to a specific deployed contract.
|
||||
func NewAbstractTokenTRC21(address common.Address, backend bind.ContractBackend) (*AbstractTokenTRC21, error) {
|
||||
contract, err := bindAbstractTokenTRC21(address, backend, backend, backend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &AbstractTokenTRC21{AbstractTokenTRC21Caller: AbstractTokenTRC21Caller{contract: contract}, AbstractTokenTRC21Transactor: AbstractTokenTRC21Transactor{contract: contract}, AbstractTokenTRC21Filterer: AbstractTokenTRC21Filterer{contract: contract}}, nil
|
||||
}
|
||||
|
||||
// NewAbstractTokenTRC21Caller creates a new read-only instance of AbstractTokenTRC21, bound to a specific deployed contract.
|
||||
func NewAbstractTokenTRC21Caller(address common.Address, caller bind.ContractCaller) (*AbstractTokenTRC21Caller, error) {
|
||||
contract, err := bindAbstractTokenTRC21(address, caller, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &AbstractTokenTRC21Caller{contract: contract}, nil
|
||||
}
|
||||
|
||||
// NewAbstractTokenTRC21Transactor creates a new write-only instance of AbstractTokenTRC21, bound to a specific deployed contract.
|
||||
func NewAbstractTokenTRC21Transactor(address common.Address, transactor bind.ContractTransactor) (*AbstractTokenTRC21Transactor, error) {
|
||||
contract, err := bindAbstractTokenTRC21(address, nil, transactor, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &AbstractTokenTRC21Transactor{contract: contract}, nil
|
||||
}
|
||||
|
||||
// NewAbstractTokenTRC21Filterer creates a new log filterer instance of AbstractTokenTRC21, bound to a specific deployed contract.
|
||||
func NewAbstractTokenTRC21Filterer(address common.Address, filterer bind.ContractFilterer) (*AbstractTokenTRC21Filterer, error) {
|
||||
contract, err := bindAbstractTokenTRC21(address, nil, nil, filterer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &AbstractTokenTRC21Filterer{contract: contract}, nil
|
||||
}
|
||||
|
||||
// bindAbstractTokenTRC21 binds a generic wrapper to an already deployed contract.
|
||||
func bindAbstractTokenTRC21(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) {
|
||||
parsed, err := abi.JSON(strings.NewReader(AbstractTokenTRC21ABI))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil
|
||||
}
|
||||
|
||||
// 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 (_AbstractTokenTRC21 *AbstractTokenTRC21Raw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
|
||||
return _AbstractTokenTRC21.Contract.AbstractTokenTRC21Caller.contract.Call(opts, result, method, params...)
|
||||
}
|
||||
|
||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
||||
// its default method if one is available.
|
||||
func (_AbstractTokenTRC21 *AbstractTokenTRC21Raw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _AbstractTokenTRC21.Contract.AbstractTokenTRC21Transactor.contract.Transfer(opts)
|
||||
}
|
||||
|
||||
// Transact invokes the (paid) contract method with params as input values.
|
||||
func (_AbstractTokenTRC21 *AbstractTokenTRC21Raw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
|
||||
return _AbstractTokenTRC21.Contract.AbstractTokenTRC21Transactor.contract.Transact(opts, method, params...)
|
||||
}
|
||||
|
||||
// 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 (_AbstractTokenTRC21 *AbstractTokenTRC21CallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
|
||||
return _AbstractTokenTRC21.Contract.contract.Call(opts, result, method, params...)
|
||||
}
|
||||
|
||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
||||
// its default method if one is available.
|
||||
func (_AbstractTokenTRC21 *AbstractTokenTRC21TransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _AbstractTokenTRC21.Contract.contract.Transfer(opts)
|
||||
}
|
||||
|
||||
// Transact invokes the (paid) contract method with params as input values.
|
||||
func (_AbstractTokenTRC21 *AbstractTokenTRC21TransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
|
||||
return _AbstractTokenTRC21.Contract.contract.Transact(opts, method, params...)
|
||||
}
|
||||
|
||||
// Issuer is a free data retrieval call binding the contract method 0x1d143848.
|
||||
//
|
||||
// Solidity: function issuer() constant returns(address)
|
||||
func (_AbstractTokenTRC21 *AbstractTokenTRC21Caller) Issuer(opts *bind.CallOpts) (common.Address, error) {
|
||||
var (
|
||||
ret0 = new(common.Address)
|
||||
)
|
||||
out := &[]interface{}{
|
||||
ret0,
|
||||
}
|
||||
err := _AbstractTokenTRC21.contract.Call(opts, out, "issuer")
|
||||
return *ret0, err
|
||||
}
|
||||
|
||||
// Issuer is a free data retrieval call binding the contract method 0x1d143848.
|
||||
//
|
||||
// Solidity: function issuer() constant returns(address)
|
||||
func (_AbstractTokenTRC21 *AbstractTokenTRC21Session) Issuer() (common.Address, error) {
|
||||
return _AbstractTokenTRC21.Contract.Issuer(&_AbstractTokenTRC21.CallOpts)
|
||||
}
|
||||
|
||||
// Issuer is a free data retrieval call binding the contract method 0x1d143848.
|
||||
//
|
||||
// Solidity: function issuer() constant returns(address)
|
||||
func (_AbstractTokenTRC21 *AbstractTokenTRC21CallerSession) Issuer() (common.Address, error) {
|
||||
return _AbstractTokenTRC21.Contract.Issuer(&_AbstractTokenTRC21.CallOpts)
|
||||
}
|
||||
|
||||
// TRC21IssuerABI is the input ABI used to generate the binding from.
|
||||
const TRC21IssuerABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"minCap\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"token\",\"type\":\"address\"}],\"name\":\"getTokenCapacity\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"tokens\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"token\",\"type\":\"address\"}],\"name\":\"apply\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"token\",\"type\":\"address\"}],\"name\":\"charge\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"value\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"issuer\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"token\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Apply\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"supporter\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"token\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Charge\",\"type\":\"event\"}]"
|
||||
|
||||
// TRC21IssuerBin is the compiled bytecode used for deploying new contracts.
|
||||
const TRC21IssuerBin = `0x608060405234801561001057600080fd5b506040516020806104578339810160405251600055610423806100346000396000f30060806040526004361061006c5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633fa615b081146100715780638f3a981c146100985780639d63848a146100b9578063c6b32f341461011e578063fc6bd76a14610134575b600080fd5b34801561007d57600080fd5b50610086610148565b60408051918252519081900360200190f35b3480156100a457600080fd5b50610086600160a060020a036004351661014e565b3480156100c557600080fd5b506100ce610169565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561010a5781810151838201526020016100f2565b505050509050019250505060405180910390f35b610132600160a060020a03600435166101cb565b005b610132600160a060020a036004351661035d565b60005490565b600160a060020a031660009081526002602052604090205490565b606060018054806020026020016040519081016040528092919081815260200182805480156101c157602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116101a3575b5050505050905090565b600081600160a060020a03811615156101e357600080fd5b6000543410156101f257600080fd5b82915033600160a060020a031682600160a060020a0316631d1438486040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b15801561025657600080fd5b505af115801561026a573d6000803e3d6000fd5b505050506040513d602081101561028057600080fd5b5051600160a060020a03161461029557600080fd5b600180548082019091557fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf601805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03851690811790915560009081526002602052604090205461030390346103de565b600160a060020a0384166000818152600260209081526040918290209390935580513481529051919233927f2d485624158277d5113a56388c3abf5c20e3511dd112123ba376d16b21e4d7169281900390910190a3505050565b600160a060020a038116600090815260026020526040902054610386903463ffffffff6103de16565b600160a060020a0382166000818152600260209081526040918290209390935580513481529051919233927f5cffac866325fd9b2a8ea8df2f110a0058313b279402d15ae28dd324a2282e069281900390910190a350565b6000828201838110156103f057600080fd5b93925050505600a165627a7a7230582005dc9504c7a156980fbaadfe03ffb20a475e65b947f9a8ef3e6d6beee52325a80029`
|
||||
|
||||
// DeployTRC21Issuer deploys a new Ethereum contract, binding an instance of TRC21Issuer to it.
|
||||
func DeployTRC21Issuer(auth *bind.TransactOpts, backend bind.ContractBackend, value *big.Int) (common.Address, *types.Transaction, *TRC21Issuer, error) {
|
||||
parsed, err := abi.JSON(strings.NewReader(TRC21IssuerABI))
|
||||
if err != nil {
|
||||
return common.Address{}, nil, nil, err
|
||||
}
|
||||
address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(TRC21IssuerBin), backend, value)
|
||||
if err != nil {
|
||||
return common.Address{}, nil, nil, err
|
||||
}
|
||||
return address, tx, &TRC21Issuer{TRC21IssuerCaller: TRC21IssuerCaller{contract: contract}, TRC21IssuerTransactor: TRC21IssuerTransactor{contract: contract}, TRC21IssuerFilterer: TRC21IssuerFilterer{contract: contract}}, nil
|
||||
}
|
||||
|
||||
// TRC21Issuer is an auto generated Go binding around an Ethereum contract.
|
||||
type TRC21Issuer struct {
|
||||
TRC21IssuerCaller // Read-only binding to the contract
|
||||
TRC21IssuerTransactor // Write-only binding to the contract
|
||||
TRC21IssuerFilterer // Log filterer for contract events
|
||||
}
|
||||
|
||||
// TRC21IssuerCaller is an auto generated read-only Go binding around an Ethereum contract.
|
||||
type TRC21IssuerCaller struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// TRC21IssuerTransactor is an auto generated write-only Go binding around an Ethereum contract.
|
||||
type TRC21IssuerTransactor struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// TRC21IssuerFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
|
||||
type TRC21IssuerFilterer struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// TRC21IssuerSession is an auto generated Go binding around an Ethereum contract,
|
||||
// with pre-set call and transact options.
|
||||
type TRC21IssuerSession struct {
|
||||
Contract *TRC21Issuer // 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
|
||||
}
|
||||
|
||||
// TRC21IssuerCallerSession is an auto generated read-only Go binding around an Ethereum contract,
|
||||
// with pre-set call options.
|
||||
type TRC21IssuerCallerSession struct {
|
||||
Contract *TRC21IssuerCaller // Generic contract caller binding to set the session for
|
||||
CallOpts bind.CallOpts // Call options to use throughout this session
|
||||
}
|
||||
|
||||
// TRC21IssuerTransactorSession is an auto generated write-only Go binding around an Ethereum contract,
|
||||
// with pre-set transact options.
|
||||
type TRC21IssuerTransactorSession struct {
|
||||
Contract *TRC21IssuerTransactor // Generic contract transactor binding to set the session for
|
||||
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
|
||||
}
|
||||
|
||||
// TRC21IssuerRaw is an auto generated low-level Go binding around an Ethereum contract.
|
||||
type TRC21IssuerRaw struct {
|
||||
Contract *TRC21Issuer // Generic contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// TRC21IssuerCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
|
||||
type TRC21IssuerCallerRaw struct {
|
||||
Contract *TRC21IssuerCaller // Generic read-only contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// TRC21IssuerTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
|
||||
type TRC21IssuerTransactorRaw struct {
|
||||
Contract *TRC21IssuerTransactor // Generic write-only contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// NewTRC21Issuer creates a new instance of TRC21Issuer, bound to a specific deployed contract.
|
||||
func NewTRC21Issuer(address common.Address, backend bind.ContractBackend) (*TRC21Issuer, error) {
|
||||
contract, err := bindTRC21Issuer(address, backend, backend, backend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &TRC21Issuer{TRC21IssuerCaller: TRC21IssuerCaller{contract: contract}, TRC21IssuerTransactor: TRC21IssuerTransactor{contract: contract}, TRC21IssuerFilterer: TRC21IssuerFilterer{contract: contract}}, nil
|
||||
}
|
||||
|
||||
// NewTRC21IssuerCaller creates a new read-only instance of TRC21Issuer, bound to a specific deployed contract.
|
||||
func NewTRC21IssuerCaller(address common.Address, caller bind.ContractCaller) (*TRC21IssuerCaller, error) {
|
||||
contract, err := bindTRC21Issuer(address, caller, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &TRC21IssuerCaller{contract: contract}, nil
|
||||
}
|
||||
|
||||
// NewTRC21IssuerTransactor creates a new write-only instance of TRC21Issuer, bound to a specific deployed contract.
|
||||
func NewTRC21IssuerTransactor(address common.Address, transactor bind.ContractTransactor) (*TRC21IssuerTransactor, error) {
|
||||
contract, err := bindTRC21Issuer(address, nil, transactor, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &TRC21IssuerTransactor{contract: contract}, nil
|
||||
}
|
||||
|
||||
// NewTRC21IssuerFilterer creates a new log filterer instance of TRC21Issuer, bound to a specific deployed contract.
|
||||
func NewTRC21IssuerFilterer(address common.Address, filterer bind.ContractFilterer) (*TRC21IssuerFilterer, error) {
|
||||
contract, err := bindTRC21Issuer(address, nil, nil, filterer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &TRC21IssuerFilterer{contract: contract}, nil
|
||||
}
|
||||
|
||||
// bindTRC21Issuer binds a generic wrapper to an already deployed contract.
|
||||
func bindTRC21Issuer(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) {
|
||||
parsed, err := abi.JSON(strings.NewReader(TRC21IssuerABI))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil
|
||||
}
|
||||
|
||||
// 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 (_TRC21Issuer *TRC21IssuerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
|
||||
return _TRC21Issuer.Contract.TRC21IssuerCaller.contract.Call(opts, result, method, params...)
|
||||
}
|
||||
|
||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
||||
// its default method if one is available.
|
||||
func (_TRC21Issuer *TRC21IssuerRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.Contract.TRC21IssuerTransactor.contract.Transfer(opts)
|
||||
}
|
||||
|
||||
// Transact invokes the (paid) contract method with params as input values.
|
||||
func (_TRC21Issuer *TRC21IssuerRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.Contract.TRC21IssuerTransactor.contract.Transact(opts, method, params...)
|
||||
}
|
||||
|
||||
// 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 (_TRC21Issuer *TRC21IssuerCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
|
||||
return _TRC21Issuer.Contract.contract.Call(opts, result, method, params...)
|
||||
}
|
||||
|
||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
||||
// its default method if one is available.
|
||||
func (_TRC21Issuer *TRC21IssuerTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.Contract.contract.Transfer(opts)
|
||||
}
|
||||
|
||||
// Transact invokes the (paid) contract method with params as input values.
|
||||
func (_TRC21Issuer *TRC21IssuerTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.Contract.contract.Transact(opts, method, params...)
|
||||
}
|
||||
|
||||
// GetTokenCapacity is a free data retrieval call binding the contract method 0x8f3a981c.
|
||||
//
|
||||
// Solidity: function getTokenCapacity(token address) constant returns(uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerCaller) GetTokenCapacity(opts *bind.CallOpts, token common.Address) (*big.Int, error) {
|
||||
var (
|
||||
ret0 = new(*big.Int)
|
||||
)
|
||||
out := &[]interface{}{
|
||||
ret0,
|
||||
}
|
||||
err := _TRC21Issuer.contract.Call(opts, out, "getTokenCapacity", token)
|
||||
return *ret0, err
|
||||
}
|
||||
|
||||
// GetTokenCapacity is a free data retrieval call binding the contract method 0x8f3a981c.
|
||||
//
|
||||
// Solidity: function getTokenCapacity(token address) constant returns(uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerSession) GetTokenCapacity(token common.Address) (*big.Int, error) {
|
||||
return _TRC21Issuer.Contract.GetTokenCapacity(&_TRC21Issuer.CallOpts, token)
|
||||
}
|
||||
|
||||
// GetTokenCapacity is a free data retrieval call binding the contract method 0x8f3a981c.
|
||||
//
|
||||
// Solidity: function getTokenCapacity(token address) constant returns(uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerCallerSession) GetTokenCapacity(token common.Address) (*big.Int, error) {
|
||||
return _TRC21Issuer.Contract.GetTokenCapacity(&_TRC21Issuer.CallOpts, token)
|
||||
}
|
||||
|
||||
// MinCap is a free data retrieval call binding the contract method 0x3fa615b0.
|
||||
//
|
||||
// Solidity: function minCap() constant returns(uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerCaller) MinCap(opts *bind.CallOpts) (*big.Int, error) {
|
||||
var (
|
||||
ret0 = new(*big.Int)
|
||||
)
|
||||
out := &[]interface{}{
|
||||
ret0,
|
||||
}
|
||||
err := _TRC21Issuer.contract.Call(opts, out, "minCap")
|
||||
return *ret0, err
|
||||
}
|
||||
|
||||
// MinCap is a free data retrieval call binding the contract method 0x3fa615b0.
|
||||
//
|
||||
// Solidity: function minCap() constant returns(uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerSession) MinCap() (*big.Int, error) {
|
||||
return _TRC21Issuer.Contract.MinCap(&_TRC21Issuer.CallOpts)
|
||||
}
|
||||
|
||||
// MinCap is a free data retrieval call binding the contract method 0x3fa615b0.
|
||||
//
|
||||
// Solidity: function minCap() constant returns(uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerCallerSession) MinCap() (*big.Int, error) {
|
||||
return _TRC21Issuer.Contract.MinCap(&_TRC21Issuer.CallOpts)
|
||||
}
|
||||
|
||||
// Tokens is a free data retrieval call binding the contract method 0x9d63848a.
|
||||
//
|
||||
// Solidity: function tokens() constant returns(address[])
|
||||
func (_TRC21Issuer *TRC21IssuerCaller) Tokens(opts *bind.CallOpts) ([]common.Address, error) {
|
||||
var (
|
||||
ret0 = new([]common.Address)
|
||||
)
|
||||
out := &[]interface{}{
|
||||
ret0,
|
||||
}
|
||||
err := _TRC21Issuer.contract.Call(opts, out, "tokens")
|
||||
return *ret0, err
|
||||
}
|
||||
|
||||
// Tokens is a free data retrieval call binding the contract method 0x9d63848a.
|
||||
//
|
||||
// Solidity: function tokens() constant returns(address[])
|
||||
func (_TRC21Issuer *TRC21IssuerSession) Tokens() ([]common.Address, error) {
|
||||
return _TRC21Issuer.Contract.Tokens(&_TRC21Issuer.CallOpts)
|
||||
}
|
||||
|
||||
// Tokens is a free data retrieval call binding the contract method 0x9d63848a.
|
||||
//
|
||||
// Solidity: function tokens() constant returns(address[])
|
||||
func (_TRC21Issuer *TRC21IssuerCallerSession) Tokens() ([]common.Address, error) {
|
||||
return _TRC21Issuer.Contract.Tokens(&_TRC21Issuer.CallOpts)
|
||||
}
|
||||
|
||||
// Apply is a paid mutator transaction binding the contract method 0xc6b32f34.
|
||||
//
|
||||
// Solidity: function apply(token address) returns()
|
||||
func (_TRC21Issuer *TRC21IssuerTransactor) Apply(opts *bind.TransactOpts, token common.Address) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.contract.Transact(opts, "apply", token)
|
||||
}
|
||||
|
||||
// Apply is a paid mutator transaction binding the contract method 0xc6b32f34.
|
||||
//
|
||||
// Solidity: function apply(token address) returns()
|
||||
func (_TRC21Issuer *TRC21IssuerSession) Apply(token common.Address) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.Contract.Apply(&_TRC21Issuer.TransactOpts, token)
|
||||
}
|
||||
|
||||
// Apply is a paid mutator transaction binding the contract method 0xc6b32f34.
|
||||
//
|
||||
// Solidity: function apply(token address) returns()
|
||||
func (_TRC21Issuer *TRC21IssuerTransactorSession) Apply(token common.Address) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.Contract.Apply(&_TRC21Issuer.TransactOpts, token)
|
||||
}
|
||||
|
||||
// Charge is a paid mutator transaction binding the contract method 0xfc6bd76a.
|
||||
//
|
||||
// Solidity: function charge(token address) returns()
|
||||
func (_TRC21Issuer *TRC21IssuerTransactor) Charge(opts *bind.TransactOpts, token common.Address) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.contract.Transact(opts, "charge", token)
|
||||
}
|
||||
|
||||
// Charge is a paid mutator transaction binding the contract method 0xfc6bd76a.
|
||||
//
|
||||
// Solidity: function charge(token address) returns()
|
||||
func (_TRC21Issuer *TRC21IssuerSession) Charge(token common.Address) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.Contract.Charge(&_TRC21Issuer.TransactOpts, token)
|
||||
}
|
||||
|
||||
// Charge is a paid mutator transaction binding the contract method 0xfc6bd76a.
|
||||
//
|
||||
// Solidity: function charge(token address) returns()
|
||||
func (_TRC21Issuer *TRC21IssuerTransactorSession) Charge(token common.Address) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.Contract.Charge(&_TRC21Issuer.TransactOpts, token)
|
||||
}
|
||||
|
||||
// TRC21IssuerApplyIterator is returned from FilterApply and is used to iterate over the raw logs and unpacked data for Apply events raised by the TRC21Issuer contract.
|
||||
type TRC21IssuerApplyIterator struct {
|
||||
Event *TRC21IssuerApply // Event containing the contract specifics and raw log
|
||||
|
||||
contract *bind.BoundContract // Generic contract to use for unpacking event data
|
||||
event string // Event name to use for unpacking event data
|
||||
|
||||
logs chan types.Log // Log channel receiving the found contract events
|
||||
sub ethereum.Subscription // Subscription for errors, completion and termination
|
||||
done bool // Whether the subscription completed delivering logs
|
||||
fail error // Occurred error to stop iteration
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (it *TRC21IssuerApplyIterator) Next() bool {
|
||||
// If the iterator failed, stop iterating
|
||||
if it.fail != nil {
|
||||
return false
|
||||
}
|
||||
// If the iterator completed, deliver directly whatever's available
|
||||
if it.done {
|
||||
select {
|
||||
case log := <-it.logs:
|
||||
it.Event = new(TRC21IssuerApply)
|
||||
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
|
||||
it.fail = err
|
||||
return false
|
||||
}
|
||||
it.Event.Raw = log
|
||||
return true
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
// Iterator still in progress, wait for either a data or an error event
|
||||
select {
|
||||
case log := <-it.logs:
|
||||
it.Event = new(TRC21IssuerApply)
|
||||
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
|
||||
it.fail = err
|
||||
return false
|
||||
}
|
||||
it.Event.Raw = log
|
||||
return true
|
||||
|
||||
case err := <-it.sub.Err():
|
||||
it.done = true
|
||||
it.fail = err
|
||||
return it.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// Error returns any retrieval or parsing error occurred during filtering.
|
||||
func (it *TRC21IssuerApplyIterator) Error() error {
|
||||
return it.fail
|
||||
}
|
||||
|
||||
// Close terminates the iteration process, releasing any pending underlying
|
||||
// resources.
|
||||
func (it *TRC21IssuerApplyIterator) Close() error {
|
||||
it.sub.Unsubscribe()
|
||||
return nil
|
||||
}
|
||||
|
||||
// TRC21IssuerApply represents a Apply event raised by the TRC21Issuer contract.
|
||||
type TRC21IssuerApply struct {
|
||||
Issuer common.Address
|
||||
Token common.Address
|
||||
Value *big.Int
|
||||
Raw types.Log // Blockchain specific contextual infos
|
||||
}
|
||||
|
||||
// FilterApply is a free log retrieval operation binding the contract event 0x2d485624158277d5113a56388c3abf5c20e3511dd112123ba376d16b21e4d716.
|
||||
//
|
||||
// Solidity: event Apply(issuer indexed address, token indexed address, value uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerFilterer) FilterApply(opts *bind.FilterOpts, issuer []common.Address, token []common.Address) (*TRC21IssuerApplyIterator, error) {
|
||||
|
||||
var issuerRule []interface{}
|
||||
for _, issuerItem := range issuer {
|
||||
issuerRule = append(issuerRule, issuerItem)
|
||||
}
|
||||
var tokenRule []interface{}
|
||||
for _, tokenItem := range token {
|
||||
tokenRule = append(tokenRule, tokenItem)
|
||||
}
|
||||
|
||||
logs, sub, err := _TRC21Issuer.contract.FilterLogs(opts, "Apply", issuerRule, tokenRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &TRC21IssuerApplyIterator{contract: _TRC21Issuer.contract, event: "Apply", logs: logs, sub: sub}, nil
|
||||
}
|
||||
|
||||
// WatchApply is a free log subscription operation binding the contract event 0x2d485624158277d5113a56388c3abf5c20e3511dd112123ba376d16b21e4d716.
|
||||
//
|
||||
// Solidity: event Apply(issuer indexed address, token indexed address, value uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerFilterer) WatchApply(opts *bind.WatchOpts, sink chan<- *TRC21IssuerApply, issuer []common.Address, token []common.Address) (event.Subscription, error) {
|
||||
|
||||
var issuerRule []interface{}
|
||||
for _, issuerItem := range issuer {
|
||||
issuerRule = append(issuerRule, issuerItem)
|
||||
}
|
||||
var tokenRule []interface{}
|
||||
for _, tokenItem := range token {
|
||||
tokenRule = append(tokenRule, tokenItem)
|
||||
}
|
||||
|
||||
logs, sub, err := _TRC21Issuer.contract.WatchLogs(opts, "Apply", issuerRule, tokenRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return event.NewSubscription(func(quit <-chan struct{}) error {
|
||||
defer sub.Unsubscribe()
|
||||
for {
|
||||
select {
|
||||
case log := <-logs:
|
||||
// New log arrived, parse the event and forward to the user
|
||||
event := new(TRC21IssuerApply)
|
||||
if err := _TRC21Issuer.contract.UnpackLog(event, "Apply", log); err != nil {
|
||||
return err
|
||||
}
|
||||
event.Raw = log
|
||||
|
||||
select {
|
||||
case sink <- event:
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-quit:
|
||||
return nil
|
||||
}
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-quit:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}), nil
|
||||
}
|
||||
|
||||
// TRC21IssuerChargeIterator is returned from FilterCharge and is used to iterate over the raw logs and unpacked data for Charge events raised by the TRC21Issuer contract.
|
||||
type TRC21IssuerChargeIterator struct {
|
||||
Event *TRC21IssuerCharge // Event containing the contract specifics and raw log
|
||||
|
||||
contract *bind.BoundContract // Generic contract to use for unpacking event data
|
||||
event string // Event name to use for unpacking event data
|
||||
|
||||
logs chan types.Log // Log channel receiving the found contract events
|
||||
sub ethereum.Subscription // Subscription for errors, completion and termination
|
||||
done bool // Whether the subscription completed delivering logs
|
||||
fail error // Occurred error to stop iteration
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (it *TRC21IssuerChargeIterator) Next() bool {
|
||||
// If the iterator failed, stop iterating
|
||||
if it.fail != nil {
|
||||
return false
|
||||
}
|
||||
// If the iterator completed, deliver directly whatever's available
|
||||
if it.done {
|
||||
select {
|
||||
case log := <-it.logs:
|
||||
it.Event = new(TRC21IssuerCharge)
|
||||
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
|
||||
it.fail = err
|
||||
return false
|
||||
}
|
||||
it.Event.Raw = log
|
||||
return true
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
// Iterator still in progress, wait for either a data or an error event
|
||||
select {
|
||||
case log := <-it.logs:
|
||||
it.Event = new(TRC21IssuerCharge)
|
||||
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
|
||||
it.fail = err
|
||||
return false
|
||||
}
|
||||
it.Event.Raw = log
|
||||
return true
|
||||
|
||||
case err := <-it.sub.Err():
|
||||
it.done = true
|
||||
it.fail = err
|
||||
return it.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// Error returns any retrieval or parsing error occurred during filtering.
|
||||
func (it *TRC21IssuerChargeIterator) Error() error {
|
||||
return it.fail
|
||||
}
|
||||
|
||||
// Close terminates the iteration process, releasing any pending underlying
|
||||
// resources.
|
||||
func (it *TRC21IssuerChargeIterator) Close() error {
|
||||
it.sub.Unsubscribe()
|
||||
return nil
|
||||
}
|
||||
|
||||
// TRC21IssuerCharge represents a Charge event raised by the TRC21Issuer contract.
|
||||
type TRC21IssuerCharge struct {
|
||||
Supporter common.Address
|
||||
Token common.Address
|
||||
Value *big.Int
|
||||
Raw types.Log // Blockchain specific contextual infos
|
||||
}
|
||||
|
||||
// FilterCharge is a free log retrieval operation binding the contract event 0x5cffac866325fd9b2a8ea8df2f110a0058313b279402d15ae28dd324a2282e06.
|
||||
//
|
||||
// Solidity: event Charge(supporter indexed address, token indexed address, value uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerFilterer) FilterCharge(opts *bind.FilterOpts, supporter []common.Address, token []common.Address) (*TRC21IssuerChargeIterator, error) {
|
||||
|
||||
var supporterRule []interface{}
|
||||
for _, supporterItem := range supporter {
|
||||
supporterRule = append(supporterRule, supporterItem)
|
||||
}
|
||||
var tokenRule []interface{}
|
||||
for _, tokenItem := range token {
|
||||
tokenRule = append(tokenRule, tokenItem)
|
||||
}
|
||||
|
||||
logs, sub, err := _TRC21Issuer.contract.FilterLogs(opts, "Charge", supporterRule, tokenRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &TRC21IssuerChargeIterator{contract: _TRC21Issuer.contract, event: "Charge", logs: logs, sub: sub}, nil
|
||||
}
|
||||
|
||||
// WatchCharge is a free log subscription operation binding the contract event 0x5cffac866325fd9b2a8ea8df2f110a0058313b279402d15ae28dd324a2282e06.
|
||||
//
|
||||
// Solidity: event Charge(supporter indexed address, token indexed address, value uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerFilterer) WatchCharge(opts *bind.WatchOpts, sink chan<- *TRC21IssuerCharge, supporter []common.Address, token []common.Address) (event.Subscription, error) {
|
||||
|
||||
var supporterRule []interface{}
|
||||
for _, supporterItem := range supporter {
|
||||
supporterRule = append(supporterRule, supporterItem)
|
||||
}
|
||||
var tokenRule []interface{}
|
||||
for _, tokenItem := range token {
|
||||
tokenRule = append(tokenRule, tokenItem)
|
||||
}
|
||||
|
||||
logs, sub, err := _TRC21Issuer.contract.WatchLogs(opts, "Charge", supporterRule, tokenRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return event.NewSubscription(func(quit <-chan struct{}) error {
|
||||
defer sub.Unsubscribe()
|
||||
for {
|
||||
select {
|
||||
case log := <-logs:
|
||||
// New log arrived, parse the event and forward to the user
|
||||
event := new(TRC21IssuerCharge)
|
||||
if err := _TRC21Issuer.contract.UnpackLog(event, "Charge", log); err != nil {
|
||||
return err
|
||||
}
|
||||
event.Raw = log
|
||||
|
||||
select {
|
||||
case sink <- event:
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-quit:
|
||||
return nil
|
||||
}
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-quit:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}), nil
|
||||
}
|
||||
251
contracts/XDCx/contract/XDCXListing.go
Normal file
251
contracts/XDCx/contract/XDCXListing.go
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
// Code generated - DO NOT EDIT.
|
||||
// This file is a generated binding and any manual changes will be lost.
|
||||
|
||||
package contract
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
)
|
||||
|
||||
// XDCXListingABI is the input ABI used to generate the binding from.
|
||||
const XDCXListingABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"tokens\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"token\",\"type\":\"address\"}],\"name\":\"getTokenStatus\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"token\",\"type\":\"address\"}],\"name\":\"apply\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"}]"
|
||||
|
||||
// XDCXListingBin is the compiled bytecode used for deploying new contracts.
|
||||
const XDCXListingBin = `0x608060405234801561001057600080fd5b506102be806100206000396000f3006080604052600436106100565763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416639d63848a811461005b578063a3ff31b5146100c0578063c6b32f34146100f5575b600080fd5b34801561006757600080fd5b5061007061010b565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156100ac578181015183820152602001610094565b505050509050019250505060405180910390f35b3480156100cc57600080fd5b506100e1600160a060020a036004351661016d565b604080519115158252519081900360200190f35b610109600160a060020a036004351661018b565b005b6060600080548060200260200160405190810160405280929190818152602001828054801561016357602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610145575b5050505050905090565b600160a060020a031660009081526001602052604090205460ff1690565b80600160a060020a03811615156101a157600080fd5b600160a060020a03811660009081526001602081905260409091205460ff16151514156101cd57600080fd5b683635c9adc5dea0000034146101e257600080fd5b6040516068903480156108fc02916000818181858888f1935050505015801561020f573d6000803e3d6000fd5b505060008054600180820183557f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563909101805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a039490941693841790556040805160208082018352838252948452919093529190209051815460ff19169015151790555600a165627a7a723058206d2dc0ce827743c25efa82f99e7830ade39d28e17f4d651573f89e0460a6626a0029`
|
||||
|
||||
// DeployXDCXListing deploys a new Ethereum contract, binding an instance of XDCXListing to it.
|
||||
func DeployXDCXListing(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *XDCXListing, error) {
|
||||
parsed, err := abi.JSON(strings.NewReader(XDCXListingABI))
|
||||
if err != nil {
|
||||
return common.Address{}, nil, nil, err
|
||||
}
|
||||
address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(XDCXListingBin), backend)
|
||||
if err != nil {
|
||||
return common.Address{}, nil, nil, err
|
||||
}
|
||||
return address, tx, &XDCXListing{XDCXListingCaller: XDCXListingCaller{contract: contract}, XDCXListingTransactor: XDCXListingTransactor{contract: contract}, XDCXListingFilterer: XDCXListingFilterer{contract: contract}}, nil
|
||||
}
|
||||
|
||||
// XDCXListing is an auto generated Go binding around an Ethereum contract.
|
||||
type XDCXListing struct {
|
||||
XDCXListingCaller // Read-only binding to the contract
|
||||
XDCXListingTransactor // Write-only binding to the contract
|
||||
XDCXListingFilterer // Log filterer for contract events
|
||||
}
|
||||
|
||||
// XDCXListingCaller is an auto generated read-only Go binding around an Ethereum contract.
|
||||
type XDCXListingCaller struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// XDCXListingTransactor is an auto generated write-only Go binding around an Ethereum contract.
|
||||
type XDCXListingTransactor struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// XDCXListingFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
|
||||
type XDCXListingFilterer struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// XDCXListingSession is an auto generated Go binding around an Ethereum contract,
|
||||
// with pre-set call and transact options.
|
||||
type XDCXListingSession struct {
|
||||
Contract *XDCXListing // 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
|
||||
}
|
||||
|
||||
// XDCXListingCallerSession is an auto generated read-only Go binding around an Ethereum contract,
|
||||
// with pre-set call options.
|
||||
type XDCXListingCallerSession struct {
|
||||
Contract *XDCXListingCaller // Generic contract caller binding to set the session for
|
||||
CallOpts bind.CallOpts // Call options to use throughout this session
|
||||
}
|
||||
|
||||
// XDCXListingTransactorSession is an auto generated write-only Go binding around an Ethereum contract,
|
||||
// with pre-set transact options.
|
||||
type XDCXListingTransactorSession struct {
|
||||
Contract *XDCXListingTransactor // Generic contract transactor binding to set the session for
|
||||
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
|
||||
}
|
||||
|
||||
// XDCXListingRaw is an auto generated low-level Go binding around an Ethereum contract.
|
||||
type XDCXListingRaw struct {
|
||||
Contract *XDCXListing // Generic contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// XDCXListingCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
|
||||
type XDCXListingCallerRaw struct {
|
||||
Contract *XDCXListingCaller // Generic read-only contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// XDCXListingTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
|
||||
type XDCXListingTransactorRaw struct {
|
||||
Contract *XDCXListingTransactor // Generic write-only contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// NewXDCXListing creates a new instance of XDCXListing, bound to a specific deployed contract.
|
||||
func NewXDCXListing(address common.Address, backend bind.ContractBackend) (*XDCXListing, error) {
|
||||
contract, err := bindXDCXListing(address, backend, backend, backend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &XDCXListing{XDCXListingCaller: XDCXListingCaller{contract: contract}, XDCXListingTransactor: XDCXListingTransactor{contract: contract}, XDCXListingFilterer: XDCXListingFilterer{contract: contract}}, nil
|
||||
}
|
||||
|
||||
// NewXDCXListingCaller creates a new read-only instance of XDCXListing, bound to a specific deployed contract.
|
||||
func NewXDCXListingCaller(address common.Address, caller bind.ContractCaller) (*XDCXListingCaller, error) {
|
||||
contract, err := bindXDCXListing(address, caller, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &XDCXListingCaller{contract: contract}, nil
|
||||
}
|
||||
|
||||
// NewXDCXListingTransactor creates a new write-only instance of XDCXListing, bound to a specific deployed contract.
|
||||
func NewXDCXListingTransactor(address common.Address, transactor bind.ContractTransactor) (*XDCXListingTransactor, error) {
|
||||
contract, err := bindXDCXListing(address, nil, transactor, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &XDCXListingTransactor{contract: contract}, nil
|
||||
}
|
||||
|
||||
// NewXDCXListingFilterer creates a new log filterer instance of XDCXListing, bound to a specific deployed contract.
|
||||
func NewXDCXListingFilterer(address common.Address, filterer bind.ContractFilterer) (*XDCXListingFilterer, error) {
|
||||
contract, err := bindXDCXListing(address, nil, nil, filterer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &XDCXListingFilterer{contract: contract}, nil
|
||||
}
|
||||
|
||||
// bindXDCXListing binds a generic wrapper to an already deployed contract.
|
||||
func bindXDCXListing(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) {
|
||||
parsed, err := abi.JSON(strings.NewReader(XDCXListingABI))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil
|
||||
}
|
||||
|
||||
// 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 (_XDCXListing *XDCXListingRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
|
||||
return _XDCXListing.Contract.XDCXListingCaller.contract.Call(opts, result, method, params...)
|
||||
}
|
||||
|
||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
||||
// its default method if one is available.
|
||||
func (_XDCXListing *XDCXListingRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _XDCXListing.Contract.XDCXListingTransactor.contract.Transfer(opts)
|
||||
}
|
||||
|
||||
// Transact invokes the (paid) contract method with params as input values.
|
||||
func (_XDCXListing *XDCXListingRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
|
||||
return _XDCXListing.Contract.XDCXListingTransactor.contract.Transact(opts, method, params...)
|
||||
}
|
||||
|
||||
// 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 (_XDCXListing *XDCXListingCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
|
||||
return _XDCXListing.Contract.contract.Call(opts, result, method, params...)
|
||||
}
|
||||
|
||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
||||
// its default method if one is available.
|
||||
func (_XDCXListing *XDCXListingTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _XDCXListing.Contract.contract.Transfer(opts)
|
||||
}
|
||||
|
||||
// Transact invokes the (paid) contract method with params as input values.
|
||||
func (_XDCXListing *XDCXListingTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
|
||||
return _XDCXListing.Contract.contract.Transact(opts, method, params...)
|
||||
}
|
||||
|
||||
// GetTokenStatus is a free data retrieval call binding the contract method 0xa3ff31b5.
|
||||
//
|
||||
// Solidity: function getTokenStatus(token address) constant returns(bool)
|
||||
func (_XDCXListing *XDCXListingCaller) GetTokenStatus(opts *bind.CallOpts, token common.Address) (bool, error) {
|
||||
var (
|
||||
ret0 = new(bool)
|
||||
)
|
||||
out := &[]interface{}{
|
||||
ret0,
|
||||
}
|
||||
err := _XDCXListing.contract.Call(opts, out, "getTokenStatus", token)
|
||||
return *ret0, err
|
||||
}
|
||||
|
||||
// GetTokenStatus is a free data retrieval call binding the contract method 0xa3ff31b5.
|
||||
//
|
||||
// Solidity: function getTokenStatus(token address) constant returns(bool)
|
||||
func (_XDCXListing *XDCXListingSession) GetTokenStatus(token common.Address) (bool, error) {
|
||||
return _XDCXListing.Contract.GetTokenStatus(&_XDCXListing.CallOpts, token)
|
||||
}
|
||||
|
||||
// GetTokenStatus is a free data retrieval call binding the contract method 0xa3ff31b5.
|
||||
//
|
||||
// Solidity: function getTokenStatus(token address) constant returns(bool)
|
||||
func (_XDCXListing *XDCXListingCallerSession) GetTokenStatus(token common.Address) (bool, error) {
|
||||
return _XDCXListing.Contract.GetTokenStatus(&_XDCXListing.CallOpts, token)
|
||||
}
|
||||
|
||||
// Tokens is a free data retrieval call binding the contract method 0x9d63848a.
|
||||
//
|
||||
// Solidity: function tokens() constant returns(address[])
|
||||
func (_XDCXListing *XDCXListingCaller) Tokens(opts *bind.CallOpts) ([]common.Address, error) {
|
||||
var (
|
||||
ret0 = new([]common.Address)
|
||||
)
|
||||
out := &[]interface{}{
|
||||
ret0,
|
||||
}
|
||||
err := _XDCXListing.contract.Call(opts, out, "tokens")
|
||||
return *ret0, err
|
||||
}
|
||||
|
||||
// Tokens is a free data retrieval call binding the contract method 0x9d63848a.
|
||||
//
|
||||
// Solidity: function tokens() constant returns(address[])
|
||||
func (_XDCXListing *XDCXListingSession) Tokens() ([]common.Address, error) {
|
||||
return _XDCXListing.Contract.Tokens(&_XDCXListing.CallOpts)
|
||||
}
|
||||
|
||||
// Tokens is a free data retrieval call binding the contract method 0x9d63848a.
|
||||
//
|
||||
// Solidity: function tokens() constant returns(address[])
|
||||
func (_XDCXListing *XDCXListingCallerSession) Tokens() ([]common.Address, error) {
|
||||
return _XDCXListing.Contract.Tokens(&_XDCXListing.CallOpts)
|
||||
}
|
||||
|
||||
// Apply is a paid mutator transaction binding the contract method 0xc6b32f34.
|
||||
//
|
||||
// Solidity: function apply(token address) returns()
|
||||
func (_XDCXListing *XDCXListingTransactor) Apply(opts *bind.TransactOpts, token common.Address) (*types.Transaction, error) {
|
||||
return _XDCXListing.contract.Transact(opts, "apply", token)
|
||||
}
|
||||
|
||||
// Apply is a paid mutator transaction binding the contract method 0xc6b32f34.
|
||||
//
|
||||
// Solidity: function apply(token address) returns()
|
||||
func (_XDCXListing *XDCXListingSession) Apply(token common.Address) (*types.Transaction, error) {
|
||||
return _XDCXListing.Contract.Apply(&_XDCXListing.TransactOpts, token)
|
||||
}
|
||||
|
||||
// Apply is a paid mutator transaction binding the contract method 0xc6b32f34.
|
||||
//
|
||||
// Solidity: function apply(token address) returns()
|
||||
func (_XDCXListing *XDCXListingTransactorSession) Apply(token common.Address) (*types.Transaction, error) {
|
||||
return _XDCXListing.Contract.Apply(&_XDCXListing.TransactOpts, token)
|
||||
}
|
||||
40
contracts/XDCx/lendingRelayerRegistration.go
Normal file
40
contracts/XDCx/lendingRelayerRegistration.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package XDCx
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/contracts/XDCx/contract"
|
||||
)
|
||||
|
||||
type LendingRelayerRegistration struct {
|
||||
*contract.LendingSession
|
||||
contractBackend bind.ContractBackend
|
||||
}
|
||||
|
||||
func NewLendingRelayerRegistration(transactOpts *bind.TransactOpts, contractAddr common.Address, contractBackend bind.ContractBackend) (*LendingRelayerRegistration, error) {
|
||||
smartContract, err := contract.NewLending(contractAddr, contractBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &LendingRelayerRegistration{
|
||||
&contract.LendingSession{
|
||||
Contract: smartContract,
|
||||
TransactOpts: *transactOpts,
|
||||
},
|
||||
contractBackend,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func DeployLendingRelayerRegistration(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, relayerAddr common.Address, XDCxListtingAddr common.Address) (common.Address, *LendingRelayerRegistration, error) {
|
||||
contractAddr, _, _, err := contract.DeployLending(transactOpts, contractBackend, relayerAddr, XDCxListtingAddr)
|
||||
if err != nil {
|
||||
return contractAddr, nil, err
|
||||
}
|
||||
smartContract, err := NewLendingRelayerRegistration(transactOpts, contractAddr, contractBackend)
|
||||
if err != nil {
|
||||
return contractAddr, nil, err
|
||||
}
|
||||
|
||||
return contractAddr, smartContract, nil
|
||||
}
|
||||
42
contracts/XDCx/relayerRegistration.go
Normal file
42
contracts/XDCx/relayerRegistration.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package XDCx
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/contracts/XDCx/contract"
|
||||
)
|
||||
|
||||
type RelayerRegistration struct {
|
||||
*contract.RelayerRegistrationSession
|
||||
contractBackend bind.ContractBackend
|
||||
}
|
||||
|
||||
func NewRelayerRegistration(transactOpts *bind.TransactOpts, contractAddr common.Address, contractBackend bind.ContractBackend) (*RelayerRegistration, error) {
|
||||
smartContract, err := contract.NewRelayerRegistration(contractAddr, contractBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &RelayerRegistration{
|
||||
&contract.RelayerRegistrationSession{
|
||||
Contract: smartContract,
|
||||
TransactOpts: *transactOpts,
|
||||
},
|
||||
contractBackend,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func DeployRelayerRegistration(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, XDCxListing common.Address, maxRelayers *big.Int, maxTokenList *big.Int, minDeposit *big.Int) (common.Address, *RelayerRegistration, error) {
|
||||
contractAddr, _, _, err := contract.DeployRelayerRegistration(transactOpts, contractBackend, XDCxListing, maxRelayers, maxTokenList, minDeposit)
|
||||
if err != nil {
|
||||
return contractAddr, nil, err
|
||||
}
|
||||
smartContract, err := NewRelayerRegistration(transactOpts, contractAddr, contractBackend)
|
||||
if err != nil {
|
||||
return contractAddr, nil, err
|
||||
}
|
||||
|
||||
return contractAddr, smartContract, nil
|
||||
}
|
||||
75
contracts/XDCx/simulation/constants.go
Normal file
75
contracts/XDCx/simulation/constants.go
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
package simulation
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"os"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
)
|
||||
|
||||
var (
|
||||
BaseXDC = big.NewInt(0).Mul(big.NewInt(10), big.NewInt(100000000000000000)) // 1 XDC
|
||||
RpcEndpoint = "http://127.0.0.1:8501/"
|
||||
MainKey, _ = crypto.HexToECDSA(os.Getenv("MAIN_ADDRESS_KEY"))
|
||||
MainAddr = crypto.PubkeyToAddress(MainKey.PublicKey) //0x17F2beD710ba50Ed27aEa52fc4bD7Bda5ED4a037
|
||||
|
||||
// TRC21 Token
|
||||
MinTRC21Apply = big.NewInt(0).Mul(big.NewInt(10), BaseXDC) // 10 XDC
|
||||
TRC21TokenCap = big.NewInt(0).Mul(big.NewInt(1000000000000), BaseXDC)
|
||||
TRC21TokenFee = big.NewInt(0)
|
||||
XDCXListingFee = big.NewInt(0).Mul(big.NewInt(1000), BaseXDC) // 1000 XDC
|
||||
|
||||
// XDCX
|
||||
MaxRelayers = big.NewInt(200)
|
||||
MaxTokenList = big.NewInt(200)
|
||||
MinDeposit = big.NewInt(0).Mul(big.NewInt(25000), BaseXDC) // 25000 XDC
|
||||
CollateralDepositRate = big.NewInt(150)
|
||||
CollateralLiquidationRate = big.NewInt(110)
|
||||
CollateralRecallRate = big.NewInt(200)
|
||||
TradeFee = uint16(10) // trade fee decimals 10^4
|
||||
LendingTradeFee = uint16(100) // lending trade fee decimals 10^4
|
||||
// 1m , 1d,7d,30d
|
||||
Terms = []*big.Int{big.NewInt(60), big.NewInt(86400), big.NewInt(7 * 86400), big.NewInt(30 * 86400)}
|
||||
RelayerCoinbaseKey, _ = crypto.HexToECDSA(os.Getenv("RELAYER_COINBASE_KEY")) //
|
||||
RelayerCoinbaseAddr = crypto.PubkeyToAddress(RelayerCoinbaseKey.PublicKey) // 0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e
|
||||
|
||||
OwnerRelayerKey, _ = crypto.HexToECDSA(os.Getenv("RELAYER_OWNER_KEY"))
|
||||
OwnerRelayerAddr = crypto.PubkeyToAddress(OwnerRelayerKey.PublicKey) //0x703c4b2bD70c169f5717101CaeE543299Fc946C7
|
||||
|
||||
XDCNative = common.HexToAddress("0x0000000000000000000000000000000000000001")
|
||||
|
||||
TokenNameList = []string{"BTC", "ETH", "XRP", "LTC", "BNB", "ADA", "ETC", "BCH", "EOS", "USDT"}
|
||||
TeamAddresses = []common.Address{
|
||||
common.HexToAddress("0x8fB1047e874d2e472cd08980FF8383053dd83102"), // MM team
|
||||
common.HexToAddress("0x9ca1514E3Dc4059C29a1608AE3a3E3fd35900888"), // MM team
|
||||
common.HexToAddress("0x15e08dE16f534c890828F2a0D935433aF5B3CE0C"), // CTO
|
||||
common.HexToAddress("0xb68D825655F2fE14C32558cDf950b45beF18D218"), // DEX team
|
||||
common.HexToAddress("0xF7349C253FF7747Df661296E0859c44e974fb52E"), // HaiDV
|
||||
common.HexToAddress("0x9f6b8fDD3733B099A91B6D70CDC7963ebBbd2684"), // Can
|
||||
common.HexToAddress("0x06605B28aab9835be75ca242a8aE58f2e15F2F45"), // Nien
|
||||
common.HexToAddress("0x33c2E732ae7dce8B05F37B2ba0CFe14c980c4Dbe"), // Vu Pham
|
||||
common.HexToAddress("0x16a73f3a64eca79e117258e66dfd7071cc8312a9"), // BTCXDC
|
||||
common.HexToAddress("0xac177441ac2237b2f79ecff1b8f6bca39e27ef9f"), // ETHXDC
|
||||
common.HexToAddress("0x4215250e55984c75bbce8ae639b86a6cad8ec126"), // XRPXDC
|
||||
common.HexToAddress("0x6b70ca959814866dd5c426d63d47dde9cc6c32d2"), // LTCXDC
|
||||
common.HexToAddress("0x33df079fe9b9cd7fb23a1085e4eaaa8eb6952cb3"), // BNBXDC
|
||||
common.HexToAddress("0x3cab8292137804688714670640d19f9d7a60c472"), // ADAXDC
|
||||
common.HexToAddress("0x9415d953d47c5f155cac9de7b24a756f352eafbf"), // ETCXDC
|
||||
common.HexToAddress("0xe32d2e7c8e8809e45c8e2332830b48d9e231e3f2"), // BCHXDC
|
||||
common.HexToAddress("0xf76ddbda664ea47088937e1cf9ff15036714dee3"), // EOSXDC
|
||||
common.HexToAddress("0xc465ee82440dada9509feb235c7cd7d896acf13c"), // ETHBTC
|
||||
common.HexToAddress("0xb95bdc136c579dc3fd2b2424a8e925a90228d2c2"), // XRPBTC
|
||||
common.HexToAddress("0xe36c1842365595D44854eEcd64B11c8115E133EF"), // USDXDC
|
||||
common.HexToAddress("0xaaC1959F6F0fb539F653409079Ec4146267B7555"), // BTCUSD
|
||||
common.HexToAddress("0x726DA688e2e09f01A2e1aB4c10F25B7CEdD4a0f3"), // ETHUSD
|
||||
common.HexToAddress("0xc70f010E8DB8bc436712A93D170C7c27Db1981Ea"), // rosetta-cli testing account
|
||||
}
|
||||
|
||||
Required = big.NewInt(2)
|
||||
Owners = []common.Address{
|
||||
common.HexToAddress("0x244e17B2141288a6F00E79E8feC2341f827d156f"),
|
||||
common.HexToAddress("0xd106159eC58BD2EAf5B62eF4e9cDb286170B0Bb9"),
|
||||
common.HexToAddress("0x0197BE034Bf0Bd2b3adDC84366a5681Bb7545888"),
|
||||
}
|
||||
)
|
||||
68
contracts/XDCx/testnet/constants.go
Normal file
68
contracts/XDCx/testnet/constants.go
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
package testnet
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"os"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
)
|
||||
|
||||
var (
|
||||
BaseXDC = big.NewInt(0).Mul(big.NewInt(10), big.NewInt(100000000000000000)) // 1 XDC
|
||||
RpcEndpoint = "http://127.0.0.1:8545/"
|
||||
MainKey, _ = crypto.HexToECDSA(os.Getenv("MAIN_ADDRESS_KEY"))
|
||||
MainAddr = crypto.PubkeyToAddress(MainKey.PublicKey) //0x17F2beD710ba50Ed27aEa52fc4bD7Bda5ED4a037
|
||||
|
||||
// TRC21 Token
|
||||
MinTRC21Apply = big.NewInt(0).Mul(big.NewInt(10), BaseXDC) // 10 XDC
|
||||
TRC21TokenCap = big.NewInt(0).Mul(big.NewInt(1000000000000), BaseXDC)
|
||||
TRC21TokenFee = big.NewInt(0)
|
||||
XDCXListingFee = big.NewInt(0).Mul(big.NewInt(1000), BaseXDC) // 1000 XDC
|
||||
|
||||
// XDCX
|
||||
MaxRelayers = big.NewInt(200)
|
||||
MaxTokenList = big.NewInt(200)
|
||||
MinDeposit = big.NewInt(0).Mul(big.NewInt(25000), BaseXDC) // 25000 XDC
|
||||
CollateralDepositRate = big.NewInt(150)
|
||||
CollateralLiquidationRate = big.NewInt(110)
|
||||
CollateralRecallRate = big.NewInt(200)
|
||||
TradeFee = uint16(10) // trade fee decimals 10^4
|
||||
LendingTradeFee = uint16(100) // lending trade fee decimals 10^4
|
||||
// 1m , 1d,7d,30d
|
||||
Terms = []*big.Int{big.NewInt(60), big.NewInt(86400), big.NewInt(7 * 86400), big.NewInt(30 * 86400)}
|
||||
RelayerCoinbaseKey, _ = crypto.HexToECDSA(os.Getenv("RELAYER_COINBASE_KEY")) //
|
||||
RelayerCoinbaseAddr = crypto.PubkeyToAddress(RelayerCoinbaseKey.PublicKey) // 0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e
|
||||
|
||||
OwnerRelayerKey, _ = crypto.HexToECDSA(os.Getenv("RELAYER_OWNER_KEY"))
|
||||
OwnerRelayerAddr = crypto.PubkeyToAddress(OwnerRelayerKey.PublicKey) //0x703c4b2bD70c169f5717101CaeE543299Fc946C7
|
||||
|
||||
XDCNative = common.HexToAddress("0x0000000000000000000000000000000000000001")
|
||||
|
||||
TokenNameList = []string{"BTC", "ETH", "XRP", "LTC", "BNB", "ADA", "ETC", "BCH", "EOS", "USDT"}
|
||||
TeamAddresses = []common.Address{
|
||||
common.HexToAddress("0xE3584D2D430eF34FF9fEeCBEBE6E0f6980082F05"), // Test1
|
||||
common.HexToAddress("0x16a73f3a64eca79e117258e66dfd7071cc8312a9"), // BTCXDC
|
||||
common.HexToAddress("0xac177441ac2237b2f79ecff1b8f6bca39e27ef9f"), // ETHXDC
|
||||
common.HexToAddress("0x4215250e55984c75bbce8ae639b86a6cad8ec126"), // XRPXDC
|
||||
common.HexToAddress("0x6b70ca959814866dd5c426d63d47dde9cc6c32d2"), // LTCXDC
|
||||
common.HexToAddress("0x33df079fe9b9cd7fb23a1085e4eaaa8eb6952cb3"), // BNBXDC
|
||||
common.HexToAddress("0x3cab8292137804688714670640d19f9d7a60c472"), // ADAXDC
|
||||
common.HexToAddress("0x9415d953d47c5f155cac9de7b24a756f352eafbf"), // ETCXDC
|
||||
common.HexToAddress("0xe32d2e7c8e8809e45c8e2332830b48d9e231e3f2"), // BCHXDC
|
||||
common.HexToAddress("0xf76ddbda664ea47088937e1cf9ff15036714dee3"), // EOSXDC
|
||||
common.HexToAddress("0xc465ee82440dada9509feb235c7cd7d896acf13c"), // ETHBTC
|
||||
common.HexToAddress("0xb95bdc136c579dc3fd2b2424a8e925a90228d2c2"), // XRPBTC
|
||||
common.HexToAddress("0xe36c1842365595D44854eEcd64B11c8115E133EF"), // XDCUSDT
|
||||
common.HexToAddress("0xaaC1959F6F0fb539F653409079Ec4146267B7555"), // BTCUSDT
|
||||
common.HexToAddress("0x726DA688e2e09f01A2e1aB4c10F25B7CEdD4a0f3"), // ETHUSDT
|
||||
|
||||
}
|
||||
|
||||
Required = big.NewInt(2)
|
||||
Owners = []common.Address{
|
||||
common.HexToAddress("0x244e17B2141288a6F00E79E8feC2341f827d156f"),
|
||||
common.HexToAddress("0xd106159eC58BD2EAf5B62eF4e9cDb286170B0Bb9"),
|
||||
common.HexToAddress("0x0197BE034Bf0Bd2b3adDC84366a5681Bb7545888"),
|
||||
}
|
||||
)
|
||||
41
contracts/XDCx/trc21.go
Normal file
41
contracts/XDCx/trc21.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package XDCx
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/contracts/XDCx/contract"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
type MyTRC21 struct {
|
||||
*contract.MyTRC21Session
|
||||
contractBackend bind.ContractBackend
|
||||
}
|
||||
|
||||
func NewTRC21(transactOpts *bind.TransactOpts, contractAddr common.Address, contractBackend bind.ContractBackend) (*MyTRC21, error) {
|
||||
smartContract, err := contract.NewMyTRC21(contractAddr, contractBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &MyTRC21{
|
||||
&contract.MyTRC21Session{
|
||||
Contract: smartContract,
|
||||
TransactOpts: *transactOpts,
|
||||
},
|
||||
contractBackend,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func DeployTRC21(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, owners []common.Address, required *big.Int, name string, symbol string, decimals uint8, cap, fee, depositFee, withdrawFee *big.Int) (common.Address, *MyTRC21, error) {
|
||||
contractAddr, _, _, err := contract.DeployMyTRC21(transactOpts, contractBackend, owners, required, name, symbol, decimals, cap, fee, depositFee, withdrawFee)
|
||||
if err != nil {
|
||||
return contractAddr, nil, err
|
||||
}
|
||||
smartContract, err := NewTRC21(transactOpts, contractAddr, contractBackend)
|
||||
if err != nil {
|
||||
return contractAddr, nil, err
|
||||
}
|
||||
|
||||
return contractAddr, smartContract, nil
|
||||
}
|
||||
41
contracts/XDCx/trc21Issuer.go
Normal file
41
contracts/XDCx/trc21Issuer.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package XDCx
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/contracts/XDCx/contract"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
type TRC21Issuer struct {
|
||||
*contract.TRC21IssuerSession
|
||||
contractBackend bind.ContractBackend
|
||||
}
|
||||
|
||||
func NewTRC21Issuer(transactOpts *bind.TransactOpts, contractAddr common.Address, contractBackend bind.ContractBackend) (*TRC21Issuer, error) {
|
||||
contractObject, err := contract.NewTRC21Issuer(contractAddr, contractBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &TRC21Issuer{
|
||||
&contract.TRC21IssuerSession{
|
||||
Contract: contractObject,
|
||||
TransactOpts: *transactOpts,
|
||||
},
|
||||
contractBackend,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func DeployTRC21Issuer(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, minApply *big.Int) (common.Address, *TRC21Issuer, error) {
|
||||
contractAddr, _, _, err := contract.DeployTRC21Issuer(transactOpts, contractBackend, minApply)
|
||||
if err != nil {
|
||||
return contractAddr, nil, err
|
||||
}
|
||||
contractObject, err := NewTRC21Issuer(transactOpts, contractAddr, contractBackend)
|
||||
if err != nil {
|
||||
return contractAddr, nil, err
|
||||
}
|
||||
|
||||
return contractAddr, contractObject, nil
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
// Copyright (c) 2018 XDPoSChain
|
||||
// Copyright 2024 The go-ethereum Authors
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
|
|
@ -14,77 +13,45 @@
|
|||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// Package blocksigner provides the XDC Network block signer contract interface.
|
||||
// The block signer contract is deployed at address 0x0000000000000000000000000000000000000089
|
||||
// and records block signatures for reward distribution.
|
||||
package blocksigner
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/contracts/blocksigner/contract"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// ContractAddress is the block signer contract address on XDC Network
|
||||
var ContractAddress = common.HexToAddress("0x0000000000000000000000000000000000000089")
|
||||
|
||||
// BlockSignerInfo contains information about a block signature
|
||||
type BlockSignerInfo struct {
|
||||
BlockNumber *big.Int
|
||||
BlockHash common.Hash
|
||||
Signer common.Address
|
||||
type BlockSigner struct {
|
||||
*contract.BlockSignerSession
|
||||
contractBackend bind.ContractBackend
|
||||
}
|
||||
|
||||
// SignMethodID is the method ID for sign(uint256,bytes32) function
|
||||
// keccak256("sign(uint256,bytes32)")[:4]
|
||||
var SignMethodID = []byte{0x44, 0x00, 0x8f, 0x05}
|
||||
|
||||
// GetSignersMethodID is the method ID for getSigners(uint256) function
|
||||
// keccak256("getSigners(uint256)")[:4]
|
||||
var GetSignersMethodID = []byte{0xe7, 0xec, 0x6a, 0xef}
|
||||
|
||||
// EncodeSign encodes the sign(uint256,bytes32) call
|
||||
func EncodeSign(blockNumber *big.Int, blockHash common.Hash) []byte {
|
||||
data := make([]byte, 4+64)
|
||||
copy(data[:4], SignMethodID)
|
||||
|
||||
// Encode block number (uint256)
|
||||
blockNumBytes := blockNumber.Bytes()
|
||||
copy(data[4+32-len(blockNumBytes):4+32], blockNumBytes)
|
||||
|
||||
// Encode block hash (bytes32)
|
||||
copy(data[4+32:], blockHash.Bytes())
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
// EncodeGetSigners encodes the getSigners(uint256) call
|
||||
func EncodeGetSigners(blockNumber *big.Int) []byte {
|
||||
data := make([]byte, 4+32)
|
||||
copy(data[:4], GetSignersMethodID)
|
||||
|
||||
// Encode block number (uint256)
|
||||
blockNumBytes := blockNumber.Bytes()
|
||||
copy(data[4+32-len(blockNumBytes):4+32], blockNumBytes)
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
// DecodeSigners decodes a list of signer addresses from contract return data
|
||||
func DecodeSigners(data []byte) ([]common.Address, error) {
|
||||
if len(data) < 64 {
|
||||
return nil, nil
|
||||
func NewBlockSigner(transactOpts *bind.TransactOpts, contractAddr common.Address, contractBackend bind.ContractBackend) (*BlockSigner, error) {
|
||||
blockSigner, err := contract.NewBlockSigner(contractAddr, contractBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Skip offset (32 bytes) and get length
|
||||
length := new(big.Int).SetBytes(data[32:64]).Uint64()
|
||||
signers := make([]common.Address, 0, length)
|
||||
|
||||
offset := 64
|
||||
for i := uint64(0); i < length && offset+32 <= len(data); i++ {
|
||||
var addr common.Address
|
||||
copy(addr[:], data[offset+12:offset+32])
|
||||
signers = append(signers, addr)
|
||||
offset += 32
|
||||
}
|
||||
return signers, nil
|
||||
|
||||
return &BlockSigner{
|
||||
&contract.BlockSignerSession{
|
||||
Contract: blockSigner,
|
||||
TransactOpts: *transactOpts,
|
||||
},
|
||||
contractBackend,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func DeployBlockSigner(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, epochNumber *big.Int) (common.Address, *BlockSigner, error) {
|
||||
blockSignerAddr, _, _, err := contract.DeployBlockSigner(transactOpts, contractBackend, epochNumber)
|
||||
if err != nil {
|
||||
return blockSignerAddr, nil, err
|
||||
}
|
||||
|
||||
blockSigner, err := NewBlockSigner(transactOpts, blockSignerAddr, contractBackend)
|
||||
if err != nil {
|
||||
return blockSignerAddr, nil, err
|
||||
}
|
||||
|
||||
return blockSignerAddr, blockSigner, nil
|
||||
}
|
||||
|
|
|
|||
539
contracts/blocksigner/contract/blocksigner.go
Normal file
539
contracts/blocksigner/contract/blocksigner.go
Normal file
|
|
@ -0,0 +1,539 @@
|
|||
// Code generated - DO NOT EDIT.
|
||||
// This file is a generated binding and any manual changes will be lost.
|
||||
|
||||
package contract
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"strings"
|
||||
|
||||
ethereum "github.com/ethereum/go-ethereum"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
)
|
||||
|
||||
// BlockSignerABI is the input ABI used to generate the binding from.
|
||||
const BlockSignerABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_blockNumber\",\"type\":\"uint256\"},{\"name\":\"_blockHash\",\"type\":\"bytes32\"}],\"name\":\"sign\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_blockHash\",\"type\":\"bytes32\"}],\"name\":\"getSigners\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"epochNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_epochNumber\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_signer\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_blockNumber\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_blockHash\",\"type\":\"bytes32\"}],\"name\":\"Sign\",\"type\":\"event\"}]"
|
||||
|
||||
// BlockSignerBin is the compiled bytecode used for deploying new contracts.
|
||||
const BlockSignerBin = `0x6060604052341561000f57600080fd5b604051602080610386833981016040528080516002555050610350806100366000396000f3006060604052600436106100565763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663e341eaa4811461005b578063e7ec6aef14610076578063f4145a83146100df575b600080fd5b341561006657600080fd5b610074600435602435610104565b005b341561008157600080fd5b61008c600435610227565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156100cb5780820151838201526020016100b3565b505050509050019250505060405180910390f35b34156100ea57600080fd5b6100f26102ac565b60405190815260200160405180910390f35b438290101561011257600080fd5b600280546101289184910263ffffffff6102b216565b43111561013457600080fd5b600082815260016020819052604090912080549091810161015583826102c8565b5060009182526020808320919091018390558282528190526040902080546001810161018183826102c8565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19163373ffffffffffffffffffffffffffffffffffffffff8116919091179091557f62855fa22e051687c32ac285857751f6d3f2c100c72756d8d30cb7ecb1f64f5490838360405173ffffffffffffffffffffffffffffffffffffffff909316835260208301919091526040808301919091526060909101905180910390a15050565b61022f6102f1565b600082815260208181526040918290208054909290918281020190519081016040528092919081815260200182805480156102a057602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311610275575b50505050509050919050565b60025481565b6000828201838110156102c157fe5b9392505050565b8154818355818115116102ec576000838152602090206102ec918101908301610303565b505050565b60206040519081016040526000815290565b61032191905b8082111561031d5760008155600101610309565b5090565b905600a165627a7a72305820a8ceddaea8e4ae00991e2ae81c8c88e160dd8770f255523282c24c2df4c30ec70029`
|
||||
|
||||
// DeployBlockSigner deploys a new Ethereum contract, binding an instance of BlockSigner to it.
|
||||
func DeployBlockSigner(auth *bind.TransactOpts, backend bind.ContractBackend, _epochNumber *big.Int) (common.Address, *types.Transaction, *BlockSigner, error) {
|
||||
parsed, err := abi.JSON(strings.NewReader(BlockSignerABI))
|
||||
if err != nil {
|
||||
return common.Address{}, nil, nil, err
|
||||
}
|
||||
address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(BlockSignerBin), backend, _epochNumber)
|
||||
if err != nil {
|
||||
return common.Address{}, nil, nil, err
|
||||
}
|
||||
return address, tx, &BlockSigner{BlockSignerCaller: BlockSignerCaller{contract: contract}, BlockSignerTransactor: BlockSignerTransactor{contract: contract}, BlockSignerFilterer: BlockSignerFilterer{contract: contract}}, nil
|
||||
}
|
||||
|
||||
// BlockSigner is an auto generated Go binding around an Ethereum contract.
|
||||
type BlockSigner struct {
|
||||
BlockSignerCaller // Read-only binding to the contract
|
||||
BlockSignerTransactor // Write-only binding to the contract
|
||||
BlockSignerFilterer // Log filterer for contract events
|
||||
}
|
||||
|
||||
// BlockSignerCaller is an auto generated read-only Go binding around an Ethereum contract.
|
||||
type BlockSignerCaller struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// BlockSignerTransactor is an auto generated write-only Go binding around an Ethereum contract.
|
||||
type BlockSignerTransactor struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// BlockSignerFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
|
||||
type BlockSignerFilterer struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// BlockSignerSession is an auto generated Go binding around an Ethereum contract,
|
||||
// with pre-set call and transact options.
|
||||
type BlockSignerSession struct {
|
||||
Contract *BlockSigner // 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
|
||||
}
|
||||
|
||||
// BlockSignerCallerSession is an auto generated read-only Go binding around an Ethereum contract,
|
||||
// with pre-set call options.
|
||||
type BlockSignerCallerSession struct {
|
||||
Contract *BlockSignerCaller // Generic contract caller binding to set the session for
|
||||
CallOpts bind.CallOpts // Call options to use throughout this session
|
||||
}
|
||||
|
||||
// BlockSignerTransactorSession is an auto generated write-only Go binding around an Ethereum contract,
|
||||
// with pre-set transact options.
|
||||
type BlockSignerTransactorSession struct {
|
||||
Contract *BlockSignerTransactor // Generic contract transactor binding to set the session for
|
||||
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
|
||||
}
|
||||
|
||||
// BlockSignerRaw is an auto generated low-level Go binding around an Ethereum contract.
|
||||
type BlockSignerRaw struct {
|
||||
Contract *BlockSigner // Generic contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// BlockSignerCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
|
||||
type BlockSignerCallerRaw struct {
|
||||
Contract *BlockSignerCaller // Generic read-only contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// BlockSignerTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
|
||||
type BlockSignerTransactorRaw struct {
|
||||
Contract *BlockSignerTransactor // Generic write-only contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// NewBlockSigner creates a new instance of BlockSigner, bound to a specific deployed contract.
|
||||
func NewBlockSigner(address common.Address, backend bind.ContractBackend) (*BlockSigner, error) {
|
||||
contract, err := bindBlockSigner(address, backend, backend, backend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &BlockSigner{BlockSignerCaller: BlockSignerCaller{contract: contract}, BlockSignerTransactor: BlockSignerTransactor{contract: contract}, BlockSignerFilterer: BlockSignerFilterer{contract: contract}}, nil
|
||||
}
|
||||
|
||||
// NewBlockSignerCaller creates a new read-only instance of BlockSigner, bound to a specific deployed contract.
|
||||
func NewBlockSignerCaller(address common.Address, caller bind.ContractCaller) (*BlockSignerCaller, error) {
|
||||
contract, err := bindBlockSigner(address, caller, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &BlockSignerCaller{contract: contract}, nil
|
||||
}
|
||||
|
||||
// NewBlockSignerTransactor creates a new write-only instance of BlockSigner, bound to a specific deployed contract.
|
||||
func NewBlockSignerTransactor(address common.Address, transactor bind.ContractTransactor) (*BlockSignerTransactor, error) {
|
||||
contract, err := bindBlockSigner(address, nil, transactor, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &BlockSignerTransactor{contract: contract}, nil
|
||||
}
|
||||
|
||||
// NewBlockSignerFilterer creates a new log filterer instance of BlockSigner, bound to a specific deployed contract.
|
||||
func NewBlockSignerFilterer(address common.Address, filterer bind.ContractFilterer) (*BlockSignerFilterer, error) {
|
||||
contract, err := bindBlockSigner(address, nil, nil, filterer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &BlockSignerFilterer{contract: contract}, nil
|
||||
}
|
||||
|
||||
// bindBlockSigner binds a generic wrapper to an already deployed contract.
|
||||
func bindBlockSigner(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) {
|
||||
parsed, err := abi.JSON(strings.NewReader(BlockSignerABI))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil
|
||||
}
|
||||
|
||||
// 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 (_BlockSigner *BlockSignerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
|
||||
return _BlockSigner.Contract.BlockSignerCaller.contract.Call(opts, result, method, params...)
|
||||
}
|
||||
|
||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
||||
// its default method if one is available.
|
||||
func (_BlockSigner *BlockSignerRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _BlockSigner.Contract.BlockSignerTransactor.contract.Transfer(opts)
|
||||
}
|
||||
|
||||
// Transact invokes the (paid) contract method with params as input values.
|
||||
func (_BlockSigner *BlockSignerRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
|
||||
return _BlockSigner.Contract.BlockSignerTransactor.contract.Transact(opts, method, params...)
|
||||
}
|
||||
|
||||
// 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 (_BlockSigner *BlockSignerCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
|
||||
return _BlockSigner.Contract.contract.Call(opts, result, method, params...)
|
||||
}
|
||||
|
||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
||||
// its default method if one is available.
|
||||
func (_BlockSigner *BlockSignerTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _BlockSigner.Contract.contract.Transfer(opts)
|
||||
}
|
||||
|
||||
// Transact invokes the (paid) contract method with params as input values.
|
||||
func (_BlockSigner *BlockSignerTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
|
||||
return _BlockSigner.Contract.contract.Transact(opts, method, params...)
|
||||
}
|
||||
|
||||
// EpochNumber is a free data retrieval call binding the contract method 0xf4145a83.
|
||||
//
|
||||
// Solidity: function epochNumber() constant returns(uint256)
|
||||
func (_BlockSigner *BlockSignerCaller) EpochNumber(opts *bind.CallOpts) (*big.Int, error) {
|
||||
var (
|
||||
ret0 = new(*big.Int)
|
||||
)
|
||||
out := &[]interface{}{
|
||||
ret0,
|
||||
}
|
||||
err := _BlockSigner.contract.Call(opts, out, "epochNumber")
|
||||
return *ret0, err
|
||||
}
|
||||
|
||||
// EpochNumber is a free data retrieval call binding the contract method 0xf4145a83.
|
||||
//
|
||||
// Solidity: function epochNumber() constant returns(uint256)
|
||||
func (_BlockSigner *BlockSignerSession) EpochNumber() (*big.Int, error) {
|
||||
return _BlockSigner.Contract.EpochNumber(&_BlockSigner.CallOpts)
|
||||
}
|
||||
|
||||
// EpochNumber is a free data retrieval call binding the contract method 0xf4145a83.
|
||||
//
|
||||
// Solidity: function epochNumber() constant returns(uint256)
|
||||
func (_BlockSigner *BlockSignerCallerSession) EpochNumber() (*big.Int, error) {
|
||||
return _BlockSigner.Contract.EpochNumber(&_BlockSigner.CallOpts)
|
||||
}
|
||||
|
||||
// GetSigners is a free data retrieval call binding the contract method 0xe7ec6aef.
|
||||
//
|
||||
// Solidity: function getSigners(_blockHash bytes32) constant returns(address[])
|
||||
func (_BlockSigner *BlockSignerCaller) GetSigners(opts *bind.CallOpts, _blockHash [32]byte) ([]common.Address, error) {
|
||||
var (
|
||||
ret0 = new([]common.Address)
|
||||
)
|
||||
out := &[]interface{}{
|
||||
ret0,
|
||||
}
|
||||
err := _BlockSigner.contract.Call(opts, out, "getSigners", _blockHash)
|
||||
return *ret0, err
|
||||
}
|
||||
|
||||
// GetSigners is a free data retrieval call binding the contract method 0xe7ec6aef.
|
||||
//
|
||||
// Solidity: function getSigners(_blockHash bytes32) constant returns(address[])
|
||||
func (_BlockSigner *BlockSignerSession) GetSigners(_blockHash [32]byte) ([]common.Address, error) {
|
||||
return _BlockSigner.Contract.GetSigners(&_BlockSigner.CallOpts, _blockHash)
|
||||
}
|
||||
|
||||
// GetSigners is a free data retrieval call binding the contract method 0xe7ec6aef.
|
||||
//
|
||||
// Solidity: function getSigners(_blockHash bytes32) constant returns(address[])
|
||||
func (_BlockSigner *BlockSignerCallerSession) GetSigners(_blockHash [32]byte) ([]common.Address, error) {
|
||||
return _BlockSigner.Contract.GetSigners(&_BlockSigner.CallOpts, _blockHash)
|
||||
}
|
||||
|
||||
// Sign is a paid mutator transaction binding the contract method 0xe341eaa4.
|
||||
//
|
||||
// Solidity: function sign(_blockNumber uint256, _blockHash bytes32) returns()
|
||||
func (_BlockSigner *BlockSignerTransactor) Sign(opts *bind.TransactOpts, _blockNumber *big.Int, _blockHash [32]byte) (*types.Transaction, error) {
|
||||
return _BlockSigner.contract.Transact(opts, "sign", _blockNumber, _blockHash)
|
||||
}
|
||||
|
||||
// Sign is a paid mutator transaction binding the contract method 0xe341eaa4.
|
||||
//
|
||||
// Solidity: function sign(_blockNumber uint256, _blockHash bytes32) returns()
|
||||
func (_BlockSigner *BlockSignerSession) Sign(_blockNumber *big.Int, _blockHash [32]byte) (*types.Transaction, error) {
|
||||
return _BlockSigner.Contract.Sign(&_BlockSigner.TransactOpts, _blockNumber, _blockHash)
|
||||
}
|
||||
|
||||
// Sign is a paid mutator transaction binding the contract method 0xe341eaa4.
|
||||
//
|
||||
// Solidity: function sign(_blockNumber uint256, _blockHash bytes32) returns()
|
||||
func (_BlockSigner *BlockSignerTransactorSession) Sign(_blockNumber *big.Int, _blockHash [32]byte) (*types.Transaction, error) {
|
||||
return _BlockSigner.Contract.Sign(&_BlockSigner.TransactOpts, _blockNumber, _blockHash)
|
||||
}
|
||||
|
||||
// BlockSignerSignIterator is returned from FilterSign and is used to iterate over the raw logs and unpacked data for Sign events raised by the BlockSigner contract.
|
||||
type BlockSignerSignIterator struct {
|
||||
Event *BlockSignerSign // Event containing the contract specifics and raw log
|
||||
|
||||
contract *bind.BoundContract // Generic contract to use for unpacking event data
|
||||
event string // Event name to use for unpacking event data
|
||||
|
||||
logs chan types.Log // Log channel receiving the found contract events
|
||||
sub ethereum.Subscription // Subscription for errors, completion and termination
|
||||
done bool // Whether the subscription completed delivering logs
|
||||
fail error // Occurred error to stop iteration
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (it *BlockSignerSignIterator) Next() bool {
|
||||
// If the iterator failed, stop iterating
|
||||
if it.fail != nil {
|
||||
return false
|
||||
}
|
||||
// If the iterator completed, deliver directly whatever's available
|
||||
if it.done {
|
||||
select {
|
||||
case log := <-it.logs:
|
||||
it.Event = new(BlockSignerSign)
|
||||
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
|
||||
it.fail = err
|
||||
return false
|
||||
}
|
||||
it.Event.Raw = log
|
||||
return true
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
// Iterator still in progress, wait for either a data or an error event
|
||||
select {
|
||||
case log := <-it.logs:
|
||||
it.Event = new(BlockSignerSign)
|
||||
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
|
||||
it.fail = err
|
||||
return false
|
||||
}
|
||||
it.Event.Raw = log
|
||||
return true
|
||||
|
||||
case err := <-it.sub.Err():
|
||||
it.done = true
|
||||
it.fail = err
|
||||
return it.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// Error returns any retrieval or parsing error occurred during filtering.
|
||||
func (it *BlockSignerSignIterator) Error() error {
|
||||
return it.fail
|
||||
}
|
||||
|
||||
// Close terminates the iteration process, releasing any pending underlying
|
||||
// resources.
|
||||
func (it *BlockSignerSignIterator) Close() error {
|
||||
it.sub.Unsubscribe()
|
||||
return nil
|
||||
}
|
||||
|
||||
// BlockSignerSign represents a Sign event raised by the BlockSigner contract.
|
||||
type BlockSignerSign struct {
|
||||
Signer common.Address
|
||||
BlockNumber *big.Int
|
||||
BlockHash [32]byte
|
||||
Raw types.Log // Blockchain specific contextual infos
|
||||
}
|
||||
|
||||
// FilterSign is a free log retrieval operation binding the contract event 0x62855fa22e051687c32ac285857751f6d3f2c100c72756d8d30cb7ecb1f64f54.
|
||||
//
|
||||
// Solidity: event Sign(_signer address, _blockNumber uint256, _blockHash bytes32)
|
||||
func (_BlockSigner *BlockSignerFilterer) FilterSign(opts *bind.FilterOpts) (*BlockSignerSignIterator, error) {
|
||||
|
||||
logs, sub, err := _BlockSigner.contract.FilterLogs(opts, "Sign")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &BlockSignerSignIterator{contract: _BlockSigner.contract, event: "Sign", logs: logs, sub: sub}, nil
|
||||
}
|
||||
|
||||
// WatchSign is a free log subscription operation binding the contract event 0x62855fa22e051687c32ac285857751f6d3f2c100c72756d8d30cb7ecb1f64f54.
|
||||
//
|
||||
// Solidity: event Sign(_signer address, _blockNumber uint256, _blockHash bytes32)
|
||||
func (_BlockSigner *BlockSignerFilterer) WatchSign(opts *bind.WatchOpts, sink chan<- *BlockSignerSign) (event.Subscription, error) {
|
||||
|
||||
logs, sub, err := _BlockSigner.contract.WatchLogs(opts, "Sign")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return event.NewSubscription(func(quit <-chan struct{}) error {
|
||||
defer sub.Unsubscribe()
|
||||
for {
|
||||
select {
|
||||
case log := <-logs:
|
||||
// New log arrived, parse the event and forward to the user
|
||||
event := new(BlockSignerSign)
|
||||
if err := _BlockSigner.contract.UnpackLog(event, "Sign", log); err != nil {
|
||||
return err
|
||||
}
|
||||
event.Raw = log
|
||||
|
||||
select {
|
||||
case sink <- event:
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-quit:
|
||||
return nil
|
||||
}
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-quit:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}), nil
|
||||
}
|
||||
|
||||
// SafeMathABI is the input ABI used to generate the binding from.
|
||||
const SafeMathABI = "[]"
|
||||
|
||||
// SafeMathBin is the compiled bytecode used for deploying new contracts.
|
||||
const SafeMathBin = `0x604c602c600b82828239805160001a60731460008114601c57601e565bfe5b5030600052607381538281f30073000000000000000000000000000000000000000030146060604052600080fd00a165627a7a72305820b9407d48ebc7efee5c9f08b3b3a957df2939281f5913225e8c1291f069b900490029`
|
||||
|
||||
// DeploySafeMath deploys a new Ethereum contract, binding an instance of SafeMath to it.
|
||||
func DeploySafeMath(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *SafeMath, error) {
|
||||
parsed, err := abi.JSON(strings.NewReader(SafeMathABI))
|
||||
if err != nil {
|
||||
return common.Address{}, nil, nil, err
|
||||
}
|
||||
address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(SafeMathBin), backend)
|
||||
if err != nil {
|
||||
return common.Address{}, nil, nil, err
|
||||
}
|
||||
return address, tx, &SafeMath{SafeMathCaller: SafeMathCaller{contract: contract}, SafeMathTransactor: SafeMathTransactor{contract: contract}, SafeMathFilterer: SafeMathFilterer{contract: contract}}, nil
|
||||
}
|
||||
|
||||
// SafeMath is an auto generated Go binding around an Ethereum contract.
|
||||
type SafeMath struct {
|
||||
SafeMathCaller // Read-only binding to the contract
|
||||
SafeMathTransactor // Write-only binding to the contract
|
||||
SafeMathFilterer // Log filterer for contract events
|
||||
}
|
||||
|
||||
// SafeMathCaller is an auto generated read-only Go binding around an Ethereum contract.
|
||||
type SafeMathCaller struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// SafeMathTransactor is an auto generated write-only Go binding around an Ethereum contract.
|
||||
type SafeMathTransactor struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// SafeMathFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
|
||||
type SafeMathFilterer struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// SafeMathSession is an auto generated Go binding around an Ethereum contract,
|
||||
// with pre-set call and transact options.
|
||||
type SafeMathSession struct {
|
||||
Contract *SafeMath // 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
|
||||
}
|
||||
|
||||
// SafeMathCallerSession is an auto generated read-only Go binding around an Ethereum contract,
|
||||
// with pre-set call options.
|
||||
type SafeMathCallerSession struct {
|
||||
Contract *SafeMathCaller // Generic contract caller binding to set the session for
|
||||
CallOpts bind.CallOpts // Call options to use throughout this session
|
||||
}
|
||||
|
||||
// SafeMathTransactorSession is an auto generated write-only Go binding around an Ethereum contract,
|
||||
// with pre-set transact options.
|
||||
type SafeMathTransactorSession struct {
|
||||
Contract *SafeMathTransactor // Generic contract transactor binding to set the session for
|
||||
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
|
||||
}
|
||||
|
||||
// SafeMathRaw is an auto generated low-level Go binding around an Ethereum contract.
|
||||
type SafeMathRaw struct {
|
||||
Contract *SafeMath // Generic contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// SafeMathCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
|
||||
type SafeMathCallerRaw struct {
|
||||
Contract *SafeMathCaller // Generic read-only contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// SafeMathTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
|
||||
type SafeMathTransactorRaw struct {
|
||||
Contract *SafeMathTransactor // Generic write-only contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// NewSafeMath creates a new instance of SafeMath, bound to a specific deployed contract.
|
||||
func NewSafeMath(address common.Address, backend bind.ContractBackend) (*SafeMath, error) {
|
||||
contract, err := bindSafeMath(address, backend, backend, backend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &SafeMath{SafeMathCaller: SafeMathCaller{contract: contract}, SafeMathTransactor: SafeMathTransactor{contract: contract}, SafeMathFilterer: SafeMathFilterer{contract: contract}}, nil
|
||||
}
|
||||
|
||||
// NewSafeMathCaller creates a new read-only instance of SafeMath, bound to a specific deployed contract.
|
||||
func NewSafeMathCaller(address common.Address, caller bind.ContractCaller) (*SafeMathCaller, error) {
|
||||
contract, err := bindSafeMath(address, caller, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &SafeMathCaller{contract: contract}, nil
|
||||
}
|
||||
|
||||
// NewSafeMathTransactor creates a new write-only instance of SafeMath, bound to a specific deployed contract.
|
||||
func NewSafeMathTransactor(address common.Address, transactor bind.ContractTransactor) (*SafeMathTransactor, error) {
|
||||
contract, err := bindSafeMath(address, nil, transactor, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &SafeMathTransactor{contract: contract}, nil
|
||||
}
|
||||
|
||||
// NewSafeMathFilterer creates a new log filterer instance of SafeMath, bound to a specific deployed contract.
|
||||
func NewSafeMathFilterer(address common.Address, filterer bind.ContractFilterer) (*SafeMathFilterer, error) {
|
||||
contract, err := bindSafeMath(address, nil, nil, filterer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &SafeMathFilterer{contract: contract}, nil
|
||||
}
|
||||
|
||||
// bindSafeMath binds a generic wrapper to an already deployed contract.
|
||||
func bindSafeMath(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) {
|
||||
parsed, err := abi.JSON(strings.NewReader(SafeMathABI))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil
|
||||
}
|
||||
|
||||
// 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 (_SafeMath *SafeMathRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
|
||||
return _SafeMath.Contract.SafeMathCaller.contract.Call(opts, result, method, params...)
|
||||
}
|
||||
|
||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
||||
// its default method if one is available.
|
||||
func (_SafeMath *SafeMathRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _SafeMath.Contract.SafeMathTransactor.contract.Transfer(opts)
|
||||
}
|
||||
|
||||
// Transact invokes the (paid) contract method with params as input values.
|
||||
func (_SafeMath *SafeMathRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
|
||||
return _SafeMath.Contract.SafeMathTransactor.contract.Transact(opts, method, params...)
|
||||
}
|
||||
|
||||
// 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 (_SafeMath *SafeMathCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
|
||||
return _SafeMath.Contract.contract.Call(opts, result, method, params...)
|
||||
}
|
||||
|
||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
||||
// its default method if one is available.
|
||||
func (_SafeMath *SafeMathTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _SafeMath.Contract.contract.Transfer(opts)
|
||||
}
|
||||
|
||||
// Transact invokes the (paid) contract method with params as input values.
|
||||
func (_SafeMath *SafeMathTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
|
||||
return _SafeMath.Contract.contract.Transact(opts, method, params...)
|
||||
}
|
||||
1924
contracts/multisigwallet/contract/multisigwallet.go
Normal file
1924
contracts/multisigwallet/contract/multisigwallet.go
Normal file
File diff suppressed because one or more lines are too long
57
contracts/multisigwallet/multisigwallet.go
Normal file
57
contracts/multisigwallet/multisigwallet.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
// Copyright (c) 2018 XDPoSChain
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package multisigwallet
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/contracts/multisigwallet/contract"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
type MultiSigWallet struct {
|
||||
*contract.MultiSigWalletSession
|
||||
contractBackend bind.ContractBackend
|
||||
}
|
||||
|
||||
func NewMultiSigWallet(transactOpts *bind.TransactOpts, contractAddr common.Address, contractBackend bind.ContractBackend) (*MultiSigWallet, error) {
|
||||
blockSigner, err := contract.NewMultiSigWallet(contractAddr, contractBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &MultiSigWallet{
|
||||
&contract.MultiSigWalletSession{
|
||||
Contract: blockSigner,
|
||||
TransactOpts: *transactOpts,
|
||||
},
|
||||
contractBackend,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func DeployMultiSigWallet(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, _owners []common.Address, _required *big.Int) (common.Address, *MultiSigWallet, error) {
|
||||
blockSignerAddr, _, _, err := contract.DeployMultiSigWallet(transactOpts, contractBackend, _owners, _required)
|
||||
if err != nil {
|
||||
return blockSignerAddr, nil, err
|
||||
}
|
||||
|
||||
blockSigner, err := NewMultiSigWallet(transactOpts, blockSignerAddr, contractBackend)
|
||||
if err != nil {
|
||||
return blockSignerAddr, nil, err
|
||||
}
|
||||
|
||||
return blockSignerAddr, blockSigner, nil
|
||||
}
|
||||
2525
contracts/trc21issuer/contract/TRC21.go
Normal file
2525
contracts/trc21issuer/contract/TRC21.go
Normal file
File diff suppressed because one or more lines are too long
776
contracts/trc21issuer/contract/TRC21Issuer.go
Normal file
776
contracts/trc21issuer/contract/TRC21Issuer.go
Normal file
|
|
@ -0,0 +1,776 @@
|
|||
// Code generated - DO NOT EDIT.
|
||||
// This file is a generated binding and any manual changes will be lost.
|
||||
|
||||
package contract
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"strings"
|
||||
|
||||
ethereum "github.com/ethereum/go-ethereum"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
)
|
||||
|
||||
// AbstractTokenTRC21ABI is the input ABI used to generate the binding from.
|
||||
const AbstractTokenTRC21ABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"issuer\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]"
|
||||
|
||||
// AbstractTokenTRC21Bin is the compiled bytecode used for deploying new contracts.
|
||||
const AbstractTokenTRC21Bin = `0x`
|
||||
|
||||
// DeployAbstractTokenTRC21 deploys a new Ethereum contract, binding an instance of AbstractTokenTRC21 to it.
|
||||
func DeployAbstractTokenTRC21(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *AbstractTokenTRC21, error) {
|
||||
parsed, err := abi.JSON(strings.NewReader(AbstractTokenTRC21ABI))
|
||||
if err != nil {
|
||||
return common.Address{}, nil, nil, err
|
||||
}
|
||||
address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(AbstractTokenTRC21Bin), backend)
|
||||
if err != nil {
|
||||
return common.Address{}, nil, nil, err
|
||||
}
|
||||
return address, tx, &AbstractTokenTRC21{AbstractTokenTRC21Caller: AbstractTokenTRC21Caller{contract: contract}, AbstractTokenTRC21Transactor: AbstractTokenTRC21Transactor{contract: contract}, AbstractTokenTRC21Filterer: AbstractTokenTRC21Filterer{contract: contract}}, nil
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21 is an auto generated Go binding around an Ethereum contract.
|
||||
type AbstractTokenTRC21 struct {
|
||||
AbstractTokenTRC21Caller // Read-only binding to the contract
|
||||
AbstractTokenTRC21Transactor // Write-only binding to the contract
|
||||
AbstractTokenTRC21Filterer // Log filterer for contract events
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21Caller is an auto generated read-only Go binding around an Ethereum contract.
|
||||
type AbstractTokenTRC21Caller struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21Transactor is an auto generated write-only Go binding around an Ethereum contract.
|
||||
type AbstractTokenTRC21Transactor struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21Filterer is an auto generated log filtering Go binding around an Ethereum contract events.
|
||||
type AbstractTokenTRC21Filterer struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21Session is an auto generated Go binding around an Ethereum contract,
|
||||
// with pre-set call and transact options.
|
||||
type AbstractTokenTRC21Session struct {
|
||||
Contract *AbstractTokenTRC21 // 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
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21CallerSession is an auto generated read-only Go binding around an Ethereum contract,
|
||||
// with pre-set call options.
|
||||
type AbstractTokenTRC21CallerSession struct {
|
||||
Contract *AbstractTokenTRC21Caller // Generic contract caller binding to set the session for
|
||||
CallOpts bind.CallOpts // Call options to use throughout this session
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21TransactorSession is an auto generated write-only Go binding around an Ethereum contract,
|
||||
// with pre-set transact options.
|
||||
type AbstractTokenTRC21TransactorSession struct {
|
||||
Contract *AbstractTokenTRC21Transactor // Generic contract transactor binding to set the session for
|
||||
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21Raw is an auto generated low-level Go binding around an Ethereum contract.
|
||||
type AbstractTokenTRC21Raw struct {
|
||||
Contract *AbstractTokenTRC21 // Generic contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21CallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
|
||||
type AbstractTokenTRC21CallerRaw struct {
|
||||
Contract *AbstractTokenTRC21Caller // Generic read-only contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// AbstractTokenTRC21TransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
|
||||
type AbstractTokenTRC21TransactorRaw struct {
|
||||
Contract *AbstractTokenTRC21Transactor // Generic write-only contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// NewAbstractTokenTRC21 creates a new instance of AbstractTokenTRC21, bound to a specific deployed contract.
|
||||
func NewAbstractTokenTRC21(address common.Address, backend bind.ContractBackend) (*AbstractTokenTRC21, error) {
|
||||
contract, err := bindAbstractTokenTRC21(address, backend, backend, backend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &AbstractTokenTRC21{AbstractTokenTRC21Caller: AbstractTokenTRC21Caller{contract: contract}, AbstractTokenTRC21Transactor: AbstractTokenTRC21Transactor{contract: contract}, AbstractTokenTRC21Filterer: AbstractTokenTRC21Filterer{contract: contract}}, nil
|
||||
}
|
||||
|
||||
// NewAbstractTokenTRC21Caller creates a new read-only instance of AbstractTokenTRC21, bound to a specific deployed contract.
|
||||
func NewAbstractTokenTRC21Caller(address common.Address, caller bind.ContractCaller) (*AbstractTokenTRC21Caller, error) {
|
||||
contract, err := bindAbstractTokenTRC21(address, caller, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &AbstractTokenTRC21Caller{contract: contract}, nil
|
||||
}
|
||||
|
||||
// NewAbstractTokenTRC21Transactor creates a new write-only instance of AbstractTokenTRC21, bound to a specific deployed contract.
|
||||
func NewAbstractTokenTRC21Transactor(address common.Address, transactor bind.ContractTransactor) (*AbstractTokenTRC21Transactor, error) {
|
||||
contract, err := bindAbstractTokenTRC21(address, nil, transactor, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &AbstractTokenTRC21Transactor{contract: contract}, nil
|
||||
}
|
||||
|
||||
// NewAbstractTokenTRC21Filterer creates a new log filterer instance of AbstractTokenTRC21, bound to a specific deployed contract.
|
||||
func NewAbstractTokenTRC21Filterer(address common.Address, filterer bind.ContractFilterer) (*AbstractTokenTRC21Filterer, error) {
|
||||
contract, err := bindAbstractTokenTRC21(address, nil, nil, filterer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &AbstractTokenTRC21Filterer{contract: contract}, nil
|
||||
}
|
||||
|
||||
// bindAbstractTokenTRC21 binds a generic wrapper to an already deployed contract.
|
||||
func bindAbstractTokenTRC21(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) {
|
||||
parsed, err := abi.JSON(strings.NewReader(AbstractTokenTRC21ABI))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil
|
||||
}
|
||||
|
||||
// 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 (_AbstractTokenTRC21 *AbstractTokenTRC21Raw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
|
||||
return _AbstractTokenTRC21.Contract.AbstractTokenTRC21Caller.contract.Call(opts, result, method, params...)
|
||||
}
|
||||
|
||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
||||
// its default method if one is available.
|
||||
func (_AbstractTokenTRC21 *AbstractTokenTRC21Raw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _AbstractTokenTRC21.Contract.AbstractTokenTRC21Transactor.contract.Transfer(opts)
|
||||
}
|
||||
|
||||
// Transact invokes the (paid) contract method with params as input values.
|
||||
func (_AbstractTokenTRC21 *AbstractTokenTRC21Raw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
|
||||
return _AbstractTokenTRC21.Contract.AbstractTokenTRC21Transactor.contract.Transact(opts, method, params...)
|
||||
}
|
||||
|
||||
// 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 (_AbstractTokenTRC21 *AbstractTokenTRC21CallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
|
||||
return _AbstractTokenTRC21.Contract.contract.Call(opts, result, method, params...)
|
||||
}
|
||||
|
||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
||||
// its default method if one is available.
|
||||
func (_AbstractTokenTRC21 *AbstractTokenTRC21TransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _AbstractTokenTRC21.Contract.contract.Transfer(opts)
|
||||
}
|
||||
|
||||
// Transact invokes the (paid) contract method with params as input values.
|
||||
func (_AbstractTokenTRC21 *AbstractTokenTRC21TransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
|
||||
return _AbstractTokenTRC21.Contract.contract.Transact(opts, method, params...)
|
||||
}
|
||||
|
||||
// Issuer is a free data retrieval call binding the contract method 0x1d143848.
|
||||
//
|
||||
// Solidity: function issuer() constant returns(address)
|
||||
func (_AbstractTokenTRC21 *AbstractTokenTRC21Caller) Issuer(opts *bind.CallOpts) (common.Address, error) {
|
||||
var (
|
||||
ret0 = new(common.Address)
|
||||
)
|
||||
out := &[]interface{}{
|
||||
ret0,
|
||||
}
|
||||
err := _AbstractTokenTRC21.contract.Call(opts, out, "issuer")
|
||||
return *ret0, err
|
||||
}
|
||||
|
||||
// Issuer is a free data retrieval call binding the contract method 0x1d143848.
|
||||
//
|
||||
// Solidity: function issuer() constant returns(address)
|
||||
func (_AbstractTokenTRC21 *AbstractTokenTRC21Session) Issuer() (common.Address, error) {
|
||||
return _AbstractTokenTRC21.Contract.Issuer(&_AbstractTokenTRC21.CallOpts)
|
||||
}
|
||||
|
||||
// Issuer is a free data retrieval call binding the contract method 0x1d143848.
|
||||
//
|
||||
// Solidity: function issuer() constant returns(address)
|
||||
func (_AbstractTokenTRC21 *AbstractTokenTRC21CallerSession) Issuer() (common.Address, error) {
|
||||
return _AbstractTokenTRC21.Contract.Issuer(&_AbstractTokenTRC21.CallOpts)
|
||||
}
|
||||
|
||||
// TRC21IssuerABI is the input ABI used to generate the binding from.
|
||||
const TRC21IssuerABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"minCap\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"token\",\"type\":\"address\"}],\"name\":\"getTokenCapacity\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"tokens\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"token\",\"type\":\"address\"}],\"name\":\"apply\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"token\",\"type\":\"address\"}],\"name\":\"charge\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"value\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"issuer\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"token\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Apply\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"supporter\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"token\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Charge\",\"type\":\"event\"}]"
|
||||
|
||||
// TRC21IssuerBin is the compiled bytecode used for deploying new contracts.
|
||||
const TRC21IssuerBin = `0x608060405234801561001057600080fd5b5060405160208061047d8339810160405251600055610449806100346000396000f30060806040526004361061006c5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633fa615b081146100715780638f3a981c146100985780639d63848a146100b9578063c6b32f341461011e578063fc6bd76a14610134575b600080fd5b34801561007d57600080fd5b50610086610148565b60408051918252519081900360200190f35b3480156100a457600080fd5b50610086600160a060020a036004351661014e565b3480156100c557600080fd5b506100ce610169565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561010a5781810151838201526020016100f2565b505050509050019250505060405180910390f35b610132600160a060020a03600435166101cb565b005b610132600160a060020a036004351661035d565b60005490565b600160a060020a031660009081526002602052604090205490565b606060018054806020026020016040519081016040528092919081815260200182805480156101c157602002820191906000526020600020905b8154600160a060020a031681526001909101906020018083116101a3575b5050505050905090565b600081600160a060020a03811615156101e357600080fd5b6000543410156101f257600080fd5b82915033600160a060020a031682600160a060020a0316631d1438486040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b15801561025657600080fd5b505af115801561026a573d6000803e3d6000fd5b505050506040513d602081101561028057600080fd5b5051600160a060020a03161461029557600080fd5b600180548082019091557fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf601805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0385169081179091556000908152600260205260409020546103039034610404565b600160a060020a0384166000818152600260209081526040918290209390935580513481529051919233927f2d485624158277d5113a56388c3abf5c20e3511dd112123ba376d16b21e4d7169281900390910190a3505050565b80600160a060020a038116151561037357600080fd5b60005434101561038257600080fd5b600160a060020a0382166000908152600260205260409020546103ab903463ffffffff61040416565b600160a060020a0383166000818152600260209081526040918290209390935580513481529051919233927f5cffac866325fd9b2a8ea8df2f110a0058313b279402d15ae28dd324a2282e069281900390910190a35050565b60008282018381101561041657600080fd5b93925050505600a165627a7a7230582017d25c61c6dd745630f85ec71140358aef38c084b91e940943bb4a15314b5e660029`
|
||||
|
||||
// DeployTRC21Issuer deploys a new Ethereum contract, binding an instance of TRC21Issuer to it.
|
||||
func DeployTRC21Issuer(auth *bind.TransactOpts, backend bind.ContractBackend, value *big.Int) (common.Address, *types.Transaction, *TRC21Issuer, error) {
|
||||
parsed, err := abi.JSON(strings.NewReader(TRC21IssuerABI))
|
||||
if err != nil {
|
||||
return common.Address{}, nil, nil, err
|
||||
}
|
||||
address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(TRC21IssuerBin), backend, value)
|
||||
if err != nil {
|
||||
return common.Address{}, nil, nil, err
|
||||
}
|
||||
return address, tx, &TRC21Issuer{TRC21IssuerCaller: TRC21IssuerCaller{contract: contract}, TRC21IssuerTransactor: TRC21IssuerTransactor{contract: contract}, TRC21IssuerFilterer: TRC21IssuerFilterer{contract: contract}}, nil
|
||||
}
|
||||
|
||||
// TRC21Issuer is an auto generated Go binding around an Ethereum contract.
|
||||
type TRC21Issuer struct {
|
||||
TRC21IssuerCaller // Read-only binding to the contract
|
||||
TRC21IssuerTransactor // Write-only binding to the contract
|
||||
TRC21IssuerFilterer // Log filterer for contract events
|
||||
}
|
||||
|
||||
// TRC21IssuerCaller is an auto generated read-only Go binding around an Ethereum contract.
|
||||
type TRC21IssuerCaller struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// TRC21IssuerTransactor is an auto generated write-only Go binding around an Ethereum contract.
|
||||
type TRC21IssuerTransactor struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// TRC21IssuerFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
|
||||
type TRC21IssuerFilterer struct {
|
||||
contract *bind.BoundContract // Generic contract wrapper for the low level calls
|
||||
}
|
||||
|
||||
// TRC21IssuerSession is an auto generated Go binding around an Ethereum contract,
|
||||
// with pre-set call and transact options.
|
||||
type TRC21IssuerSession struct {
|
||||
Contract *TRC21Issuer // 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
|
||||
}
|
||||
|
||||
// TRC21IssuerCallerSession is an auto generated read-only Go binding around an Ethereum contract,
|
||||
// with pre-set call options.
|
||||
type TRC21IssuerCallerSession struct {
|
||||
Contract *TRC21IssuerCaller // Generic contract caller binding to set the session for
|
||||
CallOpts bind.CallOpts // Call options to use throughout this session
|
||||
}
|
||||
|
||||
// TRC21IssuerTransactorSession is an auto generated write-only Go binding around an Ethereum contract,
|
||||
// with pre-set transact options.
|
||||
type TRC21IssuerTransactorSession struct {
|
||||
Contract *TRC21IssuerTransactor // Generic contract transactor binding to set the session for
|
||||
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
|
||||
}
|
||||
|
||||
// TRC21IssuerRaw is an auto generated low-level Go binding around an Ethereum contract.
|
||||
type TRC21IssuerRaw struct {
|
||||
Contract *TRC21Issuer // Generic contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// TRC21IssuerCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
|
||||
type TRC21IssuerCallerRaw struct {
|
||||
Contract *TRC21IssuerCaller // Generic read-only contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// TRC21IssuerTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
|
||||
type TRC21IssuerTransactorRaw struct {
|
||||
Contract *TRC21IssuerTransactor // Generic write-only contract binding to access the raw methods on
|
||||
}
|
||||
|
||||
// NewTRC21Issuer creates a new instance of TRC21Issuer, bound to a specific deployed contract.
|
||||
func NewTRC21Issuer(address common.Address, backend bind.ContractBackend) (*TRC21Issuer, error) {
|
||||
contract, err := bindTRC21Issuer(address, backend, backend, backend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &TRC21Issuer{TRC21IssuerCaller: TRC21IssuerCaller{contract: contract}, TRC21IssuerTransactor: TRC21IssuerTransactor{contract: contract}, TRC21IssuerFilterer: TRC21IssuerFilterer{contract: contract}}, nil
|
||||
}
|
||||
|
||||
// NewTRC21IssuerCaller creates a new read-only instance of TRC21Issuer, bound to a specific deployed contract.
|
||||
func NewTRC21IssuerCaller(address common.Address, caller bind.ContractCaller) (*TRC21IssuerCaller, error) {
|
||||
contract, err := bindTRC21Issuer(address, caller, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &TRC21IssuerCaller{contract: contract}, nil
|
||||
}
|
||||
|
||||
// NewTRC21IssuerTransactor creates a new write-only instance of TRC21Issuer, bound to a specific deployed contract.
|
||||
func NewTRC21IssuerTransactor(address common.Address, transactor bind.ContractTransactor) (*TRC21IssuerTransactor, error) {
|
||||
contract, err := bindTRC21Issuer(address, nil, transactor, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &TRC21IssuerTransactor{contract: contract}, nil
|
||||
}
|
||||
|
||||
// NewTRC21IssuerFilterer creates a new log filterer instance of TRC21Issuer, bound to a specific deployed contract.
|
||||
func NewTRC21IssuerFilterer(address common.Address, filterer bind.ContractFilterer) (*TRC21IssuerFilterer, error) {
|
||||
contract, err := bindTRC21Issuer(address, nil, nil, filterer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &TRC21IssuerFilterer{contract: contract}, nil
|
||||
}
|
||||
|
||||
// bindTRC21Issuer binds a generic wrapper to an already deployed contract.
|
||||
func bindTRC21Issuer(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) {
|
||||
parsed, err := abi.JSON(strings.NewReader(TRC21IssuerABI))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil
|
||||
}
|
||||
|
||||
// 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 (_TRC21Issuer *TRC21IssuerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
|
||||
return _TRC21Issuer.Contract.TRC21IssuerCaller.contract.Call(opts, result, method, params...)
|
||||
}
|
||||
|
||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
||||
// its default method if one is available.
|
||||
func (_TRC21Issuer *TRC21IssuerRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.Contract.TRC21IssuerTransactor.contract.Transfer(opts)
|
||||
}
|
||||
|
||||
// Transact invokes the (paid) contract method with params as input values.
|
||||
func (_TRC21Issuer *TRC21IssuerRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.Contract.TRC21IssuerTransactor.contract.Transact(opts, method, params...)
|
||||
}
|
||||
|
||||
// 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 (_TRC21Issuer *TRC21IssuerCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
|
||||
return _TRC21Issuer.Contract.contract.Call(opts, result, method, params...)
|
||||
}
|
||||
|
||||
// Transfer initiates a plain transaction to move funds to the contract, calling
|
||||
// its default method if one is available.
|
||||
func (_TRC21Issuer *TRC21IssuerTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.Contract.contract.Transfer(opts)
|
||||
}
|
||||
|
||||
// Transact invokes the (paid) contract method with params as input values.
|
||||
func (_TRC21Issuer *TRC21IssuerTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.Contract.contract.Transact(opts, method, params...)
|
||||
}
|
||||
|
||||
// GetTokenCapacity is a free data retrieval call binding the contract method 0x8f3a981c.
|
||||
//
|
||||
// Solidity: function getTokenCapacity(token address) constant returns(uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerCaller) GetTokenCapacity(opts *bind.CallOpts, token common.Address) (*big.Int, error) {
|
||||
var (
|
||||
ret0 = new(*big.Int)
|
||||
)
|
||||
out := &[]interface{}{
|
||||
ret0,
|
||||
}
|
||||
err := _TRC21Issuer.contract.Call(opts, out, "getTokenCapacity", token)
|
||||
return *ret0, err
|
||||
}
|
||||
|
||||
// GetTokenCapacity is a free data retrieval call binding the contract method 0x8f3a981c.
|
||||
//
|
||||
// Solidity: function getTokenCapacity(token address) constant returns(uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerSession) GetTokenCapacity(token common.Address) (*big.Int, error) {
|
||||
return _TRC21Issuer.Contract.GetTokenCapacity(&_TRC21Issuer.CallOpts, token)
|
||||
}
|
||||
|
||||
// GetTokenCapacity is a free data retrieval call binding the contract method 0x8f3a981c.
|
||||
//
|
||||
// Solidity: function getTokenCapacity(token address) constant returns(uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerCallerSession) GetTokenCapacity(token common.Address) (*big.Int, error) {
|
||||
return _TRC21Issuer.Contract.GetTokenCapacity(&_TRC21Issuer.CallOpts, token)
|
||||
}
|
||||
|
||||
// MinCap is a free data retrieval call binding the contract method 0x3fa615b0.
|
||||
//
|
||||
// Solidity: function minCap() constant returns(uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerCaller) MinCap(opts *bind.CallOpts) (*big.Int, error) {
|
||||
var (
|
||||
ret0 = new(*big.Int)
|
||||
)
|
||||
out := &[]interface{}{
|
||||
ret0,
|
||||
}
|
||||
err := _TRC21Issuer.contract.Call(opts, out, "minCap")
|
||||
return *ret0, err
|
||||
}
|
||||
|
||||
// MinCap is a free data retrieval call binding the contract method 0x3fa615b0.
|
||||
//
|
||||
// Solidity: function minCap() constant returns(uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerSession) MinCap() (*big.Int, error) {
|
||||
return _TRC21Issuer.Contract.MinCap(&_TRC21Issuer.CallOpts)
|
||||
}
|
||||
|
||||
// MinCap is a free data retrieval call binding the contract method 0x3fa615b0.
|
||||
//
|
||||
// Solidity: function minCap() constant returns(uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerCallerSession) MinCap() (*big.Int, error) {
|
||||
return _TRC21Issuer.Contract.MinCap(&_TRC21Issuer.CallOpts)
|
||||
}
|
||||
|
||||
// Tokens is a free data retrieval call binding the contract method 0x9d63848a.
|
||||
//
|
||||
// Solidity: function tokens() constant returns(address[])
|
||||
func (_TRC21Issuer *TRC21IssuerCaller) Tokens(opts *bind.CallOpts) ([]common.Address, error) {
|
||||
var (
|
||||
ret0 = new([]common.Address)
|
||||
)
|
||||
out := &[]interface{}{
|
||||
ret0,
|
||||
}
|
||||
err := _TRC21Issuer.contract.Call(opts, out, "tokens")
|
||||
return *ret0, err
|
||||
}
|
||||
|
||||
// Tokens is a free data retrieval call binding the contract method 0x9d63848a.
|
||||
//
|
||||
// Solidity: function tokens() constant returns(address[])
|
||||
func (_TRC21Issuer *TRC21IssuerSession) Tokens() ([]common.Address, error) {
|
||||
return _TRC21Issuer.Contract.Tokens(&_TRC21Issuer.CallOpts)
|
||||
}
|
||||
|
||||
// Tokens is a free data retrieval call binding the contract method 0x9d63848a.
|
||||
//
|
||||
// Solidity: function tokens() constant returns(address[])
|
||||
func (_TRC21Issuer *TRC21IssuerCallerSession) Tokens() ([]common.Address, error) {
|
||||
return _TRC21Issuer.Contract.Tokens(&_TRC21Issuer.CallOpts)
|
||||
}
|
||||
|
||||
// Apply is a paid mutator transaction binding the contract method 0xc6b32f34.
|
||||
//
|
||||
// Solidity: function apply(token address) returns()
|
||||
func (_TRC21Issuer *TRC21IssuerTransactor) Apply(opts *bind.TransactOpts, token common.Address) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.contract.Transact(opts, "apply", token)
|
||||
}
|
||||
|
||||
// Apply is a paid mutator transaction binding the contract method 0xc6b32f34.
|
||||
//
|
||||
// Solidity: function apply(token address) returns()
|
||||
func (_TRC21Issuer *TRC21IssuerSession) Apply(token common.Address) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.Contract.Apply(&_TRC21Issuer.TransactOpts, token)
|
||||
}
|
||||
|
||||
// Apply is a paid mutator transaction binding the contract method 0xc6b32f34.
|
||||
//
|
||||
// Solidity: function apply(token address) returns()
|
||||
func (_TRC21Issuer *TRC21IssuerTransactorSession) Apply(token common.Address) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.Contract.Apply(&_TRC21Issuer.TransactOpts, token)
|
||||
}
|
||||
|
||||
// Charge is a paid mutator transaction binding the contract method 0xfc6bd76a.
|
||||
//
|
||||
// Solidity: function charge(token address) returns()
|
||||
func (_TRC21Issuer *TRC21IssuerTransactor) Charge(opts *bind.TransactOpts, token common.Address) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.contract.Transact(opts, "charge", token)
|
||||
}
|
||||
|
||||
// Charge is a paid mutator transaction binding the contract method 0xfc6bd76a.
|
||||
//
|
||||
// Solidity: function charge(token address) returns()
|
||||
func (_TRC21Issuer *TRC21IssuerSession) Charge(token common.Address) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.Contract.Charge(&_TRC21Issuer.TransactOpts, token)
|
||||
}
|
||||
|
||||
// Charge is a paid mutator transaction binding the contract method 0xfc6bd76a.
|
||||
//
|
||||
// Solidity: function charge(token address) returns()
|
||||
func (_TRC21Issuer *TRC21IssuerTransactorSession) Charge(token common.Address) (*types.Transaction, error) {
|
||||
return _TRC21Issuer.Contract.Charge(&_TRC21Issuer.TransactOpts, token)
|
||||
}
|
||||
|
||||
// TRC21IssuerApplyIterator is returned from FilterApply and is used to iterate over the raw logs and unpacked data for Apply events raised by the TRC21Issuer contract.
|
||||
type TRC21IssuerApplyIterator struct {
|
||||
Event *TRC21IssuerApply // Event containing the contract specifics and raw log
|
||||
|
||||
contract *bind.BoundContract // Generic contract to use for unpacking event data
|
||||
event string // Event name to use for unpacking event data
|
||||
|
||||
logs chan types.Log // Log channel receiving the found contract events
|
||||
sub ethereum.Subscription // Subscription for errors, completion and termination
|
||||
done bool // Whether the subscription completed delivering logs
|
||||
fail error // Occurred error to stop iteration
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (it *TRC21IssuerApplyIterator) Next() bool {
|
||||
// If the iterator failed, stop iterating
|
||||
if it.fail != nil {
|
||||
return false
|
||||
}
|
||||
// If the iterator completed, deliver directly whatever's available
|
||||
if it.done {
|
||||
select {
|
||||
case log := <-it.logs:
|
||||
it.Event = new(TRC21IssuerApply)
|
||||
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
|
||||
it.fail = err
|
||||
return false
|
||||
}
|
||||
it.Event.Raw = log
|
||||
return true
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
// Iterator still in progress, wait for either a data or an error event
|
||||
select {
|
||||
case log := <-it.logs:
|
||||
it.Event = new(TRC21IssuerApply)
|
||||
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
|
||||
it.fail = err
|
||||
return false
|
||||
}
|
||||
it.Event.Raw = log
|
||||
return true
|
||||
|
||||
case err := <-it.sub.Err():
|
||||
it.done = true
|
||||
it.fail = err
|
||||
return it.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// Error returns any retrieval or parsing error occurred during filtering.
|
||||
func (it *TRC21IssuerApplyIterator) Error() error {
|
||||
return it.fail
|
||||
}
|
||||
|
||||
// Close terminates the iteration process, releasing any pending underlying
|
||||
// resources.
|
||||
func (it *TRC21IssuerApplyIterator) Close() error {
|
||||
it.sub.Unsubscribe()
|
||||
return nil
|
||||
}
|
||||
|
||||
// TRC21IssuerApply represents a Apply event raised by the TRC21Issuer contract.
|
||||
type TRC21IssuerApply struct {
|
||||
Issuer common.Address
|
||||
Token common.Address
|
||||
Value *big.Int
|
||||
Raw types.Log // Blockchain specific contextual infos
|
||||
}
|
||||
|
||||
// FilterApply is a free log retrieval operation binding the contract event 0x2d485624158277d5113a56388c3abf5c20e3511dd112123ba376d16b21e4d716.
|
||||
//
|
||||
// Solidity: event Apply(issuer indexed address, token indexed address, value uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerFilterer) FilterApply(opts *bind.FilterOpts, issuer []common.Address, token []common.Address) (*TRC21IssuerApplyIterator, error) {
|
||||
|
||||
var issuerRule []interface{}
|
||||
for _, issuerItem := range issuer {
|
||||
issuerRule = append(issuerRule, issuerItem)
|
||||
}
|
||||
var tokenRule []interface{}
|
||||
for _, tokenItem := range token {
|
||||
tokenRule = append(tokenRule, tokenItem)
|
||||
}
|
||||
|
||||
logs, sub, err := _TRC21Issuer.contract.FilterLogs(opts, "Apply", issuerRule, tokenRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &TRC21IssuerApplyIterator{contract: _TRC21Issuer.contract, event: "Apply", logs: logs, sub: sub}, nil
|
||||
}
|
||||
|
||||
// WatchApply is a free log subscription operation binding the contract event 0x2d485624158277d5113a56388c3abf5c20e3511dd112123ba376d16b21e4d716.
|
||||
//
|
||||
// Solidity: event Apply(issuer indexed address, token indexed address, value uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerFilterer) WatchApply(opts *bind.WatchOpts, sink chan<- *TRC21IssuerApply, issuer []common.Address, token []common.Address) (event.Subscription, error) {
|
||||
|
||||
var issuerRule []interface{}
|
||||
for _, issuerItem := range issuer {
|
||||
issuerRule = append(issuerRule, issuerItem)
|
||||
}
|
||||
var tokenRule []interface{}
|
||||
for _, tokenItem := range token {
|
||||
tokenRule = append(tokenRule, tokenItem)
|
||||
}
|
||||
|
||||
logs, sub, err := _TRC21Issuer.contract.WatchLogs(opts, "Apply", issuerRule, tokenRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return event.NewSubscription(func(quit <-chan struct{}) error {
|
||||
defer sub.Unsubscribe()
|
||||
for {
|
||||
select {
|
||||
case log := <-logs:
|
||||
// New log arrived, parse the event and forward to the user
|
||||
event := new(TRC21IssuerApply)
|
||||
if err := _TRC21Issuer.contract.UnpackLog(event, "Apply", log); err != nil {
|
||||
return err
|
||||
}
|
||||
event.Raw = log
|
||||
|
||||
select {
|
||||
case sink <- event:
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-quit:
|
||||
return nil
|
||||
}
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-quit:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}), nil
|
||||
}
|
||||
|
||||
// TRC21IssuerChargeIterator is returned from FilterCharge and is used to iterate over the raw logs and unpacked data for Charge events raised by the TRC21Issuer contract.
|
||||
type TRC21IssuerChargeIterator struct {
|
||||
Event *TRC21IssuerCharge // Event containing the contract specifics and raw log
|
||||
|
||||
contract *bind.BoundContract // Generic contract to use for unpacking event data
|
||||
event string // Event name to use for unpacking event data
|
||||
|
||||
logs chan types.Log // Log channel receiving the found contract events
|
||||
sub ethereum.Subscription // Subscription for errors, completion and termination
|
||||
done bool // Whether the subscription completed delivering logs
|
||||
fail error // Occurred error to stop iteration
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (it *TRC21IssuerChargeIterator) Next() bool {
|
||||
// If the iterator failed, stop iterating
|
||||
if it.fail != nil {
|
||||
return false
|
||||
}
|
||||
// If the iterator completed, deliver directly whatever's available
|
||||
if it.done {
|
||||
select {
|
||||
case log := <-it.logs:
|
||||
it.Event = new(TRC21IssuerCharge)
|
||||
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
|
||||
it.fail = err
|
||||
return false
|
||||
}
|
||||
it.Event.Raw = log
|
||||
return true
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
// Iterator still in progress, wait for either a data or an error event
|
||||
select {
|
||||
case log := <-it.logs:
|
||||
it.Event = new(TRC21IssuerCharge)
|
||||
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
|
||||
it.fail = err
|
||||
return false
|
||||
}
|
||||
it.Event.Raw = log
|
||||
return true
|
||||
|
||||
case err := <-it.sub.Err():
|
||||
it.done = true
|
||||
it.fail = err
|
||||
return it.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// Error returns any retrieval or parsing error occurred during filtering.
|
||||
func (it *TRC21IssuerChargeIterator) Error() error {
|
||||
return it.fail
|
||||
}
|
||||
|
||||
// Close terminates the iteration process, releasing any pending underlying
|
||||
// resources.
|
||||
func (it *TRC21IssuerChargeIterator) Close() error {
|
||||
it.sub.Unsubscribe()
|
||||
return nil
|
||||
}
|
||||
|
||||
// TRC21IssuerCharge represents a Charge event raised by the TRC21Issuer contract.
|
||||
type TRC21IssuerCharge struct {
|
||||
Supporter common.Address
|
||||
Token common.Address
|
||||
Value *big.Int
|
||||
Raw types.Log // Blockchain specific contextual infos
|
||||
}
|
||||
|
||||
// FilterCharge is a free log retrieval operation binding the contract event 0x5cffac866325fd9b2a8ea8df2f110a0058313b279402d15ae28dd324a2282e06.
|
||||
//
|
||||
// Solidity: event Charge(supporter indexed address, token indexed address, value uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerFilterer) FilterCharge(opts *bind.FilterOpts, supporter []common.Address, token []common.Address) (*TRC21IssuerChargeIterator, error) {
|
||||
|
||||
var supporterRule []interface{}
|
||||
for _, supporterItem := range supporter {
|
||||
supporterRule = append(supporterRule, supporterItem)
|
||||
}
|
||||
var tokenRule []interface{}
|
||||
for _, tokenItem := range token {
|
||||
tokenRule = append(tokenRule, tokenItem)
|
||||
}
|
||||
|
||||
logs, sub, err := _TRC21Issuer.contract.FilterLogs(opts, "Charge", supporterRule, tokenRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &TRC21IssuerChargeIterator{contract: _TRC21Issuer.contract, event: "Charge", logs: logs, sub: sub}, nil
|
||||
}
|
||||
|
||||
// WatchCharge is a free log subscription operation binding the contract event 0x5cffac866325fd9b2a8ea8df2f110a0058313b279402d15ae28dd324a2282e06.
|
||||
//
|
||||
// Solidity: event Charge(supporter indexed address, token indexed address, value uint256)
|
||||
func (_TRC21Issuer *TRC21IssuerFilterer) WatchCharge(opts *bind.WatchOpts, sink chan<- *TRC21IssuerCharge, supporter []common.Address, token []common.Address) (event.Subscription, error) {
|
||||
|
||||
var supporterRule []interface{}
|
||||
for _, supporterItem := range supporter {
|
||||
supporterRule = append(supporterRule, supporterItem)
|
||||
}
|
||||
var tokenRule []interface{}
|
||||
for _, tokenItem := range token {
|
||||
tokenRule = append(tokenRule, tokenItem)
|
||||
}
|
||||
|
||||
logs, sub, err := _TRC21Issuer.contract.WatchLogs(opts, "Charge", supporterRule, tokenRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return event.NewSubscription(func(quit <-chan struct{}) error {
|
||||
defer sub.Unsubscribe()
|
||||
for {
|
||||
select {
|
||||
case log := <-logs:
|
||||
// New log arrived, parse the event and forward to the user
|
||||
event := new(TRC21IssuerCharge)
|
||||
if err := _TRC21Issuer.contract.UnpackLog(event, "Charge", log); err != nil {
|
||||
return err
|
||||
}
|
||||
event.Raw = log
|
||||
|
||||
select {
|
||||
case sink <- event:
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-quit:
|
||||
return nil
|
||||
}
|
||||
case err := <-sub.Err():
|
||||
return err
|
||||
case <-quit:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}), nil
|
||||
}
|
||||
41
contracts/trc21issuer/trc21.go
Normal file
41
contracts/trc21issuer/trc21.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package trc21issuer
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/contracts/trc21issuer/contract"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
type MyTRC21 struct {
|
||||
*contract.MyTRC21Session
|
||||
contractBackend bind.ContractBackend
|
||||
}
|
||||
|
||||
func NewTRC21(transactOpts *bind.TransactOpts, contractAddr common.Address, contractBackend bind.ContractBackend) (*MyTRC21, error) {
|
||||
smartContract, err := contract.NewMyTRC21(contractAddr, contractBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &MyTRC21{
|
||||
&contract.MyTRC21Session{
|
||||
Contract: smartContract,
|
||||
TransactOpts: *transactOpts,
|
||||
},
|
||||
contractBackend,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func DeployTRC21(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, name string, symbol string, decimals uint8, cap, fee *big.Int) (common.Address, *MyTRC21, error) {
|
||||
contractAddr, _, _, err := contract.DeployMyTRC21(transactOpts, contractBackend, name, symbol, decimals, cap, fee)
|
||||
if err != nil {
|
||||
return contractAddr, nil, err
|
||||
}
|
||||
smartContract, err := NewTRC21(transactOpts, contractAddr, contractBackend)
|
||||
if err != nil {
|
||||
return contractAddr, nil, err
|
||||
}
|
||||
|
||||
return contractAddr, smartContract, nil
|
||||
}
|
||||
41
contracts/trc21issuer/trc21issuer.go
Normal file
41
contracts/trc21issuer/trc21issuer.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package trc21issuer
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/contracts/trc21issuer/contract"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
type TRC21Issuer struct {
|
||||
*contract.TRC21IssuerSession
|
||||
contractBackend bind.ContractBackend
|
||||
}
|
||||
|
||||
func NewTRC21Issuer(transactOpts *bind.TransactOpts, contractAddr common.Address, contractBackend bind.ContractBackend) (*TRC21Issuer, error) {
|
||||
contractObject, err := contract.NewTRC21Issuer(contractAddr, contractBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &TRC21Issuer{
|
||||
&contract.TRC21IssuerSession{
|
||||
Contract: contractObject,
|
||||
TransactOpts: *transactOpts,
|
||||
},
|
||||
contractBackend,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func DeployTRC21Issuer(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, minApply *big.Int) (common.Address, *TRC21Issuer, error) {
|
||||
contractAddr, _, _, err := contract.DeployTRC21Issuer(transactOpts, contractBackend, minApply)
|
||||
if err != nil {
|
||||
return contractAddr, nil, err
|
||||
}
|
||||
contractObject, err := NewTRC21Issuer(transactOpts, contractAddr, contractBackend)
|
||||
if err != nil {
|
||||
return contractAddr, nil, err
|
||||
}
|
||||
|
||||
return contractAddr, contractObject, nil
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ import (
|
|||
"crypto/cipher"
|
||||
cryptoRand "crypto/rand"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"errors"
|
||||
"io"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
|
|
@ -30,9 +30,9 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/consensus/XDPoS/utils"
|
||||
"github.com/ethereum/go-ethereum/contracts/blocksigner/contract"
|
||||
randomizeContract "github.com/ethereum/go-ethereum/contracts/randomize/contract"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
)
|
||||
|
|
@ -42,6 +42,7 @@ const (
|
|||
extraSeal = 65 // Fixed number of extra-data suffix bytes reserved for signer seal
|
||||
)
|
||||
|
||||
// RewardLog represents the reward info for logging
|
||||
type RewardLog struct {
|
||||
Sign uint64 `json:"sign"`
|
||||
Reward *big.Int `json:"reward"`
|
||||
|
|
@ -81,7 +82,7 @@ func BuildTxSecretRandomize(nonce uint64, randomizeAddr common.Address, epocNumb
|
|||
return tx, nil
|
||||
}
|
||||
|
||||
// Send opening to randomize SMC.
|
||||
// Send opening key into randomize smartcontract.
|
||||
func BuildTxOpeningRandomize(nonce uint64, randomizeAddr common.Address, randomizeKey []byte) (*types.Transaction, error) {
|
||||
data := common.Hex2Bytes(common.HexSetOpening)
|
||||
inputData := append(data, randomizeKey...)
|
||||
|
|
@ -90,175 +91,7 @@ func BuildTxOpeningRandomize(nonce uint64, randomizeAddr common.Address, randomi
|
|||
return tx, nil
|
||||
}
|
||||
|
||||
// Get random from randomize contract.
|
||||
func GetRandomizeFromContract(client bind.ContractBackend, addrMasternode common.Address) (int64, error) {
|
||||
randomize, err := randomizeContract.NewXDCRandomize(common.RandomizeSMCBinary, client)
|
||||
if err != nil {
|
||||
log.Error("Fail to get instance of randomize", "error", err)
|
||||
}
|
||||
opts := new(bind.CallOpts)
|
||||
secrets, err := randomize.GetSecret(opts, addrMasternode)
|
||||
if err != nil {
|
||||
log.Error("Fail get secrets from randomize", "error", err)
|
||||
}
|
||||
opening, err := randomize.GetOpening(opts, addrMasternode)
|
||||
if err != nil {
|
||||
log.Error("Fail get opening from randomize", "error", err)
|
||||
}
|
||||
|
||||
return DecryptRandomizeFromSecretsAndOpening(secrets, opening)
|
||||
}
|
||||
|
||||
// Generate m2 listing from randomize array.
|
||||
func GenM2FromRandomize(randomizes []int64, lenSigners int64) ([]int64, error) {
|
||||
blockValidator := NewSlice(int64(0), lenSigners, 1)
|
||||
randIndexs := make([]int64, lenSigners)
|
||||
total := int64(0)
|
||||
var temp int64 = 0
|
||||
for _, j := range randomizes {
|
||||
total += j
|
||||
}
|
||||
rand.Seed(total)
|
||||
for i := len(blockValidator) - 1; i >= 0; i-- {
|
||||
blockLength := len(blockValidator) - 1
|
||||
if blockLength <= 1 {
|
||||
blockLength = 1
|
||||
}
|
||||
randomIndex := int64(rand.Intn(blockLength))
|
||||
temp = blockValidator[randomIndex]
|
||||
blockValidator[randomIndex] = blockValidator[i]
|
||||
blockValidator[i] = temp
|
||||
blockValidator = append(blockValidator[:i], blockValidator[i+1:]...)
|
||||
randIndexs[i] = temp
|
||||
}
|
||||
|
||||
return randIndexs, nil
|
||||
}
|
||||
|
||||
// Get validators from m2 array integer.
|
||||
func BuildValidatorFromM2(listM2 []int64) []byte {
|
||||
var validatorBytes []byte
|
||||
for _, numberM2 := range listM2 {
|
||||
// Convert number to byte.
|
||||
m2Byte := common.LeftPadBytes([]byte(fmt.Sprintf("%d", numberM2)), utils.M2ByteLength)
|
||||
validatorBytes = append(validatorBytes, m2Byte...)
|
||||
}
|
||||
|
||||
return validatorBytes
|
||||
}
|
||||
|
||||
// Decode validator hex string.
|
||||
func DecodeValidatorsHexData(validatorsStr string) ([]int64, error) {
|
||||
validatorsByte, err := hexutil.Decode(validatorsStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return utils.ExtractValidatorsFromBytes(validatorsByte), nil
|
||||
}
|
||||
|
||||
// Decrypt randomize from secrets and opening.
|
||||
func DecryptRandomizeFromSecretsAndOpening(secrets [][32]byte, opening [32]byte) (int64, error) {
|
||||
var random int64
|
||||
if len(secrets) > 0 {
|
||||
for _, secret := range secrets {
|
||||
trimSecret := bytes.TrimLeft(secret[:], "\x00")
|
||||
decryptSecret := Decrypt(opening[:], string(trimSecret))
|
||||
if isInt(decryptSecret) {
|
||||
intNumber, err := strconv.Atoi(decryptSecret)
|
||||
if err != nil {
|
||||
log.Error("Can not convert string to integer", "error", err)
|
||||
return -1, err
|
||||
}
|
||||
random = int64(intNumber)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return random, nil
|
||||
}
|
||||
|
||||
// Dynamic generate array sequence of numbers.
|
||||
func NewSlice(start int64, end int64, step int64) []int64 {
|
||||
s := make([]int64, end-start)
|
||||
for i := range s {
|
||||
s[i] = start
|
||||
start += step
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// Shuffle array.
|
||||
func Shuffle(slice []int64) []int64 {
|
||||
newSlice := make([]int64, len(slice))
|
||||
copy(newSlice, slice)
|
||||
|
||||
for i := 0; i < len(slice)-1; i++ {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
randIndex := rand.Intn(len(newSlice))
|
||||
x := newSlice[i]
|
||||
newSlice[i] = newSlice[randIndex]
|
||||
newSlice[randIndex] = x
|
||||
}
|
||||
|
||||
return newSlice
|
||||
}
|
||||
|
||||
// encrypt string to base64 crypto using AES
|
||||
func Encrypt(key []byte, text string) string {
|
||||
plaintext := []byte(text)
|
||||
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
log.Error("Fail to encrypt", "err", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
// The IV needs to be unique, but not secure. Therefore it's common to
|
||||
// include it at the beginning of the ciphertext.
|
||||
ciphertext := make([]byte, aes.BlockSize+len(plaintext))
|
||||
iv := ciphertext[:aes.BlockSize]
|
||||
if _, err := io.ReadFull(cryptoRand.Reader, iv); err != nil {
|
||||
log.Error("Fail to encrypt iv", "err", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
stream := cipher.NewCFBEncrypter(block, iv)
|
||||
stream.XORKeyStream(ciphertext[aes.BlockSize:], plaintext)
|
||||
|
||||
// convert to base64
|
||||
return base64.URLEncoding.EncodeToString(ciphertext)
|
||||
}
|
||||
|
||||
// decrypt from base64 to decrypted string
|
||||
func Decrypt(key []byte, cryptoText string) string {
|
||||
ciphertext, _ := base64.URLEncoding.DecodeString(cryptoText)
|
||||
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
log.Error("Fail to decrypt", "err", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
// The IV needs to be unique, but not secure. Therefore it's common to
|
||||
// include it at the beginning of the ciphertext.
|
||||
if len(ciphertext) < aes.BlockSize {
|
||||
log.Error("ciphertext too short")
|
||||
return ""
|
||||
}
|
||||
iv := ciphertext[:aes.BlockSize]
|
||||
ciphertext = ciphertext[aes.BlockSize:]
|
||||
|
||||
stream := cipher.NewCFBDecrypter(block, iv)
|
||||
|
||||
// XORKeyStream can work in-place if the two arguments are the same.
|
||||
stream.XORKeyStream(ciphertext, ciphertext)
|
||||
|
||||
return string(ciphertext[:])
|
||||
}
|
||||
|
||||
// Generate random string.
|
||||
// RandStringByte generates a random string of specified length
|
||||
func RandStringByte(n int) []byte {
|
||||
letterBytes := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"
|
||||
b := make([]byte, n)
|
||||
|
|
@ -269,11 +102,223 @@ func RandStringByte(n int) []byte {
|
|||
return b
|
||||
}
|
||||
|
||||
// Helper function check string is numeric.
|
||||
func isInt(strNumber string) bool {
|
||||
if _, err := strconv.Atoi(strNumber); err == nil {
|
||||
return true
|
||||
} else {
|
||||
// Encrypt encrypts the plaintext using AES
|
||||
func Encrypt(key []byte, text string) string {
|
||||
plaintext := []byte(text)
|
||||
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
log.Error("Fail to encrypt", "error", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
ciphertext := make([]byte, aes.BlockSize+len(plaintext))
|
||||
iv := ciphertext[:aes.BlockSize]
|
||||
if _, err := io.ReadFull(cryptoRand.Reader, iv); err != nil {
|
||||
log.Error("Fail to encrypt iv", "error", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
stream := cipher.NewCFBEncrypter(block, iv)
|
||||
stream.XORKeyStream(ciphertext[aes.BlockSize:], plaintext)
|
||||
|
||||
return base64.URLEncoding.EncodeToString(ciphertext)
|
||||
}
|
||||
|
||||
// Decrypt decrypts ciphertext using AES
|
||||
func Decrypt(key []byte, cryptoText string) string {
|
||||
ciphertext, _ := base64.URLEncoding.DecodeString(cryptoText)
|
||||
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
log.Error("Fail to decrypt", "error", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
if len(ciphertext) < aes.BlockSize {
|
||||
log.Error("Ciphertext too short")
|
||||
return ""
|
||||
}
|
||||
iv := ciphertext[:aes.BlockSize]
|
||||
ciphertext = ciphertext[aes.BlockSize:]
|
||||
|
||||
stream := cipher.NewCFBDecrypter(block, iv)
|
||||
stream.XORKeyStream(ciphertext, ciphertext)
|
||||
|
||||
return string(ciphertext)
|
||||
}
|
||||
|
||||
// GetSignersFromContract returns the list of signers from the block signer contract
|
||||
func GetSignersFromContract(statedb *state.StateDB, block *types.Block) ([]common.Address, error) {
|
||||
return state.GetSigners(statedb, block), nil
|
||||
}
|
||||
|
||||
// GetRandomizeFromContract returns random number from contract
|
||||
func GetRandomizeFromContract(client bind.ContractBackend, addr common.Address) (int64, error) {
|
||||
randomize, err := randomizeContract.NewXDCRandomize(common.RandomizeSMCBinary, client)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
opts := new(bind.CallOpts)
|
||||
secrets, err := randomize.GetSecret(opts, addr)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
// Since there could be multiple secrets (array), we just use first one
|
||||
if len(secrets) == 0 {
|
||||
return 0, errors.New("no secrets found")
|
||||
}
|
||||
// Decrypt the secret to get the random number
|
||||
opening, err := randomize.GetOpening(opts, addr)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if len(opening) == 0 {
|
||||
return 0, errors.New("no opening found")
|
||||
}
|
||||
|
||||
// Decrypt secret with opening key
|
||||
decrypted := Decrypt(opening[:], string(secrets[0][:]))
|
||||
result, err := strconv.ParseInt(decrypted, 10, 64)
|
||||
if err != nil {
|
||||
// If can't parse, return a pseudo-random based on address
|
||||
return int64(addr.Big().Int64() % 100), nil
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GenM2FromRandomize generates M2 validator list from random numbers
|
||||
func GenM2FromRandomize(candidates []int64, lenSigners int64) ([]int64, error) {
|
||||
if len(candidates) == 0 {
|
||||
return nil, errors.New("empty candidates")
|
||||
}
|
||||
|
||||
// Create a copy of candidates for shuffling
|
||||
m2 := make([]int64, len(candidates))
|
||||
copy(m2, candidates)
|
||||
|
||||
// Fisher-Yates shuffle using candidates as seeds
|
||||
for i := len(m2) - 1; i > 0; i-- {
|
||||
seed := candidates[i%len(candidates)]
|
||||
j := int(seed) % (i + 1)
|
||||
if j < 0 {
|
||||
j = -j
|
||||
}
|
||||
m2[i], m2[j] = m2[j], m2[i]
|
||||
}
|
||||
|
||||
return m2, nil
|
||||
}
|
||||
|
||||
// BuildValidatorFromM2 builds validator bytes from M2 list
|
||||
func BuildValidatorFromM2(m2 []int64) []byte {
|
||||
var validators []byte
|
||||
for _, v := range m2 {
|
||||
validators = append(validators, byte(v))
|
||||
}
|
||||
return validators
|
||||
}
|
||||
|
||||
// GetBlockSigners returns signers who signed a specific block
|
||||
func GetBlockSigners(client bind.ContractBackend, blockHash common.Hash) ([]common.Address, error) {
|
||||
blockSigners, err := contract.NewBlockSigner(common.BlockSignersBinary, client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts := &bind.CallOpts{}
|
||||
addrs, err := blockSigners.GetSigners(opts, blockHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return addrs, nil
|
||||
}
|
||||
|
||||
// ExtractAddressFromBytes extracts addresses from a byte slice
|
||||
func ExtractAddressFromBytes(penaltiesBytes []byte) []common.Address {
|
||||
var addresses []common.Address
|
||||
if len(penaltiesBytes) == 0 {
|
||||
return addresses
|
||||
}
|
||||
// Each address is 20 bytes
|
||||
addressLen := common.AddressLength
|
||||
for i := 0; i+addressLen <= len(penaltiesBytes); i += addressLen {
|
||||
addresses = append(addresses, common.BytesToAddress(penaltiesBytes[i:i+addressLen]))
|
||||
}
|
||||
return addresses
|
||||
}
|
||||
|
||||
// CalculateRewardForSigner calculates rewards for signers
|
||||
func CalculateRewardForSigner(chainReward *big.Int, signers map[common.Address]*RewardLog, totalSigner uint64) (map[common.Address]*big.Int, error) {
|
||||
rewardSigners := make(map[common.Address]*big.Int)
|
||||
|
||||
if totalSigner == 0 {
|
||||
return rewardSigners, nil
|
||||
}
|
||||
|
||||
rewardPerSign := new(big.Int).Div(chainReward, big.NewInt(int64(totalSigner)))
|
||||
|
||||
for addr, rLog := range signers {
|
||||
reward := new(big.Int).Mul(rewardPerSign, big.NewInt(int64(rLog.Sign)))
|
||||
rewardSigners[addr] = reward
|
||||
}
|
||||
|
||||
return rewardSigners, nil
|
||||
}
|
||||
|
||||
// CalculateRewardForHolders calculates rewards for token holders
|
||||
func CalculateRewardForHolders(foundationWalletAddr common.Address, statedb *state.StateDB, signer common.Address, calcReward *big.Int, blockNumber uint64) (map[common.Address]*big.Int, error) {
|
||||
rewards := make(map[common.Address]*big.Int)
|
||||
|
||||
// Simple distribution: foundation gets foundation percent, signer gets rest
|
||||
foundationReward := new(big.Int).Mul(calcReward, big.NewInt(int64(common.RewardFoundationPercent)))
|
||||
foundationReward.Div(foundationReward, big.NewInt(100))
|
||||
|
||||
signerReward := new(big.Int).Sub(calcReward, foundationReward)
|
||||
|
||||
if foundationWalletAddr != (common.Address{}) {
|
||||
rewards[foundationWalletAddr] = foundationReward
|
||||
}
|
||||
rewards[signer] = signerReward
|
||||
|
||||
return rewards, nil
|
||||
}
|
||||
|
||||
// DecodeExtraFields decodes extra data fields from header
|
||||
func DecodeExtraFields(extra []byte) (common.Address, []byte, error) {
|
||||
if len(extra) < extraVanity {
|
||||
return common.Address{}, nil, errors.New("extra-data too short")
|
||||
}
|
||||
|
||||
// Extract vanity
|
||||
vanity := extra[:extraVanity]
|
||||
|
||||
// Extract signer
|
||||
if len(extra) < extraVanity+extraSeal {
|
||||
return common.Address{}, vanity, errors.New("missing signature")
|
||||
}
|
||||
|
||||
signature := extra[len(extra)-extraSeal:]
|
||||
_ = signature // Would be used to recover signer
|
||||
|
||||
return common.Address{}, vanity, nil
|
||||
}
|
||||
|
||||
// CompareSignersLists compares two lists of signers
|
||||
func CompareSignersLists(list1, list2 []common.Address) bool {
|
||||
if len(list1) != len(list2) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := range list1 {
|
||||
if list1[i] != list2[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// BytesEqual compares two byte slices
|
||||
func BytesEqual(a, b []byte) bool {
|
||||
return bytes.Equal(a, b)
|
||||
}
|
||||
|
|
|
|||
212
contracts/utils_test.go
Normal file
212
contracts/utils_test.go
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
// Copyright (c) 2018 XDPoSChain
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package contracts
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/consensus/XDPoS/utils"
|
||||
"github.com/ethereum/go-ethereum/contracts/blocksigner"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
)
|
||||
|
||||
var (
|
||||
acc1Key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
|
||||
acc2Key, _ = crypto.HexToECDSA("49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee")
|
||||
acc3Key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||
acc4Key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee04aefe388d1e14474d32c45c72ce7b7a")
|
||||
acc1Addr = crypto.PubkeyToAddress(acc1Key.PublicKey)
|
||||
acc2Addr = crypto.PubkeyToAddress(acc2Key.PublicKey)
|
||||
acc3Addr = crypto.PubkeyToAddress(acc3Key.PublicKey)
|
||||
acc4Addr = crypto.PubkeyToAddress(acc4Key.PublicKey)
|
||||
)
|
||||
|
||||
func getCommonBackend() *backends.SimulatedBackend {
|
||||
genesis := types.GenesisAlloc{acc1Addr: {Balance: big.NewInt(1000000000000)}}
|
||||
backend := backends.NewXDCSimulatedBackend(genesis, 10000000, params.TestXDPoSMockChainConfig)
|
||||
backend.Commit()
|
||||
|
||||
return backend
|
||||
}
|
||||
|
||||
func TestSendTxSign(t *testing.T) {
|
||||
accounts := []common.Address{acc2Addr, acc3Addr, acc4Addr}
|
||||
keys := []*ecdsa.PrivateKey{acc2Key, acc3Key, acc4Key}
|
||||
backend := getCommonBackend()
|
||||
signer := types.HomesteadSigner{}
|
||||
ctx := context.Background()
|
||||
|
||||
transactOpts := bind.NewKeyedTransactor(acc1Key)
|
||||
blockSignerAddr, blockSigner, err := blocksigner.DeployBlockSigner(transactOpts, backend, big.NewInt(99))
|
||||
if err != nil {
|
||||
t.Fatalf("Can't get block signer: %v", err)
|
||||
}
|
||||
backend.Commit()
|
||||
|
||||
nonces := make(map[*ecdsa.PrivateKey]int)
|
||||
oldBlocks := make(map[common.Hash]common.Address)
|
||||
|
||||
signTx := func(ctx context.Context, backend *backends.SimulatedBackend, signer types.HomesteadSigner, nonces map[*ecdsa.PrivateKey]int, accKey *ecdsa.PrivateKey, blockNumber *big.Int, blockHash common.Hash) *types.Transaction {
|
||||
tx, _ := types.SignTx(CreateTxSign(blockNumber, blockHash, uint64(nonces[accKey]), blockSignerAddr), signer, accKey)
|
||||
backend.SendTransaction(ctx, tx)
|
||||
backend.Commit()
|
||||
nonces[accKey]++
|
||||
|
||||
return tx
|
||||
}
|
||||
|
||||
// Tx sign for signer.
|
||||
signCount := int64(0)
|
||||
blockHashes := make([]common.Hash, 10)
|
||||
for i := int64(0); i < 10; i++ {
|
||||
blockHash := randomHash()
|
||||
blockHashes[i] = blockHash
|
||||
randIndex := rand.Intn(len(keys))
|
||||
accKey := keys[randIndex]
|
||||
signTx(ctx, backend, signer, nonces, accKey, new(big.Int).SetInt64(i), blockHash)
|
||||
oldBlocks[blockHash] = accounts[randIndex]
|
||||
signCount++
|
||||
|
||||
// Tx sign for validators.
|
||||
for _, key := range keys {
|
||||
if key != accKey {
|
||||
signTx(ctx, backend, signer, nonces, key, new(big.Int).SetInt64(i), blockHash)
|
||||
signCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, blockHash := range blockHashes {
|
||||
signers, err := blockSigner.GetSigners(blockHash)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't get signers: %v", err)
|
||||
}
|
||||
|
||||
if signers[0] != oldBlocks[blockHash] {
|
||||
t.Errorf("Tx sign for block signer not match %v - %v", signers[0].String(), oldBlocks[blockHash].String())
|
||||
}
|
||||
|
||||
if len(signers) != len(keys) {
|
||||
t.Error("Tx sign for block validators not match")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate random string.
|
||||
func randomHash() common.Hash {
|
||||
letterBytes := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"
|
||||
var b common.Hash
|
||||
for i := range b {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
b[i] = letterBytes[rand.Intn(len(letterBytes))]
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// Unit test for get random position of masternodes.
|
||||
func TestRandomMasterNode(t *testing.T) {
|
||||
oldSlice := NewSlice(0, 10, 1)
|
||||
newSlice := Shuffle(oldSlice)
|
||||
for _, newNumber := range newSlice {
|
||||
for i, oldNumber := range oldSlice {
|
||||
if oldNumber == newNumber {
|
||||
// Delete find element.
|
||||
oldSlice = append(oldSlice[:i], oldSlice[i+1:]...)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(oldSlice) != 0 {
|
||||
t.Errorf("Test generate random masternode fail %v - %v", oldSlice, newSlice)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncryptDecrypt(t *testing.T) {
|
||||
//byteInteger := common.LeftPadBytes([]byte(new(big.Int).SetInt64(4).String()), 32)
|
||||
randomByte := RandStringByte(32)
|
||||
encrypt := Encrypt(randomByte, new(big.Int).SetInt64(4).String())
|
||||
decrypt := Decrypt(randomByte, encrypt)
|
||||
t.Log("Encrypt", encrypt, "Test", string(randomByte), "Decrypt", decrypt, "trim", string(bytes.TrimLeft([]byte(decrypt), "\x00")))
|
||||
}
|
||||
|
||||
func isArrayEqual(a [][]int64, b [][]int64) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for i, vs := range a {
|
||||
for j, v := range vs {
|
||||
if v != b[i][j] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Unit test for
|
||||
func TestGenM2FromRandomize(t *testing.T) {
|
||||
var a []int64
|
||||
for i := 0; i <= 10; i++ {
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
a = append(a, int64(rand.Intn(9999)))
|
||||
}
|
||||
b, err := GenM2FromRandomize(a, common.MaxMasternodes)
|
||||
t.Log("randomize", b, "len", len(b))
|
||||
if err != nil {
|
||||
t.Error("Fail to test gen m2 for randomize.", err)
|
||||
}
|
||||
// Test Permutation Without Fixed-point.
|
||||
M1List := NewSlice(int64(0), common.MaxMasternodes, 1)
|
||||
for i, m1 := range M1List {
|
||||
if m1 == b[i] {
|
||||
t.Errorf("Error check Permutation Without Fixed-point %v - %v - %v", i, b[i], a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Unit test for validator m2.
|
||||
func TestBuildValidatorFromM2(t *testing.T) {
|
||||
a := []int64{84, 58, 27, 96, 127, 60, 136, 20, 121, 31, 87, 85, 40, 120, 149, 109, 141, 145, 11, 110, 147, 35, 76, 46, 34, 108, 72, 103, 102, 12, 23, 47, 70, 86, 125, 112, 128, 13, 130, 98, 126, 62, 132, 111, 134, 6, 106, 67, 24, 91, 101, 50, 94, 43, 77, 73, 129, 71, 51, 10, 92, 29, 80, 95, 33, 100, 124, 75, 38, 133, 79, 83, 61, 36, 122, 99, 16, 28, 18, 116, 140, 97, 119, 82, 148, 48, 56, 32, 93, 107, 69, 68, 123, 81, 22, 137, 25, 115, 44, 8, 42, 131, 143, 17, 55, 89, 9, 15, 19, 59, 146, 54, 5, 30, 41, 144, 117, 1, 104, 49, 105, 45, 88, 78, 74, 135, 0, 21, 57, 3, 66, 52, 63, 138, 4, 114, 37, 118, 14, 2, 26, 7, 65, 139, 39, 64, 90, 142, 53, 113}
|
||||
b := BuildValidatorFromM2(a)
|
||||
c := utils.ExtractValidatorsFromBytes(b)
|
||||
if !isArrayEqual([][]int64{a}, [][]int64{c}) {
|
||||
t.Errorf("Fail to get m2 result %v", b)
|
||||
}
|
||||
}
|
||||
|
||||
// Unit test for decode validator string data.
|
||||
func TestDecodeValidatorsHexData(t *testing.T) {
|
||||
a := "0x000000310000003000000032000000310000003000000032000000310000003000000032000000310000003000000031000000320000003000000031000000320000003000000031000000320000003000000030000000310000003200000030000000310000003200000030000000310000003200000030000000300000003100000032000000300000003100000032000000300000003100000032000000300000003200000030000000310000003200000030000000310000003200000030000000310000003000000030"
|
||||
b, err := DecodeValidatorsHexData(a)
|
||||
if err != nil {
|
||||
t.Error("Fail to decode validator from hex string", err)
|
||||
}
|
||||
c := []int64{1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 2, 0, 1, 2, 0, 1, 2, 0, 1, 0, 0}
|
||||
if !isArrayEqual([][]int64{b}, [][]int64{c}) {
|
||||
t.Errorf("Fail to get m2 result %v", b)
|
||||
}
|
||||
t.Log("b", b)
|
||||
}
|
||||
2050
contracts/validator/contract/validator.go
Normal file
2050
contracts/validator/contract/validator.go
Normal file
File diff suppressed because one or more lines are too long
196
docker/XDPoSChain/entrypoint.sh
Executable file
196
docker/XDPoSChain/entrypoint.sh
Executable file
|
|
@ -0,0 +1,196 @@
|
|||
#!/bin/sh
|
||||
|
||||
# vars from docker env
|
||||
# - IDENTITY (default to empty)
|
||||
# - PASSWORD (default to empty)
|
||||
# - PRIVATE_KEY (default to empty)
|
||||
# - BOOTNODES (default to empty)
|
||||
# - EXTIP (default to empty)
|
||||
# - VERBOSITY (default to 3)
|
||||
# - MAXPEERS (default to 25)
|
||||
# - SYNC_MODE (default to 'full')
|
||||
# - NETWORK_ID (default to '89')
|
||||
# - WS_SECRET (default to empty)
|
||||
# - NETSTATS_HOST (default to 'netstats-server:3000')
|
||||
# - NETSTATS_PORT (default to 'netstats-server:3000')
|
||||
|
||||
# constants
|
||||
DATA_DIR="data"
|
||||
KEYSTORE_DIR="keystore"
|
||||
|
||||
# variables
|
||||
genesisPath=""
|
||||
params=""
|
||||
accountsCount=$(
|
||||
XDC account list --datadir $DATA_DIR --keystore $KEYSTORE_DIR \
|
||||
2> /dev/null \
|
||||
| wc -l
|
||||
)
|
||||
|
||||
# file to env
|
||||
for env in IDENTITY PASSWORD PRIVATE_KEY BOOTNODES WS_SECRET NETSTATS_HOST \
|
||||
NETSTATS_PORT EXTIP SYNC_MODE NETWORK_ID ANNOUNCE_TXS STORE_REWARD DEBUG_MODE MAXPEERS; do
|
||||
file=$(eval echo "\$${env}_FILE")
|
||||
if [[ -f $file ]] && [[ ! -z $file ]]; then
|
||||
echo "Replacing $env by $file"
|
||||
export $env=$(cat $file)
|
||||
elif [[ "$env" == "BOOTNODES" ]] && [[ ! -z $file ]]; then
|
||||
echo "Bootnodes file is not available. Waiting for it to be provisioned..."
|
||||
while true ; do
|
||||
if [[ -f $file ]] && [[ $(grep -e enode $file) ]]; then
|
||||
echo "Fount bootnode file."
|
||||
break
|
||||
fi
|
||||
echo "Still no bootnodes file, sleeping..."
|
||||
sleep 5
|
||||
done
|
||||
export $env=$(cat $file)
|
||||
fi
|
||||
done
|
||||
|
||||
# networkid
|
||||
if [[ ! -z $NETWORK_ID ]]; then
|
||||
case $NETWORK_ID in
|
||||
88 )
|
||||
genesisPath="mainnet.json"
|
||||
;;
|
||||
89 )
|
||||
genesisPath="testnet.json"
|
||||
params="$params --apothem --gcmode archive --http-api db,eth,net,web3,debug,XDPoS"
|
||||
;;
|
||||
90 )
|
||||
genesisPath="devnet.json"
|
||||
;;
|
||||
* )
|
||||
echo "network id not supported"
|
||||
;;
|
||||
esac
|
||||
params="$params --networkid $NETWORK_ID"
|
||||
fi
|
||||
|
||||
# custom genesis path
|
||||
if [[ ! -z $GENESIS_PATH ]]; then
|
||||
genesisPath="$GENESIS_PATH"
|
||||
fi
|
||||
|
||||
# data dir
|
||||
if [[ ! -d $DATA_DIR/XDC ]]; then
|
||||
echo "No blockchain data, creating genesis block."
|
||||
XDC init $genesisPath --datadir $DATA_DIR 2> /dev/null
|
||||
fi
|
||||
|
||||
# identity
|
||||
if [[ -z $IDENTITY ]]; then
|
||||
IDENTITY="unnamed_$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6)"
|
||||
fi
|
||||
|
||||
# password file
|
||||
if [[ ! -f ./password ]]; then
|
||||
if [[ ! -z $PASSWORD ]]; then
|
||||
echo "Password env is set. Writing into file."
|
||||
echo "$PASSWORD" > ./password
|
||||
else
|
||||
echo "No password set (or empty), generating a new one"
|
||||
$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32} > password)
|
||||
fi
|
||||
fi
|
||||
|
||||
# private key
|
||||
if [[ $accountsCount -le 0 ]]; then
|
||||
echo "No accounts found"
|
||||
if [[ ! -z $PRIVATE_KEY ]]; then
|
||||
echo "Creating account from private key"
|
||||
echo "$PRIVATE_KEY" > ./private_key
|
||||
XDC account import ./private_key \
|
||||
--datadir $DATA_DIR \
|
||||
--keystore $KEYSTORE_DIR \
|
||||
--password ./password
|
||||
rm ./private_key
|
||||
else
|
||||
echo "Creating new account"
|
||||
XDC account new \
|
||||
--datadir $DATA_DIR \
|
||||
--keystore $KEYSTORE_DIR \
|
||||
--password ./password
|
||||
fi
|
||||
fi
|
||||
account=$(
|
||||
XDC account list --datadir $DATA_DIR --keystore $KEYSTORE_DIR \
|
||||
2> /dev/null \
|
||||
| head -n 1 \
|
||||
| cut -d"{" -f 2 | cut -d"}" -f 1
|
||||
)
|
||||
echo "Using account $account"
|
||||
params="$params --unlock $account"
|
||||
|
||||
# bootnodes
|
||||
if [[ ! -z $BOOTNODES ]]; then
|
||||
params="$params --bootnodes $BOOTNODES"
|
||||
fi
|
||||
|
||||
# extip
|
||||
if [[ ! -z $EXTIP ]]; then
|
||||
params="$params --nat extip:${EXTIP}"
|
||||
fi
|
||||
|
||||
# syncmode
|
||||
if [[ ! -z $SYNC_MODE ]]; then
|
||||
params="$params --syncmode ${SYNC_MODE}"
|
||||
fi
|
||||
|
||||
# netstats
|
||||
if [[ ! -z $WS_SECRET ]]; then
|
||||
echo "Will report to netstats server ${NETSTATS_HOST}:${NETSTATS_PORT}"
|
||||
params="$params --ethstats ${IDENTITY}:${WS_SECRET}@${NETSTATS_HOST}:${NETSTATS_PORT}"
|
||||
else
|
||||
echo "WS_SECRET not set, will not report to netstats server."
|
||||
fi
|
||||
|
||||
# annonce txs
|
||||
if [[ ! -z $ANNOUNCE_TXS ]]; then
|
||||
params="$params --announce-txs"
|
||||
fi
|
||||
|
||||
# store reward
|
||||
if [[ ! -z $STORE_REWARD ]]; then
|
||||
params="$params --store-reward"
|
||||
fi
|
||||
|
||||
# debug mode
|
||||
if [[ ! -z $DEBUG_MODE ]]; then
|
||||
params="$params --gcmode archive --http-api db,eth,net,web3,debug,XDPoS"
|
||||
fi
|
||||
|
||||
# maxpeers
|
||||
if [[ -z $MAXPEERS ]]; then
|
||||
MAXPEERS=25
|
||||
fi
|
||||
|
||||
# dump
|
||||
echo "dump: $IDENTITY $account $BOOTNODES"
|
||||
|
||||
set -x
|
||||
|
||||
exec XDC $params \
|
||||
--verbosity $VERBOSITY \
|
||||
--datadir $DATA_DIR \
|
||||
--keystore $KEYSTORE_DIR \
|
||||
--identity $IDENTITY \
|
||||
--maxpeers $MAXPEERS \
|
||||
--password ./password \
|
||||
--port 30303 \
|
||||
--txpool-globalqueue 5000 \
|
||||
--txpool-globalslots 5000 \
|
||||
--http \
|
||||
--http-corsdomain "*" \
|
||||
--http-addr 0.0.0.0 \
|
||||
--http-port 8545 \
|
||||
--http-vhosts "*" \
|
||||
--ws \
|
||||
--ws-addr 0.0.0.0 \
|
||||
--ws-port 8546 \
|
||||
--ws-origins "*" \
|
||||
--mine \
|
||||
--gasprice "250000000" \
|
||||
--miner-gaslimit "84000000" \
|
||||
"$@"
|
||||
0
docker/bootnode/bootnodes/bootnodes
Normal file
0
docker/bootnode/bootnodes/bootnodes
Normal file
24
docker/bootnode/entrypoint.sh
Executable file
24
docker/bootnode/entrypoint.sh
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
#!/bin/sh -x
|
||||
|
||||
# file to env
|
||||
for env in PRIVATE_KEY; do
|
||||
file=$(eval echo "\$${env}_FILE")
|
||||
if [[ -f $file ]] && [[ ! -z $file ]]; then
|
||||
echo "Replacing $env by $file"
|
||||
export $env=$(cat $file)
|
||||
fi
|
||||
done
|
||||
|
||||
# private key
|
||||
if [[ ! -z "$PRIVATE_KEY" ]]; then
|
||||
echo "$PRIVATE_KEY" > bootnode.key
|
||||
elif [[ ! -f ./bootnode.key ]]; then
|
||||
bootnode -genkey bootnode.key
|
||||
fi
|
||||
|
||||
# dump address
|
||||
address="enode://$(bootnode -nodekey bootnode.key -writeaddress)@[$(hostname -i)]:30301"
|
||||
|
||||
echo "$address" > ./bootnodes/bootnodes
|
||||
|
||||
exec bootnode "$@"
|
||||
36
eth/hooks/hooks.go
Normal file
36
eth/hooks/hooks.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
// Package hooks provides consensus hooks for XDPoS engine integration
|
||||
// Note: The full hook implementations (engine_v1_hooks.go, engine_v2_hooks.go)
|
||||
// require the complete XDPoS engine with EngineV1/EngineV2 support.
|
||||
// These stubs are provided for compatibility.
|
||||
|
||||
package hooks
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/consensus/XDPoS"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
)
|
||||
|
||||
// AttachConsensusV1Hooks attaches V1 consensus hooks to XDPoS engine
|
||||
// Note: This is a stub - full implementation requires EngineV1 support
|
||||
func AttachConsensusV1Hooks(adaptor *XDPoS.XDPoS, bc *core.BlockChain, chainConfig *params.ChainConfig) {
|
||||
// V1 hooks are not implemented in this simplified version
|
||||
// Full implementation would hook into:
|
||||
// - HookPenalty: Scan for bad masternodes
|
||||
// - HookPenaltyTIPSigning: Handle TIP signing penalties
|
||||
// - HookValidator: Prepare validators at checkpoint
|
||||
// - HookVerifyMNs: Verify masternode set
|
||||
// - HookGetSignersFromContract: Get signers from contract
|
||||
// - HookReward: Calculate masternode rewards
|
||||
}
|
||||
|
||||
// AttachConsensusV2Hooks attaches V2 consensus hooks to XDPoS engine
|
||||
// Note: This is a stub - full implementation requires EngineV2 support
|
||||
func AttachConsensusV2Hooks(adaptor *XDPoS.XDPoS, bc *core.BlockChain, chainConfig *params.ChainConfig) {
|
||||
// V2 hooks are not implemented in this simplified version
|
||||
// Full implementation would hook into:
|
||||
// - HookPenalty: V2 penalty handling
|
||||
// - HookValidator: V2 validator preparation
|
||||
// - HookVerifyMNs: V2 masternode verification
|
||||
// - HookReward: V2 reward calculation
|
||||
}
|
||||
53
eth/util/util.go
Normal file
53
eth/util/util.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/consensus"
|
||||
)
|
||||
|
||||
// RewardInflation calculates reward inflation based on block number and blocks per year
|
||||
func RewardInflation(chain consensus.ChainReader, chainReward *big.Int, number uint64, blockPerYear uint64) *big.Int {
|
||||
// Check if halving should be disabled (for newer chains)
|
||||
// For now, use the halving schedule
|
||||
if blockPerYear*2 <= number && number < blockPerYear*5 {
|
||||
chainReward.Div(chainReward, new(big.Int).SetUint64(2))
|
||||
}
|
||||
if blockPerYear*5 <= number {
|
||||
chainReward.Div(chainReward, new(big.Int).SetUint64(4))
|
||||
}
|
||||
|
||||
return chainReward
|
||||
}
|
||||
|
||||
// RewardHalving computes the reward for Masternode/Protector/Observer based on epoch total reward, supply after halving is enabled, and epoch after halving is enabled
|
||||
// The sequence is a geometric sequence in order to make supply be limited
|
||||
func RewardHalving(epochRewardSingle *big.Int, epochRewardTotal *big.Int, halvingSupply *big.Int, epochSinceHalving uint64) *big.Int {
|
||||
rt := new(big.Float).SetInt(epochRewardTotal)
|
||||
hs := new(big.Float).SetInt(halvingSupply)
|
||||
// zero cause Quo panic so return early
|
||||
// or epoch reward > halving supply, return early
|
||||
if halvingSupply.BitLen() == 0 || epochRewardTotal.Cmp(halvingSupply) > 0 {
|
||||
return big.NewInt(0)
|
||||
}
|
||||
quo := new(big.Float).Quo(rt, hs)
|
||||
// base = 1- reward/supply
|
||||
base := new(big.Float).Sub(big.NewFloat(1), quo)
|
||||
r := new(big.Float).SetInt(epochRewardSingle)
|
||||
result := new(big.Float).Mul(r, FloatPower(base, epochSinceHalving))
|
||||
resultInt, _ := result.Int(nil)
|
||||
return resultInt
|
||||
}
|
||||
|
||||
// FloatPower calculates base^exp for big.Float
|
||||
func FloatPower(base *big.Float, exp uint64) *big.Float {
|
||||
result := big.NewFloat(1)
|
||||
for exp > 0 {
|
||||
if exp%2 == 1 {
|
||||
result.Mul(result, base)
|
||||
}
|
||||
base.Mul(base, base)
|
||||
exp >>= 1 // same as: exp = exp / 2
|
||||
}
|
||||
return result
|
||||
}
|
||||
208
genesis/XDCxnet.json
Normal file
208
genesis/XDCxnet.json
Normal file
File diff suppressed because one or more lines are too long
279
genesis/devnet.json
Normal file
279
genesis/devnet.json
Normal file
File diff suppressed because one or more lines are too long
14
genesis/genesis.go
Normal file
14
genesis/genesis.go
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package genesis
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
//go:embed mainnet.json
|
||||
var MainnetGenesis []byte
|
||||
|
||||
//go:embed testnet.json
|
||||
var TestnetGenesis []byte
|
||||
|
||||
//go:embed devnet.json
|
||||
var DevnetGenesis []byte
|
||||
113
genesis/mainnet.json
Normal file
113
genesis/mainnet.json
Normal file
File diff suppressed because one or more lines are too long
142
genesis/testnet.json
Normal file
142
genesis/testnet.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue