mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
les: missing API functions
This commit is contained in:
parent
d338384f9e
commit
6ba9c5ad80
3 changed files with 42 additions and 5 deletions
|
|
@ -868,6 +868,31 @@ web3._extend({
|
||||||
call: 'lespay_connection',
|
call: 'lespay_connection',
|
||||||
params: 6
|
params: 6
|
||||||
}),
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'deposit',
|
||||||
|
call: 'lespay_deposit',
|
||||||
|
params: 4
|
||||||
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'buyTokens',
|
||||||
|
call: 'lespay_buyTokens',
|
||||||
|
params: 6
|
||||||
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'getBalance',
|
||||||
|
call: 'lespay_getBalance',
|
||||||
|
params: 2
|
||||||
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'info',
|
||||||
|
call: 'lespay_info',
|
||||||
|
params: 2
|
||||||
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'remoteInfo',
|
||||||
|
call: 'lespay_remoteInfo',
|
||||||
|
params: 3
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
properties:
|
properties:
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -473,8 +473,8 @@ func (api *PrivateLespayAPI) Deposit(ctx context.Context, remote bool, node stri
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PrivateLespayAPI) BuyTokens(ctx context.Context, remote bool, node string, maxSpend, minReceive uint64, spendAll bool) (results tsBuyTokensResults, err error) {
|
func (api *PrivateLespayAPI) BuyTokens(ctx context.Context, remote bool, node string, maxSpend, minReceive uint64, relative, spendAll bool) (results tsBuyTokensResults, err error) {
|
||||||
params := tsBuyTokensParams{maxSpend, minReceive, spendAll}
|
params := tsBuyTokensParams{maxSpend, minReceive, relative, spendAll}
|
||||||
enc, _ := rlp.EncodeToBytes(¶ms)
|
enc, _ := rlp.EncodeToBytes(¶ms)
|
||||||
var resEnc []byte
|
var resEnc []byte
|
||||||
resEnc, err = api.makeCall(ctx, remote, node, append([]byte{tsBuyTokens}, enc...))
|
resEnc, err = api.makeCall(ctx, remote, node, append([]byte{tsBuyTokens}, enc...))
|
||||||
|
|
|
||||||
|
|
@ -326,7 +326,7 @@ func (t *tokenSale) deposit(id enode.ID, paymentModule string, proofOfPayment []
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tokenSale) buyTokens(id enode.ID, maxSpend, minReceive uint64, spendAll bool) (pcBalance, tokenBalance, spend, receive uint64, success bool) {
|
func (t *tokenSale) buyTokens(id enode.ID, maxSpend, minReceive uint64, relative, spendAll bool) (pcBalance, tokenBalance, spend, receive uint64, success bool) {
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
|
|
||||||
|
|
@ -336,6 +336,18 @@ func (t *tokenSale) buyTokens(id enode.ID, maxSpend, minReceive uint64, spendAll
|
||||||
if err := rlp.DecodeBytes([]byte(pb.meta), &meta); err == nil {
|
if err := rlp.DecodeBytes([]byte(pb.meta), &meta); err == nil {
|
||||||
pcBalance = meta.pcBalance
|
pcBalance = meta.pcBalance
|
||||||
}
|
}
|
||||||
|
if relative {
|
||||||
|
if pcBalance > maxSpend {
|
||||||
|
maxSpend = pcBalance - maxSpend
|
||||||
|
} else {
|
||||||
|
maxSpend = 0
|
||||||
|
}
|
||||||
|
if minReceive > tokenBalance {
|
||||||
|
minReceive -= tokenBalance
|
||||||
|
} else {
|
||||||
|
minReceive = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if maxSpend > pcBalance {
|
if maxSpend > pcBalance {
|
||||||
maxSpend = pcBalance
|
maxSpend = pcBalance
|
||||||
|
|
@ -476,7 +488,7 @@ type (
|
||||||
}
|
}
|
||||||
tsBuyTokensParams struct {
|
tsBuyTokensParams struct {
|
||||||
MaxSpend, MinReceive uint64
|
MaxSpend, MinReceive uint64
|
||||||
SpendAll bool
|
Relative, SpendAll bool
|
||||||
}
|
}
|
||||||
tsBuyTokensResults struct {
|
tsBuyTokensResults struct {
|
||||||
PcBalance, TokenBalance, Spend, Receive uint64
|
PcBalance, TokenBalance, Spend, Receive uint64
|
||||||
|
|
@ -537,7 +549,7 @@ func (t *tokenSale) runCommand(cmd []byte, id enode.ID, freeID string) []byte {
|
||||||
)
|
)
|
||||||
if err := rlp.DecodeBytes(cmd[1:], ¶ms); err == nil {
|
if err := rlp.DecodeBytes(cmd[1:], ¶ms); err == nil {
|
||||||
results.PcBalance, results.TokenBalance, results.Spend, results.Receive, results.Success =
|
results.PcBalance, results.TokenBalance, results.Spend, results.Receive, results.Success =
|
||||||
t.buyTokens(id, params.MaxSpend, params.MinReceive, params.SpendAll)
|
t.buyTokens(id, params.MaxSpend, params.MinReceive, params.Relative, params.SpendAll)
|
||||||
res, _ = rlp.EncodeToBytes(&results)
|
res, _ = rlp.EncodeToBytes(&results)
|
||||||
}
|
}
|
||||||
case tsConnection:
|
case tsConnection:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue