Documentation
¶
Index ¶
- type API
- func (a *API) Address() (result string)
- func (a *API) ChannelFor3rdParty(channelIdentifier, thirdPartyAddress string) (result string)
- func (a *API) CloseChannel(channelIdentifier string, force bool) (result string)
- func (a *API) ContractCallTXQuery(channelIdentifierStr string, openBlockNumber int, ...) (result string)
- func (a *API) Deposit(partnerAddress, tokenAddress string, settleTimeout int, balanceStr string, ...) (result string)
- func (a *API) EthereumStatus() (result string)
- func (a *API) FindPath(targetStr, tokenStr, amountStr string) (result string)
- func (a *API) GetChannelList() (result string)
- func (a *API) GetOneChannel(channelIdentifier string) (result string)
- func (a *API) GetReceivedTransfers(tokenAddressStr string, from, to int64) (result string)
- func (a *API) GetSentTransfers(tokenAddressStr string, from, to int64) (result string)
- func (a *API) GetSystemStatus() (result string)
- func (a *API) GetTransferStatus(tokenAddressStr string, lockSecretHashStr string) (result string)
- func (a *API) NotifyNetworkDown() (result string)
- func (a *API) OnResume() string
- func (a *API) SettleChannel(channelIdentifier string) (result string)
- func (a *API) Stop()
- func (a *API) Subscribe(handler NotifyHandler) (sub *Subscription, err error)
- func (a *API) SwitchNetwork(isMesh bool)
- func (a *API) TokenPartners(tokenAddress string) (result string)
- func (a *API) Tokens() (result string)
- func (a *API) Transfers(tokenAddress, targetAddress string, amountstr string, secretStr string, ...) (result string)
- func (a *API) UpdateMeshNetworkNodes(nodesstr string) (result string)
- func (a *API) Version() string
- func (a *API) Withdraw(channelIdentifierHashStr, amountstr, op string) (result string)
- type NotifyHandler
- type Strings
- type Subscription
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API for export interface
should not export any member because of gomobile's protocol
func StartUp ¶
func StartUp(address, keystorePath, ethRPCEndPoint, dataDir, passwordfile, apiAddr, listenAddr, logFile, registryAddress string, otherArgs *Strings) (api *API, err error)
StartUp is entry point for mobile photon. address is the Node address,such as 0x1a9ec3b0b807464e6d3398a59d6b0a369bf422fa. keystorePath is the address of the private key, geth keystore directory . eg ~/.geth/keystore. ethRpcEndPoint is the URL connected to geth ,such as:ws://10.0.0.2:8546. dataDir is the working directory of a node, such as ~/.photon . passwordfile is the file to storage password eg ~/.geth/pass.txt . apiAddr is 127.0.0.1:5001 for product,0.0.0.1:5001 for test . listenAddr is the listenning address for incomming message from peers. registryAddress is the contract address working on. otherArgs is an array of other arguments.
func (*API) Address ¶
Address returns node's checksum address for example: returns "0x7B874444681F7AEF18D48f330a0Ba093d3d0fDD2"
func (*API) ChannelFor3rdParty ¶
ChannelFor3rdParty generate info for 3rd party use, for update transfer and withdraw.
example returns:
{ "channel_identifier": "0x029a853513e98050e670eb6d5f36217998a2c689ef2f1c65b5954051490d5965", "open_block_number": 2644876, "token_network_address": "0xa3b6481d1c6aa8ba538e8fa9d4d8b1dbadfd379c", "partner_address": "0x64d11d0cbb3f4f9bb3ee09709d4254f0899a6381", "update_transfer": { "nonce": 0, "transfer_amount": null, "locksroot": "0x0000000000000000000000000000000000000000000000000000000000000000", "extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "closing_signature": null, "non_closing_signature": null }, "unlocks": null, "punishes": [ { "lock_hash": "0xd4ec833949fa91e5f30b4e5e8b2e88cca10e8192a68e51bdb24d18220b3f519d", "additional_hash": "0xe800ff8e78b8e367fb165b76f6e0cd1f31d46e7fda640e02134eed4f5e983d53", "signature": "i24Lz6KVvDnlqsxhQzDu+IIx6jJKC4gdVyWg6NpkrfsEejzGV8F0CPB0oUUJjDZ2wmChKG6XjZQx24QkDmhsKhs=" } ] }
func (*API) CloseChannel ¶
CloseChannel close the channel 如果force 为false,则表示希望双方协商关闭通道, 如果force为true,则表示希望直接连上关闭通道,不需要对方同意. example returns:
{ "channel_identifier": "0x97f73562938f6d538a07780b29847330e97d40bb8d0f23845a798912e76970e1", "open_block_number": 2560271, "partner_address": "0xf0f6E53d6bbB9Debf35Da6531eC9f1141cd549d5", "balance": 50, "partner_balance": 0, "locked_amount": 0, "partner_locked_amount": 0, "token_address": "0x7B874444681F7AEF18D48f330a0Ba093d3d0fDD2", "state": 2, "StateString": "closed", "settle_timeout": 150, "reveal_timeout": 0 }
func (*API) ContractCallTXQuery ¶
func (a *API) ContractCallTXQuery(channelIdentifierStr string, openBlockNumber int, tokenAddressStr, txTypeStr, txStatusStr string) (result string)
ContractCallTXQuery 合约调用TX查询接口,4个参数均可传空值,空值即为不限制,4个参数对应的查询条件关系为and channelIdentifierStr 有值时按通道ID查询 openBlockNumber 有值时按通道OpenBlockNumber查询,一般配合channelIdentifierStr参数一起使用,以精确定位到某一个通道 txTypeStr 有值时按tx类型查询,取值:
TXInfoTypeDeposit = "ChannelDeposit" TXInfoTypeClose = "ChannelClose" TXInfoTypeSettle = "ChannelSettle" TXInfoTypeCooperateSettle = "CooperateSettle" TXInfoTypeUpdateBalanceProof = "UpdateBalanceProof" TXInfoTypeUnlock = "Unlock" TXInfoTypePunish = "Punish" TXInfoTypeWithdraw = "Withdraw" TXInfoTypeApproveDeposit = "ApproveDeposit" TXInfoTypeRegisterSecret = "RegisterSecret"
txStatusStr 有值时按tx状态查询,取值:
TXInfoStatusPending = "pending" TXInfoStatusSuccess = "success" TXInfoStatusFailed = "failed"
func (*API) Deposit ¶
func (a *API) Deposit(partnerAddress, tokenAddress string, settleTimeout int, balanceStr string, newChannel bool) (result string)
Deposit try to open a new channel on contract with `partnerAddress` . the `settleTimeout` is the settle time of the new channel. `balanceStr` is the token to deposit to this channel and it must be positive
if `NewChannel` is true, a new channel must be created and if `settleTimeout` is zero then it will be set as default
settle timeout. if `NewChannel` is false, `settleTimeout` must be zero.
//如果NewChannel为true // SettleTimeout表示新建通道的结算窗口,如果SettleTimeout为0,则用系统默认计算窗口 //如果NewChannel为 false // SettleTimeout 必须为0
example returns:
{ "channel_identifier": "0x97f73562938f6d538a07780b29847330e97d40bb8d0f23845a798912e76970e1", "open_block_number": 2560271, "partner_address": "0xf0f6E53d6bbB9Debf35Da6531eC9f1141cd549d5", "balance": 50, "partner_balance": 0, "locked_amount": 0, "partner_locked_amount": 0, "token_address": "0x7B874444681F7AEF18D48f330a0Ba093d3d0fDD2", "state": 1, "StateString": "opened", "settle_timeout": 150, "reveal_timeout": 0 }
func (*API) EthereumStatus ¶
EthereumStatus query the status between Photon and ethereum todo fix it,remove this deprecated api
func (*API) FindPath ¶
FindPath 查询所有从我到target的最低费用路径,该调用总是找pfs问路 example:
{ "path_id": 0, "path_hop": 2, "fee": 10000000000, "result": [ "0x3bc7726c489e617571792ac0cd8b70df8a5d0e22", "0x8a32108d269c11f8db859ca7fac8199ca87a2722", "0xefb2e46724f675381ce0b3f70ea66383061924e9" ] }
func (*API) GetChannelList ¶
GetChannelList returns all the available channels
example returns: [
{ "channel_address": "0xc502076485a3cff65f83c00095dc55e745f790eee4c259ea963969a343fc792a", "open_block_number": 5228715, "partner_address": "0x4B89Bff01009928784eB7e7d10Bf773e6D166066", "balance": 499490, "partner_balance": 1500506, "locked_amount": 0, "partner_locked_amount": 0, "token_address": "0x663495a1b8e9Be17083b37924cFE39e17858F9e8", "state": 1, "StateString": "opened", "settle_timeout": 100000, "reveal_timeout": 5000 }
]
func (*API) GetOneChannel ¶
GetOneChannel return one specified channel with more detail information
exmaple returns:
{ "channel_identifier": "0xc502076485a3cff65f83c00095dc55e745f790eee4c259ea963969a343fc792a", "open_block_number": 5228715, "partner_address": "0x4B89Bff01009928784eB7e7d10Bf773e6D166066", "balance": 499490, "patner_balance": 1500506, "locked_amount": 0, "partner_locked_amount": 0, "token_address": "0x663495a1b8e9Be17083b37924cFE39e17858F9e8", "state": 1, "StateString": "opened", "settle_timeout": 100000, "reveal_timeout": 0, "ClosedBlock": 0, "SettledBlock": 0, "OurUnknownSecretLocks": {}, "OurKnownSecretLocks": {}, "PartnerUnkownSecretLocks": {}, "PartnerKnownSecretLocks": {}, "OurLeaves": null, "PartnerLeaves": null, "OurBalanceProof": { "Nonce": 0, "TransferAmount": 0, "LocksRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", "ChannelIdentifier": { "ChannelIdentifier": "0x0000000000000000000000000000000000000000000000000000000000000000", "OpenBlockNumber": 0 }, "MessageHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "Signature": null, "ContractTransferAmount": 0, "ContractNonce": 0, "ContractLocksRoot": "0x0000000000000000000000000000000000000000000000000000000000000000" }, "PartnerBalanceProof": { "Nonce": 0, "TransferAmount": 0, "LocksRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", "ChannelIdentifier": { "ChannelIdentifier": "0x0000000000000000000000000000000000000000000000000000000000000000", "OpenBlockNumber": 0 }, "MessageHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "Signature": null, "ContractTransferAmount": 0, "ContractNonce": 0, "ContractLocksRoot": "0x0000000000000000000000000000000000000000000000000000000000000000" }, "Signature": null }
func (*API) GetReceivedTransfers ¶
GetReceivedTransfers retuns list of received transfer between `from_block` and `to_block` it contains token swap
func (*API) GetSentTransfers ¶
GetSentTransfers retuns list of sent transfer between `from_block` and `to_block`
func (*API) GetSystemStatus ¶
GetSystemStatus 查询系统状态,
func (*API) GetTransferStatus ¶
GetTransferStatus return transfer result status should be one the following // TransferStatusInit init TransferStatusInit = 0
// TransferStatusCanCancel transfer can cancel right now TransferStatusCanCancel =1
// TransferStatusCanNotCancel transfer can not cancel TransferStatusCanNotCancel =2
// TransferStatusSuccess transfer already success TransferStatusSuccess =3
// TransferStatusCanceled transfer cancel by user request TransferStatusCanceled =4
// TransferStatusFailed transfer already failed TransferStatusFailed =5
example returns:
{ "LockSecretHash": "0x2f6dbd44fa95d7edc840570d3bc847e24846a5422fffa324cdd9c5cab945857e", "Status": 2, "StatusMessage": "MediatedTransfer 正在发送 target=4b89\nMediatedTransfer 发送成功\n收到 SecretRequest, from=3af7\nRevealSecret 正在发送 target=3af7\nRevealSecret 发送成功\n收到 RevealSecret, from=4b89\nUnlock 正在发送 target=4b89\nUnLock 发送成功,交易成功.\n" }
func (*API) NotifyNetworkDown ¶
NotifyNetworkDown :
func (*API) SettleChannel ¶
SettleChannel settle a channel 在通道已经关闭的情况下,过了结算窗口期以后,用户可以在合约上进行结算. example returns:
{ "channel_identifier": "0x97f73562938f6d538a07780b29847330e97d40bb8d0f23845a798912e76970e1", "open_block_number": 2560271, "partner_address": "0xf0f6E53d6bbB9Debf35Da6531eC9f1141cd549d5", "balance": 50, "partner_balance": 0, "locked_amount": 0, "partner_locked_amount": 0, "token_address": "0x7B874444681F7AEF18D48f330a0Ba093d3d0fDD2", "state": 3, "StateString": "settled", "settle_timeout": 150, "reveal_timeout": 0 }
func (*API) Subscribe ¶
func (a *API) Subscribe(handler NotifyHandler) (sub *Subscription, err error)
Subscribe As to Status Notification, we put these codebase into an individual package
and use channel to communication. To avoid write block, we can write data through select. We should make effort to avoid start go routine. If there's need to create a new Photon instance, sub.Unsubscribe must be invoked to do that or memory leakage will occur.
func (*API) SwitchNetwork ¶
SwitchNetwork switch between mesh and internet
func (*API) TokenPartners ¶
TokenPartners Get all the channel partners of this token. 获取我在`token`上与其他所有节点的通道. for example: [
{ "partner_address": "0x151E62a787d0d8d9EfFac182Eae06C559d1B68C2", "channel": "api/1/channles/0x79b789e88c3d2173af4048498f8c1ce66f019f33a6b8b06bedef51dde72bbbc1" }, { "partner_address": "0x201B20123b3C489b47Fde27ce5b451a0fA55FD60", "channel": "api/1/channles/0xd971f803c7ea39ee050bf00ec9919269cf63ee5d0e968d5fe33a1a0f0004f73d" }
]
func (*API) Tokens ¶
Tokens returns all the token have registered on Photon for example: [
"0x7B874444681F7AEF18D48f330a0Ba093d3d0fDD2"
]
func (*API) Transfers ¶
func (a *API) Transfers(tokenAddress, targetAddress string, amountstr string, secretStr string, isDirect bool, data string, routeInfoStr string) (result string)
Transfers POST /api/1/transfers/0x2a65aca4d5fc5b5c859090a6c34d164135398226/0x61c808d82a3ac53231750dadc13c777b59310bd9 Initiating a Transfer tokenAddress is the token to transfer targetAddress is address of the receipt of the transfer amountstr is integer amount string feestr is always 0 now isDirect is this should be True when no internet connection,otherwise false. data: the info example returns for a correct call: transfer:
{ "initiator_address": "0x292650fee408320D888e06ed89D938294Ea42f99", "target_address": "0x4B89Bff01009928784eB7e7d10Bf773e6D166066", "token_address": "0x663495a1b8e9Be17083b37924cFE39e17858F9e8", "amount": 1, "lockSecretHash": "0x5e86d58579cfbc77901a457d7f63e8ec6e47efc5848761f51e63729e7848a01d", "sync": true }
the caller should call GetSentTransferDetail periodically to query this transfer's latest status.
func (*API) UpdateMeshNetworkNodes ¶
UpdateMeshNetworkNodes updates all nodes in MeshNetwork. Nodes within the same local network have higher priority.
type NotifyHandler ¶
type NotifyHandler interface { //some unexpected error OnError(errCode int, failure string) //OnStatusChange server connection status change OnStatusChange(s string) //OnReceivedTransfer receive a transfer OnReceivedTransfer(tr string) /* OnNotify get some important message Photon want to notify upper application level: 0:info,1:warn,2:error info: type InfoStruct struct { Type int Message interface{} } 当info.Type=0 表示Message是一个string,1表示Message是TransferStatus */ OnNotify(level int, info string) }
NotifyHandler is a client-side subscription callback to invoke on events and subscription failure.
type Strings ¶
type Strings struct {
// contains filtered or unexported fields
}
Strings represents s slice of strs.
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription represents an event subscription where events are delivered on a data channel.
func (*Subscription) Unsubscribe ¶
func (s *Subscription) Unsubscribe()
Unsubscribe cancels the sending of events to the data channel and closes the error channel.