Documentation ¶
Index ¶
- Constants
- func ABILinkLibrary(bin string, libraryName string, libraryAddress common.Address) string
- func AsEthereumSignature(msg string) string
- func DecodeSignatureBytes(signature string) ([]byte, error)
- func DeployContractWithLinks(opts *bind.TransactOpts, backend bind.ContractBackend, abiString string, ...) (common.Address, *types.Transaction, *bind.BoundContract, error)
- func GetEthAddressFromPrivateKey(privateKey *ecdsa.PrivateKey) common.Address
- func NormalizeEthAddress(addr string) string
- func SignEthMessage(pk *ecdsa.PrivateKey, message string) (string, error)
- func VerifyEthChallenge(prefix string, gracePeriod int64, challenge string) error
- func VerifyEthChallengeAndSignature(request ChallengeRequest) error
- func VerifyEthSignature(address string, message string, signature string) (bool, error)
- func VerifyEthSignatureWithPubkey(pubKey ecdsa.PublicKey, message string, signature string) (bool, error)
- func WebsocketPing(client *ethclient.Client, killChan <-chan struct{}, pingIntervalSecs int)
- type Account
- type BlockHeaderCache
- type ChallengeRequest
- type Deployer
- func (d *Deployer) DeployAttributeStore() error
- func (d *Deployer) DeployCVLToken() error
- func (d *Deployer) DeployCivilTokenController() error
- func (d *Deployer) DeployCreateNewsroomInGroup() error
- func (d *Deployer) DeployDLL() error
- func (d *Deployer) DeployECRecovery() error
- func (d *Deployer) DeployGovernment(config []interface{}, appellateAddr common.Address, ...) error
- func (d *Deployer) DeployMessagesAndCodes() error
- func (d *Deployer) DeployMultiSigWalletFactory() error
- func (d *Deployer) DeployNewsroomFactory() error
- func (d *Deployer) DeployPLCR() error
- func (d *Deployer) DeployParameterizer(config []*big.Int) error
- func (d *Deployer) DeployTCR() error
- type DeployerContractAddresses
- type GovernmentConfig
- type Helper
- type ParameterizerConfig
- type RetryChainReader
- type RetryCivilTCRContract
- func (r *RetryCivilTCRContract) ChallengeRequestAppealExpiriesWithRetry(opts *bind.CallOpts, challengeID *big.Int, maxAttempts int, baseWaitMs int) (*big.Int, error)
- func (r *RetryCivilTCRContract) ChallengesWithRetry(opts *bind.CallOpts, challengeID *big.Int, maxAttempts int, baseWaitMs int) (struct{ ... }, error)
- type Service
- type TxListener
Constants ¶
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 ¶
ABILinkLibrary replaces references to a library with the actual addresses to those library contracts
func AsEthereumSignature ¶
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 ¶
DecodeSignatureBytes decodes a signature to bytes. Handles signature hex strings with or without 0x prefix.
func DeployContractWithLinks ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
AccountFromPK constructs an Account from the provided ECDSA private key hex string
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 ¶
DeployAttributeStore deploys the AttributeStore library
func (*Deployer) DeployCVLToken ¶
DeployCVLToken deploys the CVL Token contract
func (*Deployer) DeployCivilTokenController ¶
DeployCivilTokenController creates a new CivilTokenController contract
func (*Deployer) DeployCreateNewsroomInGroup ¶
DeployCreateNewsroomInGroup creates a new instance of the CreateNewsroomInGroup contract
func (*Deployer) DeployECRecovery ¶
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 ¶
DeployMessagesAndCodes deploys the MessagesAndCodes library
func (*Deployer) DeployMultiSigWalletFactory ¶
DeployMultiSigWalletFactory creates a new instance of the MultiSigWalletFactory contract
func (*Deployer) DeployNewsroomFactory ¶
DeployNewsroomFactory deploys the NewsroomFactory contract and links required libraries
func (*Deployer) DeployPLCR ¶
DeployPLCR deploys the PLCR contract
func (*Deployer) DeployParameterizer ¶
DeployParameterizer deploys the Parameterizer 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 ¶
NewETHClientHelper creates a new Helper using an ethclient with the provided URL accountKeys is a mapping of name->privateKey hex string
func NewSimulatedBackendHelper ¶
NewSimulatedBackendHelper creates a new Helper using an ethereum SimulatedBackend generates accounts for "genesis", "alice", "bob", "carol", "dan", "erin"
func (*Helper) AddAccount ¶
AddAccount generates a new account and adds it to the account mapping
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