models

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: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger *log.Logger

Logger : global case logger

View Source
var TmpKeyStoreDir = "../../../testdata/casemanager-keystore-tmp"

TmpKeyStoreDir :

Functions

func CreateTmpKeyStore

func CreateTmpKeyStore(accountCount int) ([]string, error)

CreateTmpKeyStore :

func ExecShell

func ExecShell(cmdstr string, param []string, logfile string, canquit bool) bool

ExecShell : run shell commands

func MarshalIndent

func MarshalIndent(v interface{}) string

MarshalIndent :

Types

type Channel

type Channel struct {
	Name                string `json:"name"`
	SelfAddress         string `json:"self_address"`
	ChannelIdentifier   string `json:"channel_identifier"`
	PartnerAddress      string `json:"partner_address"`
	Balance             int32  `json:"balance"`
	LockedAmount        int32  `json:"locked_amount"`
	PartnerBalance      int32  `json:"partner_balance"`
	PartnerLockedAmount int32  `json:"partner_locked_amount"`
	TokenAddress        string `json:"token_address"`
	State               int    `json:"state"`
	SettleTimeout       int32  `json:"settle_timeout"`
	RevealTimeout       int32  `json:"reveal_timeout"`
}

Channel photon chainnode

func (*Channel) CheckEqualByPartnerNode

func (c1 *Channel) CheckEqualByPartnerNode(env *TestEnv) bool

CheckEqualByPartnerNode :

func (*Channel) CheckLockBoth

func (c1 *Channel) CheckLockBoth(lockAmt int32) bool

CheckLockBoth :

func (*Channel) CheckLockPartner

func (c1 *Channel) CheckLockPartner(lockAmt int32) bool

CheckLockPartner :

func (*Channel) CheckLockSelf

func (c1 *Channel) CheckLockSelf(lockAmt int32) bool

CheckLockSelf :

func (*Channel) CheckNoLock

func (c1 *Channel) CheckNoLock() bool

CheckNoLock :

func (*Channel) CheckPartnerBalance

func (c1 *Channel) CheckPartnerBalance(balance int32) bool

CheckPartnerBalance :

func (*Channel) CheckSelfBalance

func (c1 *Channel) CheckSelfBalance(balance int32) bool

CheckSelfBalance :

func (*Channel) CheckState

func (c1 *Channel) CheckState(state int) bool

CheckState :

func (*Channel) PrintDataAfterCrash

func (c *Channel) PrintDataAfterCrash() *Channel

PrintDataAfterCrash :

func (*Channel) PrintDataAfterRestart

func (c *Channel) PrintDataAfterRestart() *Channel

PrintDataAfterRestart :b

func (*Channel) PrintDataAfterTransfer

func (c *Channel) PrintDataAfterTransfer() *Channel

PrintDataAfterTransfer :

func (*Channel) PrintDataBeforeTransfer

func (c *Channel) PrintDataBeforeTransfer() *Channel

PrintDataBeforeTransfer :

func (*Channel) Println

func (c *Channel) Println(header string) *Channel

Println print data to console

type PartnersDataResponse

type PartnersDataResponse struct {
	PartnerAddress string `json:"partner_address"`
	Channel        string `json:"channel"`
}

PartnersDataResponse query by token

type PhotonNode

type PhotonNode struct {
	Host          string
	Address       string
	Name          string
	APIAddress    string
	ListenAddress string
	ConditionQuit *params.ConditionQuit
	DebugCrash    bool
	Running       bool
	NoNetwork     bool
	DoPprof       bool
	Runtime       PhotonNodeRuntime
}

PhotonNode a photon node

func (*PhotonNode) AllowSecret

func (node *PhotonNode) AllowSecret(secretHash, token string)

AllowSecret :

func (*PhotonNode) CancelTransfer

func (node *PhotonNode) CancelTransfer(token, locksecrethash string) (err error)

CancelTransfer cancel a on transfer which secret is not revealed

func (*PhotonNode) ClearHistoryData

func (node *PhotonNode) ClearHistoryData(dataDir string)

ClearHistoryData :

func (*PhotonNode) Close

func (node *PhotonNode) Close(channelIdentifier string, waitSeconds ...int) (err error)

Close :

func (*PhotonNode) CooperateSettle

func (node *PhotonNode) CooperateSettle(channelIdentifier string, waitSeconds ...int) (err error)

CooperateSettle : 由于CooperateSettle,close,settle,withdraw都是异步调用,因此必须再次封装

func (*PhotonNode) Deposit

func (node *PhotonNode) Deposit(partnerAddress, tokenAddress string, balance int64, waitSeconds ...int) error

Deposit :

func (*PhotonNode) FindPath

func (node *PhotonNode) FindPath(target *PhotonNode, tokenAddress common.Address, amount int32) (path []pfsproxy.FindPathResponse)

FindPath :

func (*PhotonNode) ForceUnlock

func (node *PhotonNode) ForceUnlock(channelIdentifier string, secret string) (err error)

ForceUnlock unlock a unlock whenever i send annoucedisposed or not

func (*PhotonNode) GenerateSecret

func (node *PhotonNode) GenerateSecret() (secret, secretHash string, err error)

GenerateSecret :

func (*PhotonNode) GetAddress

func (node *PhotonNode) GetAddress() common.Address

GetAddress :

func (*PhotonNode) GetChannelWith

func (node *PhotonNode) GetChannelWith(partnerNode *PhotonNode, tokenAddr string) *Channel

GetChannelWith :

func (*PhotonNode) GetChannels

func (node *PhotonNode) GetChannels(tokenAddr string) []*Channel

GetChannels :

func (*PhotonNode) GetReceivedTransfers

func (node *PhotonNode) GetReceivedTransfers() (trs []*models.ReceivedTransfer, err error)

GetReceivedTransfers query node's received transfer

func (*PhotonNode) GetSentTransferDetail

func (node *PhotonNode) GetSentTransferDetail(token, locksecrethash string) (status *models.SentTransferDetail, err error)

GetSentTransferDetail :

func (*PhotonNode) GetSentTransferDetails

func (node *PhotonNode) GetSentTransferDetails() (trs []*models.SentTransferDetail, err error)

GetSentTransferDetails query node's sent transfer

func (*PhotonNode) GetUnfinishedReceivedTransfer

func (node *PhotonNode) GetUnfinishedReceivedTransfer(token, locksecrethash string) (resp *photon.TransferDataResponse, err error)

GetUnfinishedReceivedTransfer query unfinished received transfers

func (*PhotonNode) IsRunning

func (node *PhotonNode) IsRunning() bool

IsRunning check by api address

func (*PhotonNode) OpenChannel

func (node *PhotonNode) OpenChannel(partnerAddress, tokenAddress string, balance, settleTimeout int64, waitSeconds ...int) error

OpenChannel :

func (*PhotonNode) PrepareUpdate

func (node *PhotonNode) PrepareUpdate() (err error)

PrepareUpdate query token partners

func (*PhotonNode) ReStartWithoutConditionquit

func (node *PhotonNode) ReStartWithoutConditionquit(env *TestEnv)

ReStartWithoutConditionquit : Restart start a photon node

func (*PhotonNode) RegisterSecret

func (node *PhotonNode) RegisterSecret(secret string) (err error)

RegisterSecret register a secret to contract

func (*PhotonNode) RestartName

func (node *PhotonNode) RestartName() *PhotonNode

RestartName name添加restart的链式调用

func (*PhotonNode) SendTrans

func (node *PhotonNode) SendTrans(tokenAddress string, amount int32, targetAddress string, isDirect bool)

SendTrans send a transfer, should be instead of Transfer

func (*PhotonNode) SendTransWithRouteInfo

func (node *PhotonNode) SendTransWithRouteInfo(target *PhotonNode, tokenAddress string, amount int32, routeInfo []pfsproxy.FindPathResponse)

SendTransWithRouteInfo send a transfer with route info from pfs

func (*PhotonNode) SendTransWithSecret

func (node *PhotonNode) SendTransWithSecret(tokenAddress string, amount int32, targetAddress string, secretSeed string)

SendTransWithSecret send a transfer

func (*PhotonNode) SetConditionQuit

func (node *PhotonNode) SetConditionQuit(c *params.ConditionQuit) *PhotonNode

SetConditionQuit 链式调用

func (*PhotonNode) SetDoPprof

func (node *PhotonNode) SetDoPprof() *PhotonNode

SetDoPprof 调试用

func (*PhotonNode) SetFeePolicy

func (node *PhotonNode) SetFeePolicy(fp *models.FeePolicy) error

SetFeePolicy :

func (*PhotonNode) SetNoNetwork

func (node *PhotonNode) SetNoNetwork() *PhotonNode

SetNoNetwork 不与其他节点通信

func (*PhotonNode) Settle

func (node *PhotonNode) Settle(channelIdentifier string, waitSeconds ...int) (err error)

Settle :

func (*PhotonNode) Shutdown

func (node *PhotonNode) Shutdown(env *TestEnv)

Shutdown check by api address,保证退出的时候已经关闭

func (*PhotonNode) SpecifiedChannel

func (node *PhotonNode) SpecifiedChannel(channelIdentifier string) (c channeltype.ChannelDataDetail, err error)

SpecifiedChannel query channel's detail

func (*PhotonNode) Start

func (node *PhotonNode) Start(env *TestEnv)

Start start a photon node

func (*PhotonNode) StartWithFeeAndPFS

func (node *PhotonNode) StartWithFeeAndPFS(env *TestEnv)

StartWithFeeAndPFS :

func (*PhotonNode) SwitchNetwork

func (node *PhotonNode) SwitchNetwork(tomesh string) (err error)

SwitchNetwork disable mediated transfer

func (*PhotonNode) TokenBalance

func (node *PhotonNode) TokenBalance(token string) (v int, err error)

TokenBalance query this account's balance of this token

func (*PhotonNode) TokenPartners

func (node *PhotonNode) TokenPartners(token string) (partners []*PartnersDataResponse, err error)

TokenPartners query token partners

func (*PhotonNode) TokenSwap

func (node *PhotonNode) TokenSwap(target, locksecrethash, sendingtoken, receivingtoken, role, secret string,
	sendingAmount, receivingAmount int, routeInfo []pfsproxy.FindPathResponse) error

TokenSwap send a transfer

func (*PhotonNode) Tokens

func (node *PhotonNode) Tokens() (tokens []string, err error)

Tokens : query registered tokens

func (*PhotonNode) Transfer

func (node *PhotonNode) Transfer(tokenAddress string, amount int32, targetAddress string, isDirect bool) error

Transfer send a transfer

func (*PhotonNode) UpdateMeshNetworkNodes

func (node *PhotonNode) UpdateMeshNetworkNodes(nodes ...*PhotonNode)

UpdateMeshNetworkNodes :

func (*PhotonNode) Withdraw

func (node *PhotonNode) Withdraw(channelIdentifier string, withdrawAmount int32)

Withdraw :

type PhotonNodeRuntime

type PhotonNodeRuntime struct {
	MainChainBalance *big.Int // 主链货币余额
}

PhotonNodeRuntime case运行过程中存储临时数据的地方

type Req

type Req struct {
	APIName string        `json:"api_name"`
	FullURL string        `json:"url"`
	Method  string        `json:"method"`
	Payload string        `json:"payload"`
	Timeout time.Duration `json:"timeout"`
}

Req a photon api http request

func (*Req) GetReq

func (r *Req) GetReq() *http.Request

GetReq : get *http.Request

func (*Req) Invoke

func (r *Req) Invoke() ([]byte, error)

Invoke : send a http request

func (*Req) InvokeWithoutErrorCode

func (r *Req) InvokeWithoutErrorCode() ([]byte, error)

InvokeWithoutErrorCode : send a http request

func (*Req) ToString

func (r *Req) ToString() string

ToString : get json of this

type TestEnv

type TestEnv struct {
	Conn                *ethclient.Client
	CaseName            string
	Main                string
	DataDir             string
	KeystorePath        string
	PasswordFile        string
	XMPPServer          string
	EthRPCEndpoint      string
	TokenNetwork        *contracts.TokensNetwork
	TokenNetworkAddress string
	UseMatrix           bool
	Verbosity           int
	Debug               bool
	Nodes               []*PhotonNode
	Tokens              []*Token
	Channels            []*Channel
	Keys                []*ecdsa.PrivateKey `json:"-"`
	UseOldToken         bool
	PFSMain             string // pfs可执行文件全路径
	UseNewAccount       bool
	MDNSServiceTag      string
}

TestEnv env manager for test

func NewTestEnv

func NewTestEnv(configFilePath string, useMatrix bool, ethEndPoint string) (env *TestEnv, err error)

NewTestEnv default contractor

func (*TestEnv) ClearHistoryData

func (env *TestEnv) ClearHistoryData()

ClearHistoryData :

func (*TestEnv) GetNodeAddressByName

func (env *TestEnv) GetNodeAddressByName(nodeName string) (index int, address common.Address)

GetNodeAddressByName :

func (*TestEnv) GetNodeByAddress

func (env *TestEnv) GetNodeByAddress(nodeAddress string) *PhotonNode

GetNodeByAddress :

func (*TestEnv) GetPfsProxy

func (env *TestEnv) GetPfsProxy(privateKey *ecdsa.PrivateKey) pfsproxy.PfsProxy

GetPfsProxy :

func (*TestEnv) GetPrivateKeyByNode

func (env *TestEnv) GetPrivateKeyByNode(node *PhotonNode) (key *ecdsa.PrivateKey)

GetPrivateKeyByNode :

func (*TestEnv) GetTokenByName

func (env *TestEnv) GetTokenByName(tokenName string) (index int, token *Token)

GetTokenByName :

func (*TestEnv) KillAllPhotonNodes

func (env *TestEnv) KillAllPhotonNodes()

KillAllPhotonNodes kill all photon node

func (*TestEnv) Println

func (env *TestEnv) Println(header string)

Println print all

func (*TestEnv) StartPFS

func (env *TestEnv) StartPFS()

StartPFS 启动本地pfs节点

type Token

type Token struct {
	Name         string
	Token        *contracts.Token
	TokenAddress common.Address
}

Token name and address

type TransferPayload

type TransferPayload struct {
	Amount    int32                       `json:"amount"`
	IsDirect  bool                        `json:"is_direct"`
	Secret    string                      `json:"secret"`
	Sync      bool                        `json:"sync"`
	RouteInfo []pfsproxy.FindPathResponse `json:"route_info,omitempty"`
	Data      string                      `json:"data"`
}

TransferPayload API http body

Jump to

Keyboard shortcuts

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