rpc

package
v0.0.0-...-9f791b1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PrivateRopstenRegistryAddress = common.HexToAddress(os.Getenv("TOKEN_NETWORK"))

PrivateRopstenRegistryAddress test registry address, todo use env

View Source
var TestPrivKey *ecdsa.PrivateKey

TestPrivKey for test only

View Source
var TestRPCEndpoint = os.Getenv("ETHRPCENDPOINT")

TestRPCEndpoint test eth rpc url, todo use env

Functions

func EventsGetInternal

func EventsGetInternal(ctx context.Context, contractsAddress []common.Address, fromBlock,
	toBlock int64, client *helper.SafeEthClient) ([]types.Log, error)

EventsGetInternal get events of history

func GetCallContext

func GetCallContext() context.Context

GetCallContext context for tx

func GetQueryConext

func GetQueryConext() context.Context

GetQueryConext context for query on chain

func TestGetParticipant1

func TestGetParticipant1() (privKey *ecdsa.PrivateKey, addr common.Address)

TestGetParticipant1 for test only

func TestGetParticipant2

func TestGetParticipant2() (privKey *ecdsa.PrivateKey, addr common.Address)

TestGetParticipant2 for test only

func TestGetTokenNetworkAddress

func TestGetTokenNetworkAddress() common.Address

TestGetTokenNetworkAddress for test only

func TestGetTokenNetworkRegistryAddress

func TestGetTokenNetworkRegistryAddress() common.Address

TestGetTokenNetworkRegistryAddress for test only

Types

type BlockChainService

type BlockChainService struct {
	//PrivKey of this node, todo remove this
	PrivKey *ecdsa.PrivateKey
	//NodeAddress is address of this node
	NodeAddress common.Address

	SecretRegistryProxy *SecretRegistryProxy
	//Client if eth rpc client
	Client *helper.SafeEthClient

	RegistryProxy *RegistryProxy
	//Auth needs by call on blockchain todo remove this
	Auth *bind.TransactOpts

	// things needs by contract call
	NotifyHandler *notify.Handler
	TXInfoDao     models.TXInfoDao
	// contains filtered or unexported fields
}

BlockChainService provides quering on blockchain.

func MakeTestBlockChainService

func MakeTestBlockChainService() *BlockChainService

MakeTestBlockChainService creat test BlockChainService

func NewBlockChainService

func NewBlockChainService(privateKey *ecdsa.PrivateKey, registryAddress common.Address, client *helper.SafeEthClient, notifyHandler *notify.Handler, txInfoDao models.TXInfoDao) (bcs *BlockChainService, err error)

NewBlockChainService create BlockChainService

func (*BlockChainService) GetRegistryAddress

func (bcs *BlockChainService) GetRegistryAddress() common.Address

GetRegistryAddress :

func (*BlockChainService) GetSecretRegistryAddress

func (bcs *BlockChainService) GetSecretRegistryAddress() common.Address

GetSecretRegistryAddress :

func (*BlockChainService) RegisterPendingTXInfo

func (bcs *BlockChainService) RegisterPendingTXInfo(txInfo *models.TXInfo)

RegisterPendingTXInfo 记录Pending状态的tx,并在独立线程中轮询该tx的receipt,并更新结果到db

func (*BlockChainService) Registry

func (bcs *BlockChainService) Registry(address common.Address, hasConnectChain bool) (t *RegistryProxy, err error)

Registry Return a proxy to interact with Registry.

func (*BlockChainService) SyncProgress

func (bcs *BlockChainService) SyncProgress() (sp *ethereum.SyncProgress, err error)

SyncProgress :

func (*BlockChainService) Token

func (bcs *BlockChainService) Token(tokenAddress common.Address) (t *TokenProxy, err error)

Token return a proxy to interact with a token.

func (*BlockChainService) TokenNetwork

func (bcs *BlockChainService) TokenNetwork(tokenAddress common.Address) (t *TokenNetworkProxy, err error)

TokenNetwork return a proxy to interact with a NettingChannelContract.

type FakeTXINfoDao

type FakeTXINfoDao struct{}

FakeTXINfoDao only for test

func (*FakeTXINfoDao) GetTXInfoList

func (dao *FakeTXINfoDao) GetTXInfoList(channelIdentifier common.Hash, openBlockNumber int64, tokenAddress common.Address, txType models.TXInfoType, status models.TXInfoStatus) (list []*models.TXInfo, err error)

GetTXInfoList :

func (*FakeTXINfoDao) NewPendingTXInfo

func (dao *FakeTXINfoDao) NewPendingTXInfo(tx *types.Transaction, txType models.TXInfoType, channelIdentifier common.Hash, openBlockNumber int64, txParams models.TXParams) (txInfo *models.TXInfo, err error)

NewPendingTXInfo :

func (*FakeTXINfoDao) SaveEventToTXInfo

func (dao *FakeTXINfoDao) SaveEventToTXInfo(event interface{}) (txInfo *models.TXInfo, err error)

SaveEventToTXInfo :

func (*FakeTXINfoDao) UpdateTXInfoStatus

func (dao *FakeTXINfoDao) UpdateTXInfoStatus(txHash common.Hash, status models.TXInfoStatus, pendingBlockNumber int64, gasUsed uint64) (txInfo *models.TXInfo, err error)

UpdateTXInfoStatus :

type RegistryProxy

type RegistryProxy struct {
	Address common.Address
	// contains filtered or unexported fields
}

RegistryProxy 只是为了表达方便,兼容以前代码,todo 完全去掉registry信息

func (*RegistryProxy) GetContract

func (r *RegistryProxy) GetContract() *contracts.TokensNetwork

GetContract return Contract interface

func (*RegistryProxy) GetContractVersion

func (r *RegistryProxy) GetContractVersion() (string, error)

GetContractVersion query contract version

func (*RegistryProxy) TokenNetworkByToken

func (r *RegistryProxy) TokenNetworkByToken(token common.Address) (bool, error)

TokenNetworkByToken get token

type SecretRegistryProxy

type SecretRegistryProxy struct {
	Address common.Address

	RegisteredSecret map[common.Hash]*sync.Mutex
	// contains filtered or unexported fields
}

SecretRegistryProxy proxy of secret registry

func (*SecretRegistryProxy) IsSecretRegistered

func (s *SecretRegistryProxy) IsSecretRegistered(secret common.Hash) (bool, error)

IsSecretRegistered 密码是否在合约上注册过,注册地址对不对 IsSecretRegistered : function to check whether this secret has been registered on chain, and whether the address is correct

func (*SecretRegistryProxy) RegisterSecret

func (s *SecretRegistryProxy) RegisterSecret(secret common.Hash) (err error)

RegisterSecret register secret on chain 有可能被重复调用,但是保证不会并发注册同一个密码 RegisterSecret : function to register a secret on-chain. This function can be repeatedly invoked, and ensure that there is no case that the same secret can be registered concurrently.

func (*SecretRegistryProxy) RegisterSecretAsync

func (s *SecretRegistryProxy) RegisterSecretAsync(secret common.Hash) (result *utils.AsyncResult)

RegisterSecretAsync 异步注册一个密码 RegisterSecretAsync : function to register a secret asynchronously.

type TokenNetworkProxy

type TokenNetworkProxy struct {
	*RegistryProxy
	// contains filtered or unexported fields
}

TokenNetworkProxy proxy of TokenNetwork Contract

func (*TokenNetworkProxy) CloseChannel

func (t *TokenNetworkProxy) CloseChannel(partnerAddr common.Address, transferAmount *big.Int, locksRoot common.Hash, nonce uint64, extraHash common.Hash, signature []byte) (err error)

CloseChannel close channel

func (*TokenNetworkProxy) CloseChannelAsync

func (t *TokenNetworkProxy) CloseChannelAsync(partnerAddr common.Address, transferAmount *big.Int, locksRoot common.Hash, nonce uint64, extraHash common.Hash, signature []byte) (err error)

CloseChannelAsync close channel async 认为只要交易进入了缓冲池中,肯定会成功.

func (*TokenNetworkProxy) CooperativeSettle

func (t *TokenNetworkProxy) CooperativeSettle(p1Addr, p2Addr common.Address, p1Balance, p2Balance *big.Int, p1Signature, p2Signatue []byte) (err error)

CooperativeSettle settle a channel

func (*TokenNetworkProxy) CooperativeSettleAsync

func (t *TokenNetworkProxy) CooperativeSettleAsync(p1Addr, p2Addr common.Address, p1Balance, p2Balance *big.Int, p1Signature, p2Signatue []byte) (result *utils.AsyncResult)

CooperativeSettleAsync settle a channel async

func (*TokenNetworkProxy) GetChannelInfo

func (t *TokenNetworkProxy) GetChannelInfo(participant1, participant2 common.Address) (channelID common.Hash, settleBlockNumber, openBlockNumber uint64, state uint8, settleTimeout uint64, err error)

GetChannelInfo Returns the channel specific data. @param participant1 Address of one of the channel participants. @param participant2 Address of the other channel participant. @return ch state and settle_block_number. if state is 1, settleBlockNumber is settle timeout, if state is 2,settleBlockNumber is the min block number ,settle can be called.

func (*TokenNetworkProxy) GetChannelParticipantInfo

func (t *TokenNetworkProxy) GetChannelParticipantInfo(participant, partner common.Address) (deposit *big.Int, balanceHash common.Hash, nonce uint64, err error)

GetChannelParticipantInfo Returns Info of this channel. @return The address of the token.

func (*TokenNetworkProxy) GetContract

func (t *TokenNetworkProxy) GetContract() *contracts.TokensNetwork

GetContract return contract

func (*TokenNetworkProxy) NewChannelAndDepositAsync

func (t *TokenNetworkProxy) NewChannelAndDepositAsync(participantAddress, partnerAddress common.Address, settleTimeout int, amount *big.Int) (err error)

NewChannelAndDepositAsync create channel async 创建通道并存款和存款分两种情况, 一,只有一个Tx就能完成的情况,那么和关闭通道,settle通道处理流程是一样的 二,需要两个Tx,先Approve然后调用deposit,那么就需要详细规划 1. 首先approve初步验证没问题,就把相应的deposit信息存入数据库中 2. 收到approve事件以后,调取数据库中的信息 3. 继续deposit,并从数据库中删除记录, 如果失败,则需要专门通知用户失败了, 还要考虑重复的Deposit,如果数据库中有相应记录,不允许继续创建通道也不允许继续存款,这会覆盖上一次的操作.

func (*TokenNetworkProxy) PunishObsoleteUnlock

func (t *TokenNetworkProxy) PunishObsoleteUnlock(beneficiary, cheater common.Address, lockhash, extraHash common.Hash, cheaterSignature []byte) (err error)

PunishObsoleteUnlock to a channel

func (*TokenNetworkProxy) PunishObsoleteUnlockAsync

func (t *TokenNetworkProxy) PunishObsoleteUnlockAsync(beneficiary, cheater common.Address, lockhash, extraHash common.Hash, cheaterSignature []byte) (result *utils.AsyncResult)

PunishObsoleteUnlockAsync a channel async

func (*TokenNetworkProxy) SettleChannel

func (t *TokenNetworkProxy) SettleChannel(p1Addr, p2Addr common.Address, p1Amount, p2Amount *big.Int, p1Locksroot, p2Locksroot common.Hash) (err error)

SettleChannel settle a channel

func (*TokenNetworkProxy) SettleChannelAsync

func (t *TokenNetworkProxy) SettleChannelAsync(p1Addr, p2Addr common.Address, p1Amount, p2Amount *big.Int, p1Locksroot, p2Locksroot common.Hash) (err error)

SettleChannelAsync settle a channel async 进入缓冲池就认为成功了

func (*TokenNetworkProxy) Unlock

func (t *TokenNetworkProxy) Unlock(partnerAddr common.Address, transferAmount *big.Int, lock *mtree.Lock, proof []byte) (err error)

Unlock a partner's lock

func (*TokenNetworkProxy) UnlockAsync

func (t *TokenNetworkProxy) UnlockAsync(partnerAddr common.Address, transferAmount *big.Int, lock *mtree.Lock, proof []byte) (result *utils.AsyncResult)

UnlockAsync a partner's lock async

func (*TokenNetworkProxy) UpdateBalanceProof

func (t *TokenNetworkProxy) UpdateBalanceProof(partnerAddr common.Address, transferAmount *big.Int, locksRoot common.Hash, nonce uint64, extraHash common.Hash, signature []byte) (err error)

UpdateBalanceProof update balance proof of partner

func (*TokenNetworkProxy) UpdateBalanceProofAsync

func (t *TokenNetworkProxy) UpdateBalanceProofAsync(partnerAddr common.Address, transferAmount *big.Int, locksRoot common.Hash, nonce uint64, extraHash common.Hash, signature []byte) (result *utils.AsyncResult)

UpdateBalanceProofAsync update balance proof async

func (*TokenNetworkProxy) Withdraw

func (t *TokenNetworkProxy) Withdraw(p1Addr, p2Addr common.Address, p1Balance,
	p1Withdraw *big.Int, p1Signature, p2Signature []byte) (err error)

Withdraw to a channel

func (*TokenNetworkProxy) WithdrawAsync

func (t *TokenNetworkProxy) WithdrawAsync(p1Addr, p2Addr common.Address, p1Balance,
	p1Withdraw *big.Int, p1Signature, p2Signature []byte) (result *utils.AsyncResult)

WithdrawAsync a channel async

type TokenProxy

type TokenProxy struct {
	Address common.Address

	Token *contracts.Token
	// contains filtered or unexported fields
}

TokenProxy proxy of ERC20 token todo test if support ApproveAndCall ,ERC223 etc

func (*TokenProxy) Allowance

func (t *TokenProxy) Allowance(owner, spender common.Address) (int64, error)

Allowance Amount of remaining tokens allowed to spent @param _owner The address of the account owning tokens @param _spender The address of the account able to transfer the tokens

func (*TokenProxy) Approve

func (t *TokenProxy) Approve(spender common.Address, value *big.Int) (err error)

Approve Whether the approval was successful or not @notice `msg.sender` approves `_spender` to spend `_value` tokens @param _spender The address of the account able to transfer the tokens @param _value The amount of wei to be approved for transfer 注意此函数并不会等待打包成功才返回,只要交易进入缓冲池就返回

func (*TokenProxy) ApproveAndCall

func (t *TokenProxy) ApproveAndCall(spender common.Address, value *big.Int, extraData []byte, txParams *models.DepositTXParams) (err error)

ApproveAndCall ERC20 extend,进入缓冲池以后就认为不可能会失败,不等待打包

func (*TokenProxy) BalanceOf

func (t *TokenProxy) BalanceOf(addr common.Address) (*big.Int, error)

BalanceOf The balance @param _owner The address from which the balance will be retrieved

func (*TokenProxy) TotalSupply

func (t *TokenProxy) TotalSupply() (*big.Int, error)

TotalSupply total amount of tokens

func (*TokenProxy) Transfer

func (t *TokenProxy) Transfer(spender common.Address, value *big.Int) (err error)

Transfer return Whether the transfer was successful or not @notice send `_value` token to `_to` from `msg.sender` @param _to The address of the recipient @param _value The amount of token to be transferred

func (*TokenProxy) TransferAsync

func (t *TokenProxy) TransferAsync(spender common.Address, value *big.Int) (result *utils.AsyncResult)

TransferAsync transfer async

func (*TokenProxy) TransferWithFallback

func (t *TokenProxy) TransferWithFallback(to common.Address, value *big.Int, extraData []byte, txParams *models.DepositTXParams) (err error)

TransferWithFallback ERC223 TokenFallback,进入缓冲池以后就认为不可能会失败,不等待打包

Jump to

Keyboard shortcuts

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