eth

package
v0.0.0-...-8d1786a Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: Apache-2.0 Imports: 25 Imported by: 9

Documentation

Index

Constants

View Source
const (
	// TxListenerTransactionCompleteMsg is the message sent when the transaction is completed
	TxListenerTransactionCompleteMsg = "Transaction is complete"

	// TxListenerTransactionPendingMsg is the message sent when the transaction completion is
	// pending
	TxListenerTransactionPendingMsg = "Transaction is pending"

	// TxListenerTransactionErrorMsgPrefix is the message sent when there is an error with transaction
	// polling
	TxListenerTransactionErrorMsgPrefix = "Error: err:"
)

Variables

This section is empty.

Functions

func ABILinkLibrary

func ABILinkLibrary(bin string, libraryName string, libraryAddress common.Address) string

ABILinkLibrary replaces references to a library with the actual addresses to those library contracts

func AsEthereumSignature

func AsEthereumSignature(msg string) string

AsEthereumSignedMessage adds a prefix and len to the message to identify it as an Ethereum specific signature. https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign

func DecodeSignatureBytes

func DecodeSignatureBytes(signature string) ([]byte, error)

DecodeSignatureBytes decodes a signature to bytes. Handles signature hex strings with or without 0x prefix.

func DeployContractWithLinks(
	opts *bind.TransactOpts,
	backend bind.ContractBackend,
	abiString string,
	bin string,
	libraries map[string]common.Address,
	params ...interface{},
) (common.Address, *types.Transaction, *bind.BoundContract, error)

DeployContractWithLinks patches a contract bin with provided library addresses

func GetEthAddressFromPrivateKey

func GetEthAddressFromPrivateKey(privateKey *ecdsa.PrivateKey) common.Address

GetEthAddressFromPrivateKey returns the Ethereum address for a given ECDSA private key

func NormalizeEthAddress

func NormalizeEthAddress(addr string) string

NormalizeEthAddress takes a string address to normalize the case of the ethereum address when it is a string. Runs through common.Address.Hex().

func SignEthMessage

func SignEthMessage(pk *ecdsa.PrivateKey, message string) (string, error)

SignEthMessage signs a given message with the given ECDSA private key. Returns the signature as a hex string with 0x prefix.

func VerifyEthChallenge

func VerifyEthChallenge(prefix string, gracePeriod int64, challenge string) error

VerifyEthChallenge confirms that a "challenge" string has a timestamp that is within {gracePeriod} number of seconds from the current time this is used to ensure that an attacker cannot reuse previously signed messages Challenge should be in the form of "{prefix} @ 2018-01-04T17:48:32-05:00"

func VerifyEthChallengeAndSignature

func VerifyEthChallengeAndSignature(request ChallengeRequest) error

VerifyEthChallengeAndSignature accepts a ChallengeRequest and verifies that it is valid

func VerifyEthSignature

func VerifyEthSignature(address string, message string, signature string) (bool, error)

VerifyEthSignature accepts an Ethereum address, a message string, and a signature and confirms that the signature was indeed signed by the address specified Handles signatures with and without 0x prefixes

func VerifyEthSignatureWithPubkey

func VerifyEthSignatureWithPubkey(pubKey ecdsa.PublicKey, message string, signature string) (bool, error)

VerifyEthSignatureWithPubkey accepts an ECDSA public key, a message string, and a signature and confirms that the signature was indeed signed by the key specified Handles signatures with and without 0x prefixes

func WebsocketPing

func WebsocketPing(client *ethclient.Client, killChan <-chan struct{}, pingIntervalSecs int)

WebsocketPing periodically makes a call over the given websocket conn to the Eth node to ensure the connection stays alive. Since there is no built in facility to do pings with the go-eth lib, need to do this ourselves by making a eth_getHeaderByNumber RPC call. NOTE(PN): Need to ensure the client passed in is a websocket client. XXX(PN): I'm not sure of it's effectiveness since all nodes may be configured differently in regards to keeping connections open.

Types

type Account

type Account struct {
	Key     *ecdsa.PrivateKey
	Auth    *bind.TransactOpts
	Address common.Address
}

Account groups a private key, authentication, and ETH address

func AccountFromPK

func AccountFromPK(privateKey string) (Account, error)

AccountFromPK constructs an Account from the provided ECDSA private key hex string

func MakeAccount

func MakeAccount() (Account, error)

MakeAccount generates a new random Account

type BlockHeaderCache

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

BlockHeaderCache stores a memory map of blockNumber to the types.Block. Used as a cache to prevent multiple access via the ethclient

func NewBlockHeaderCache

func NewBlockHeaderCache(expirySecs int64) *BlockHeaderCache

NewBlockHeaderCache is a convenience function to init a BlockHeaderCache

func (*BlockHeaderCache) AddHeader

func (b *BlockHeaderCache) AddHeader(num uint64, header *types.Header)

AddHeader adds a types.Block to the map with the key being block number.

func (*BlockHeaderCache) HeaderByBlockNumber

func (b *BlockHeaderCache) HeaderByBlockNumber(num uint64) *types.Header

HeaderByBlockNumber returns a types.Block if it exists in the map given the block number. Returns nil if not found in map. If block was added more than expiryPeriodSecs ago, will return nil.

type ChallengeRequest

type ChallengeRequest struct {
	ExpectedPrefix string
	GracePeriod    int64
	InputAddress   string
	InputChallenge string
	Signature      string
}

ChallengeRequest contains a signature and the fields needed to verify it

type Deployer

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

Deployer provides helper methods to deploy Civil smart contracts

func NewDeployer

func NewDeployer(helper *Helper, addresses *DeployerContractAddresses) *Deployer

NewDeployer builds a new Deployer instance

func (*Deployer) DeployAttributeStore

func (d *Deployer) DeployAttributeStore() error

DeployAttributeStore deploys the AttributeStore library

func (*Deployer) DeployCVLToken

func (d *Deployer) DeployCVLToken() error

DeployCVLToken deploys the CVL Token contract

func (*Deployer) DeployCivilTokenController

func (d *Deployer) DeployCivilTokenController() error

DeployCivilTokenController creates a new CivilTokenController contract

func (*Deployer) DeployCreateNewsroomInGroup

func (d *Deployer) DeployCreateNewsroomInGroup() error

DeployCreateNewsroomInGroup creates a new instance of the CreateNewsroomInGroup contract

func (*Deployer) DeployDLL

func (d *Deployer) DeployDLL() error

DeployDLL deploys the DLL library

func (*Deployer) DeployECRecovery

func (d *Deployer) DeployECRecovery() error

DeployECRecovery deploys ECRecovery library

func (*Deployer) DeployGovernment

func (d *Deployer) DeployGovernment(config []interface{}, appellateAddr common.Address, governmentControllerAddr common.Address) error

DeployGovernment creates a new Government contract mostly borrowed from https://github.com/joincivil/civil-events-crawler/blob/a7754bc767a7c0f09ef1ace4dd67b86b0b322326/pkg/contractutils/contractutils.go#L487

func (*Deployer) DeployMessagesAndCodes

func (d *Deployer) DeployMessagesAndCodes() error

DeployMessagesAndCodes deploys the MessagesAndCodes library

func (*Deployer) DeployMultiSigWalletFactory

func (d *Deployer) DeployMultiSigWalletFactory() error

DeployMultiSigWalletFactory creates a new instance of the MultiSigWalletFactory contract

func (*Deployer) DeployNewsroomFactory

func (d *Deployer) DeployNewsroomFactory() error

DeployNewsroomFactory deploys the NewsroomFactory contract and links required libraries

func (*Deployer) DeployPLCR

func (d *Deployer) DeployPLCR() error

DeployPLCR deploys the PLCR contract

func (*Deployer) DeployParameterizer

func (d *Deployer) DeployParameterizer(config []*big.Int) error

DeployParameterizer deploys the Parameterizer contract

func (*Deployer) DeployTCR

func (d *Deployer) DeployTCR() error

DeployTCR creates a new TCR contract

type DeployerContractAddresses

type DeployerContractAddresses struct {
	NewsroomFactory       common.Address
	MultisigFactory       common.Address
	CivilTokenController  common.Address
	CreateNewsroomInGroup common.Address
	PLCR                  common.Address
	TCR                   common.Address
	CVLToken              common.Address
	Parameterizer         common.Address
	Government            common.Address

	// libraries
	AttributeStore   common.Address
	DLL              common.Address
	ECRecovery       common.Address
	MessagesAndCodes common.Address
}

DeployerContractAddresses tracks smart contract addresses

type GovernmentConfig

type GovernmentConfig struct {
	AppealFeeAmount                    *big.Int
	RequestAppealPhaseLength           *big.Int
	JudgeAppealPhaseLength             *big.Int
	AppealSupermajorityPercentage      *big.Int
	AppealChallengeVoteDispensationPct *big.Int
	PDeposit                           *big.Int
	PCommitStageLength                 *big.Int
	PRevealStageLength                 *big.Int
	ConstitutionHash                   [32]byte
	ConstitutionURI                    string
}

GovernmentConfig contains the fields needed to instatiate the Government contract

func NewDefaultGovernmentConfig

func NewDefaultGovernmentConfig() *GovernmentConfig

NewDefaultGovernmentConfig returns default values to use when creating the Government contract

func (*GovernmentConfig) AsArray

func (g *GovernmentConfig) AsArray() []interface{}

AsArray returns a config fields as an array needed for the contract parameter

type Helper

type Helper struct {
	Blockchain bind.ContractBackend
	Key        *ecdsa.PrivateKey
	Auth       *bind.TransactOpts
	Accounts   map[string]Account
}

Helper provides methods to create Ethereum transactions

func NewETHClientHelper

func NewETHClientHelper(ethAPIURL string, accountKeys map[string]string) (*Helper, error)

NewETHClientHelper creates a new Helper using an ethclient with the provided URL accountKeys is a mapping of name->privateKey hex string

func NewSimulatedBackendHelper

func NewSimulatedBackendHelper() (*Helper, error)

NewSimulatedBackendHelper creates a new Helper using an ethereum SimulatedBackend generates accounts for "genesis", "alice", "bob", "carol", "dan", "erin"

func (*Helper) AddAccount

func (h *Helper) AddAccount(name string) (Account, error)

AddAccount generates a new account and adds it to the account mapping

func (*Helper) Call

func (h *Helper) Call() *bind.CallOpts

Call creates an empty bind.CallOpts instance

func (*Helper) Transact

func (h *Helper) Transact() *bind.TransactOpts

Transact creates a barebones bind.TransactOpts using the helper's account

func (*Helper) TransactWithGasLimit

func (h *Helper) TransactWithGasLimit() *bind.TransactOpts

TransactWithGasLimit creates a bind.TransactOpts object with a default gas limit using the helper's account

type ParameterizerConfig

type ParameterizerConfig struct {
	MinDeposit                       *big.Int
	PMinDeposit                      *big.Int
	ApplyStageLength                 *big.Int
	PApplyStageLength                *big.Int
	CommitStageLength                *big.Int
	PCommitStageLength               *big.Int
	RevealStageLength                *big.Int
	PRevealStageLength               *big.Int
	DispensationPct                  *big.Int
	PDispensationPct                 *big.Int
	VoteQuorum                       *big.Int
	PVoteQuorum                      *big.Int
	PProcessBy                       *big.Int
	ChallengeAppealLength            *big.Int
	AppealChallengeCommitStageLength *big.Int
	AppealChallengeRevealStageLength *big.Int
}

ParameterizerConfig contains the attributes needed to instantiate the Parameterizer contract

func NewDefaultParameterizerConfig

func NewDefaultParameterizerConfig() *ParameterizerConfig

NewDefaultParameterizerConfig returns default values to use when creating the Parameterizer contract

func (*ParameterizerConfig) AsArray

func (p *ParameterizerConfig) AsArray() []*big.Int

AsArray returns the ParameterizerConfig as an IntArray needed for the contract parameter

type RetryChainReader

type RetryChainReader struct {
	ethereum.ChainReader
}

RetryChainReader is a ChainReader that includes some version of ChainReader functions that are wrapped by a retry mechanism

func (*RetryChainReader) HeaderByNumberWithRetry

func (r *RetryChainReader) HeaderByNumberWithRetry(blockNumber uint64, maxAttempts int,
	baseWaitMs int) (*types.Header, error)

HeaderByNumberWithRetry is a version of HeaderByNumber that has a retry mechanism

type RetryCivilTCRContract

type RetryCivilTCRContract struct {
	*contract.CivilTCRContract
}

RetryCivilTCRContract is a CivilTCRContract that includes functions to make contract calls that retry.

func (*RetryCivilTCRContract) ChallengeRequestAppealExpiriesWithRetry

func (r *RetryCivilTCRContract) ChallengeRequestAppealExpiriesWithRetry(opts *bind.CallOpts,
	challengeID *big.Int, maxAttempts int, baseWaitMs int) (*big.Int, error)

ChallengeRequestAppealExpiriesWithRetry is a version of ChallengeRequestAppealExpiriesWithRetry that has a retry mechanism Will retry on empty values for challenges or on error

func (*RetryCivilTCRContract) ChallengesWithRetry

func (r *RetryCivilTCRContract) ChallengesWithRetry(opts *bind.CallOpts, challengeID *big.Int,
	maxAttempts int, baseWaitMs int) (struct {
	RewardPool  *big.Int
	Challenger  common.Address
	Resolved    bool
	Stake       *big.Int
	TotalTokens *big.Int
}, error)

ChallengesWithRetry is a version of Challenges that has a retry mechanism Will retry on empty values for challenges or on error

type Service

type Service struct {
	TxListener *TxListener
}

Service provides tools that help with interacting with the Ethereum blockchain

func NewService

func NewService(txListener *TxListener) *Service

NewService creates a new Service instance

type TxListener

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

TxListener provides methods to interact with Ethereum transactions

func NewTxListener

func NewTxListener(blockchain ethereum.TransactionReader, jobs jobs.JobService) *TxListener

NewTxListener creates a new TransactionService instance

func NewTxListenerWithWaitPeriod

func NewTxListenerWithWaitPeriod(blockchain ethereum.TransactionReader, jobs jobs.JobService, timeout time.Duration) *TxListener

NewTxListenerWithWaitPeriod creates a new TransactionService instance with a wait period

func (*TxListener) PollForTxCompletion

func (t *TxListener) PollForTxCompletion(txID string, updates chan<- string)

PollForTxCompletion will continuously poll until a transaction is complete

func (*TxListener) StartListener

func (t *TxListener) StartListener(txID string) (*jobs.Subscription, error)

StartListener begins listening for an ethereum transaction

func (*TxListener) StopSubscription

func (t *TxListener) StopSubscription(receipt *jobs.Subscription) error

StopSubscription will stop subscribing to job updates this will not cancel the actual job

Jump to

Keyboard shortcuts

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