mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
les: added tokensale info call
This commit is contained in:
parent
94bf8de547
commit
8c9f0eb7bf
1 changed files with 30 additions and 8 deletions
|
|
@ -30,7 +30,7 @@ import (
|
||||||
const basePriceTC = time.Hour * 10
|
const basePriceTC = time.Hour * 10
|
||||||
|
|
||||||
type paymentReceiver interface {
|
type paymentReceiver interface {
|
||||||
info() []byte
|
info() keyValueList
|
||||||
receivePayment(from enode.ID, proofOfPayment, oldMeta []byte) (value uint64, newMeta []byte, err error)
|
receivePayment(from enode.ID, proofOfPayment, oldMeta []byte) (value uint64, newMeta []byte, err error)
|
||||||
requestPayment(from enode.ID, value uint64, meta []byte) uint64
|
requestPayment(from enode.ID, value uint64, meta []byte) uint64
|
||||||
}
|
}
|
||||||
|
|
@ -40,6 +40,7 @@ type tokenSale struct {
|
||||||
clientPool *clientPool
|
clientPool *clientPool
|
||||||
stopCh chan struct{}
|
stopCh chan struct{}
|
||||||
receivers map[string]paymentReceiver
|
receivers map[string]paymentReceiver
|
||||||
|
receiverNames []string
|
||||||
basePrice, minBasePrice float64
|
basePrice, minBasePrice float64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -249,12 +250,19 @@ func (t *tokenSale) buyTokens(id enode.ID, maxSpend, minReceive uint64, spendAll
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tokenSale) paymentInfo(paymentModule []string) [][]byte {
|
func (t *tokenSale) info() (version, compatible uint, info keyValueList, receivers []string) {
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
|
|
||||||
res := make([][]byte, len(paymentModule))
|
return 1, 1, keyValueList{}, t.receiverNames
|
||||||
for i, id := range paymentModule {
|
}
|
||||||
|
|
||||||
|
func (t *tokenSale) receiverInfo(receiverIDs []string) []keyValueList {
|
||||||
|
t.lock.Lock()
|
||||||
|
defer t.lock.Unlock()
|
||||||
|
|
||||||
|
res := make([]keyValueList, len(receiverIDs))
|
||||||
|
for i, id := range receiverIDs {
|
||||||
if rec, ok := t.receivers[id]; ok {
|
if rec, ok := t.receivers[id]; ok {
|
||||||
res[i] = rec.info()
|
res[i] = rec.info()
|
||||||
}
|
}
|
||||||
|
|
@ -314,12 +322,20 @@ func (t *tokenSaleMeta) DecodeRLP(s *rlp.Stream) error {
|
||||||
|
|
||||||
const (
|
const (
|
||||||
tsInfo = iota
|
tsInfo = iota
|
||||||
|
tsReceiverInfo
|
||||||
tsDeposit
|
tsDeposit
|
||||||
tsBuyTokens
|
tsBuyTokens
|
||||||
tsConnection
|
tsConnection
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
tsInfoResults struct {
|
||||||
|
Version, Compatible uint
|
||||||
|
Info keyValueList
|
||||||
|
Receivers []string
|
||||||
|
}
|
||||||
|
tsReceiverInfoParams []string
|
||||||
|
tsReceiverInfoResults []keyValueList
|
||||||
tsDepositParams struct {
|
tsDepositParams struct {
|
||||||
PaymentModule string
|
PaymentModule string
|
||||||
ProofOfPayment []byte
|
ProofOfPayment []byte
|
||||||
|
|
@ -352,12 +368,18 @@ func (t *tokenSale) runCommand(cmd []byte, id enode.ID, freeID string) []byte {
|
||||||
var res []byte
|
var res []byte
|
||||||
switch cmd[0] {
|
switch cmd[0] {
|
||||||
case tsInfo:
|
case tsInfo:
|
||||||
|
var results tsInfoResults
|
||||||
|
if len(cmd) == 1 {
|
||||||
|
results.Version, results.Compatible, results.Info, results.Receivers = t.info()
|
||||||
|
res, _ = rlp.EncodeToBytes(&results)
|
||||||
|
}
|
||||||
|
case tsReceiverInfo:
|
||||||
var (
|
var (
|
||||||
params []string
|
params tsReceiverInfoParams
|
||||||
results [][]byte
|
results tsReceiverInfoResults
|
||||||
)
|
)
|
||||||
if err := rlp.DecodeBytes(cmd[1:], ¶ms); err == nil {
|
if err := rlp.DecodeBytes(cmd[1:], ¶ms); err == nil {
|
||||||
results = t.paymentInfo(params)
|
results = t.receiverInfo(params)
|
||||||
res, _ = rlp.EncodeToBytes(&results)
|
res, _ = rlp.EncodeToBytes(&results)
|
||||||
}
|
}
|
||||||
case tsDeposit:
|
case tsDeposit:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue