Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
159e9911
Unverified
Commit
159e9911
authored
Feb 07, 2019
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
contracts/chequebook: polishes and naked return removals
parent
53b823af
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
111 additions
and
110 deletions
+111
-110
cheque.go
contracts/chequebook/cheque.go
+111
-110
No files found.
contracts/chequebook/cheque.go
View file @
159e9911
...
...
@@ -109,12 +109,12 @@ type Chequebook struct {
log
log
.
Logger
// contextual logger with the contract address embedded
}
func
(
c
hbook
*
Chequebook
)
String
()
string
{
return
fmt
.
Sprintf
(
"contract: %s, owner: %s, balance: %v, signer: %x"
,
c
hbook
.
contractAddr
.
Hex
(),
chbook
.
owner
.
Hex
(),
chbook
.
balance
,
chbook
.
prvKey
.
PublicKey
)
func
(
c
b
*
Chequebook
)
String
()
string
{
return
fmt
.
Sprintf
(
"contract: %s, owner: %s, balance: %v, signer: %x"
,
c
b
.
contractAddr
.
Hex
(),
cb
.
owner
.
Hex
(),
cb
.
balance
,
cb
.
prvKey
.
PublicKey
)
}
// NewChequebook creates a new Chequebook.
func
NewChequebook
(
path
string
,
contractAddr
common
.
Address
,
prvKey
*
ecdsa
.
PrivateKey
,
backend
Backend
)
(
self
*
Chequebook
,
err
error
)
{
func
NewChequebook
(
path
string
,
contractAddr
common
.
Address
,
prvKey
*
ecdsa
.
PrivateKey
,
backend
Backend
)
(
*
Chequebook
,
error
)
{
balance
:=
new
(
big
.
Int
)
sent
:=
make
(
map
[
common
.
Address
]
*
big
.
Int
)
...
...
@@ -128,7 +128,7 @@ func NewChequebook(path string, contractAddr common.Address, prvKey *ecdsa.Priva
TransactOpts
:
*
transactOpts
,
}
self
=
&
Chequebook
{
cb
:
=
&
Chequebook
{
prvKey
:
prvKey
,
balance
:
balance
,
contractAddr
:
contractAddr
,
...
...
@@ -140,42 +140,39 @@ func NewChequebook(path string, contractAddr common.Address, prvKey *ecdsa.Priva
session
:
session
,
log
:
log
.
New
(
"contract"
,
contractAddr
),
}
if
(
contractAddr
!=
common
.
Address
{})
{
self
.
setBalanceFromBlockChain
()
self
.
log
.
Trace
(
"New chequebook initialised"
,
"owner"
,
self
.
owner
,
"balance"
,
self
.
balance
)
cb
.
setBalanceFromBlockChain
()
cb
.
log
.
Trace
(
"New chequebook initialised"
,
"owner"
,
cb
.
owner
,
"balance"
,
cb
.
balance
)
}
return
return
cb
,
nil
}
func
(
c
hbook
*
Chequebook
)
setBalanceFromBlockChain
()
{
balance
,
err
:=
c
hbook
.
backend
.
BalanceAt
(
context
.
TODO
(),
chbook
.
contractAddr
,
nil
)
func
(
c
b
*
Chequebook
)
setBalanceFromBlockChain
()
{
balance
,
err
:=
c
b
.
backend
.
BalanceAt
(
context
.
TODO
(),
cb
.
contractAddr
,
nil
)
if
err
!=
nil
{
log
.
Error
(
"Failed to retrieve chequebook balance"
,
"err"
,
err
)
}
else
{
c
hbook
.
balance
.
Set
(
balance
)
c
b
.
balance
.
Set
(
balance
)
}
}
// LoadChequebook loads a chequebook from disk (file path).
func
LoadChequebook
(
path
string
,
prvKey
*
ecdsa
.
PrivateKey
,
backend
Backend
,
checkBalance
bool
)
(
self
*
Chequebook
,
err
error
)
{
var
data
[]
byte
data
,
err
=
ioutil
.
ReadFile
(
path
)
func
LoadChequebook
(
path
string
,
prvKey
*
ecdsa
.
PrivateKey
,
backend
Backend
,
checkBalance
bool
)
(
*
Chequebook
,
error
)
{
data
,
err
:=
ioutil
.
ReadFile
(
path
)
if
err
!=
nil
{
return
return
nil
,
err
}
self
,
_
=
NewChequebook
(
path
,
common
.
Address
{},
prvKey
,
backend
)
cb
,
_
:
=
NewChequebook
(
path
,
common
.
Address
{},
prvKey
,
backend
)
err
=
json
.
Unmarshal
(
data
,
self
)
if
err
!=
nil
{
if
err
=
json
.
Unmarshal
(
data
,
cb
);
err
!=
nil
{
return
nil
,
err
}
if
checkBalance
{
self
.
setBalanceFromBlockChain
()
cb
.
setBalanceFromBlockChain
()
}
log
.
Trace
(
"Loaded chequebook from disk"
,
"path"
,
path
)
return
return
cb
,
nil
}
// chequebookFile is the JSON representation of a chequebook.
...
...
@@ -187,19 +184,19 @@ type chequebookFile struct {
}
// UnmarshalJSON deserialises a chequebook.
func
(
c
hbook
*
Chequebook
)
UnmarshalJSON
(
data
[]
byte
)
error
{
func
(
c
b
*
Chequebook
)
UnmarshalJSON
(
data
[]
byte
)
error
{
var
file
chequebookFile
err
:=
json
.
Unmarshal
(
data
,
&
file
)
if
err
!=
nil
{
return
err
}
_
,
ok
:=
c
hbook
.
balance
.
SetString
(
file
.
Balance
,
10
)
_
,
ok
:=
c
b
.
balance
.
SetString
(
file
.
Balance
,
10
)
if
!
ok
{
return
fmt
.
Errorf
(
"cumulative amount sent: unable to convert string to big integer: %v"
,
file
.
Balance
)
}
c
hbook
.
contractAddr
=
common
.
HexToAddress
(
file
.
Contract
)
c
b
.
contractAddr
=
common
.
HexToAddress
(
file
.
Contract
)
for
addr
,
sent
:=
range
file
.
Sent
{
c
hbook
.
sent
[
common
.
HexToAddress
(
addr
)],
ok
=
new
(
big
.
Int
)
.
SetString
(
sent
,
10
)
c
b
.
sent
[
common
.
HexToAddress
(
addr
)],
ok
=
new
(
big
.
Int
)
.
SetString
(
sent
,
10
)
if
!
ok
{
return
fmt
.
Errorf
(
"beneficiary %v cumulative amount sent: unable to convert string to big integer: %v"
,
addr
,
sent
)
}
...
...
@@ -208,14 +205,14 @@ func (chbook *Chequebook) UnmarshalJSON(data []byte) error {
}
// MarshalJSON serialises a chequebook.
func
(
c
hbook
*
Chequebook
)
MarshalJSON
()
([]
byte
,
error
)
{
func
(
c
b
*
Chequebook
)
MarshalJSON
()
([]
byte
,
error
)
{
var
file
=
&
chequebookFile
{
Balance
:
c
hbook
.
balance
.
String
(),
Contract
:
c
hbook
.
contractAddr
.
Hex
(),
Owner
:
c
hbook
.
owner
.
Hex
(),
Balance
:
c
b
.
balance
.
String
(),
Contract
:
c
b
.
contractAddr
.
Hex
(),
Owner
:
c
b
.
owner
.
Hex
(),
Sent
:
make
(
map
[
string
]
string
),
}
for
addr
,
sent
:=
range
c
hbook
.
sent
{
for
addr
,
sent
:=
range
c
b
.
sent
{
file
.
Sent
[
addr
.
Hex
()]
=
sent
.
String
()
}
return
json
.
Marshal
(
file
)
...
...
@@ -223,76 +220,78 @@ func (chbook *Chequebook) MarshalJSON() ([]byte, error) {
// Save persists the chequebook on disk, remembering balance, contract address and
// cumulative amount of funds sent for each beneficiary.
func
(
c
hbook
*
Chequebook
)
Save
()
(
err
error
)
{
data
,
err
:=
json
.
MarshalIndent
(
c
hbook
,
""
,
" "
)
func
(
c
b
*
Chequebook
)
Save
()
error
{
data
,
err
:=
json
.
MarshalIndent
(
c
b
,
""
,
" "
)
if
err
!=
nil
{
return
err
}
c
hbook
.
log
.
Trace
(
"Saving chequebook to disk"
,
chbook
.
path
)
c
b
.
log
.
Trace
(
"Saving chequebook to disk"
,
cb
.
path
)
return
ioutil
.
WriteFile
(
c
hbook
.
path
,
data
,
os
.
ModePerm
)
return
ioutil
.
WriteFile
(
c
b
.
path
,
data
,
os
.
ModePerm
)
}
// Stop quits the autodeposit go routine to terminate
func
(
c
hbook
*
Chequebook
)
Stop
()
{
defer
c
hbook
.
lock
.
Unlock
()
c
hbook
.
lock
.
Lock
()
if
c
hbook
.
quit
!=
nil
{
close
(
c
hbook
.
quit
)
c
hbook
.
quit
=
nil
func
(
c
b
*
Chequebook
)
Stop
()
{
defer
c
b
.
lock
.
Unlock
()
c
b
.
lock
.
Lock
()
if
c
b
.
quit
!=
nil
{
close
(
c
b
.
quit
)
c
b
.
quit
=
nil
}
}
// Issue creates a cheque signed by the chequebook owner's private key. The
// signer commits to a contract (one that they own), a beneficiary and amount.
func
(
c
hbook
*
Chequebook
)
Issue
(
beneficiary
common
.
Address
,
amount
*
big
.
Int
)
(
ch
*
Cheque
,
err
error
)
{
defer
c
hbook
.
lock
.
Unlock
()
c
hbook
.
lock
.
Lock
()
func
(
c
b
*
Chequebook
)
Issue
(
beneficiary
common
.
Address
,
amount
*
big
.
Int
)
(
*
Cheque
,
error
)
{
defer
c
b
.
lock
.
Unlock
()
c
b
.
lock
.
Lock
()
if
amount
.
Sign
()
<=
0
{
return
nil
,
fmt
.
Errorf
(
"amount must be greater than zero (%v)"
,
amount
)
}
if
chbook
.
balance
.
Cmp
(
amount
)
<
0
{
err
=
fmt
.
Errorf
(
"insufficient funds to issue cheque for amount: %v. balance: %v"
,
amount
,
chbook
.
balance
)
var
(
ch
*
Cheque
err
error
)
if
cb
.
balance
.
Cmp
(
amount
)
<
0
{
err
=
fmt
.
Errorf
(
"insufficient funds to issue cheque for amount: %v. balance: %v"
,
amount
,
cb
.
balance
)
}
else
{
var
sig
[]
byte
sent
,
found
:=
c
hbook
.
sent
[
beneficiary
]
sent
,
found
:=
c
b
.
sent
[
beneficiary
]
if
!
found
{
sent
=
new
(
big
.
Int
)
c
hbook
.
sent
[
beneficiary
]
=
sent
c
b
.
sent
[
beneficiary
]
=
sent
}
sum
:=
new
(
big
.
Int
)
.
Set
(
sent
)
sum
.
Add
(
sum
,
amount
)
sig
,
err
=
crypto
.
Sign
(
sigHash
(
c
hbook
.
contractAddr
,
beneficiary
,
sum
),
chbook
.
prvKey
)
sig
,
err
=
crypto
.
Sign
(
sigHash
(
c
b
.
contractAddr
,
beneficiary
,
sum
),
cb
.
prvKey
)
if
err
==
nil
{
ch
=
&
Cheque
{
Contract
:
c
hbook
.
contractAddr
,
Contract
:
c
b
.
contractAddr
,
Beneficiary
:
beneficiary
,
Amount
:
sum
,
Sig
:
sig
,
}
sent
.
Set
(
sum
)
c
hbook
.
balance
.
Sub
(
chbook
.
balance
,
amount
)
// subtract amount from balance
c
b
.
balance
.
Sub
(
cb
.
balance
,
amount
)
// subtract amount from balance
}
}
// auto deposit if threshold is set and balance is less then threshold
// note this is called even if issuing cheque fails
// so we reattempt depositing
if
c
hbook
.
threshold
!=
nil
{
if
c
hbook
.
balance
.
Cmp
(
chbook
.
threshold
)
<
0
{
send
:=
new
(
big
.
Int
)
.
Sub
(
c
hbook
.
buffer
,
chbook
.
balance
)
c
hbook
.
deposit
(
send
)
if
c
b
.
threshold
!=
nil
{
if
c
b
.
balance
.
Cmp
(
cb
.
threshold
)
<
0
{
send
:=
new
(
big
.
Int
)
.
Sub
(
c
b
.
buffer
,
cb
.
balance
)
c
b
.
deposit
(
send
)
}
}
return
return
ch
,
err
}
// Cash is a convenience method to cash any cheque.
func
(
c
hbook
*
Chequebook
)
Cash
(
ch
*
Cheque
)
(
txhash
string
,
err
error
)
{
return
ch
.
Cash
(
c
hbook
.
session
)
func
(
c
b
*
Chequebook
)
Cash
(
ch
*
Cheque
)
(
string
,
error
)
{
return
ch
.
Cash
(
c
b
.
session
)
}
// data to sign: contract address, beneficiary, cumulative amount of funds ever sent
...
...
@@ -309,73 +308,73 @@ func sigHash(contract, beneficiary common.Address, sum *big.Int) []byte {
}
// Balance returns the current balance of the chequebook.
func
(
c
hbook
*
Chequebook
)
Balance
()
*
big
.
Int
{
defer
c
hbook
.
lock
.
Unlock
()
c
hbook
.
lock
.
Lock
()
return
new
(
big
.
Int
)
.
Set
(
c
hbook
.
balance
)
func
(
c
b
*
Chequebook
)
Balance
()
*
big
.
Int
{
defer
c
b
.
lock
.
Unlock
()
c
b
.
lock
.
Lock
()
return
new
(
big
.
Int
)
.
Set
(
c
b
.
balance
)
}
// Owner returns the owner account of the chequebook.
func
(
c
hbook
*
Chequebook
)
Owner
()
common
.
Address
{
return
c
hbook
.
owner
func
(
c
b
*
Chequebook
)
Owner
()
common
.
Address
{
return
c
b
.
owner
}
// Address returns the on-chain contract address of the chequebook.
func
(
c
hbook
*
Chequebook
)
Address
()
common
.
Address
{
return
c
hbook
.
contractAddr
func
(
c
b
*
Chequebook
)
Address
()
common
.
Address
{
return
c
b
.
contractAddr
}
// Deposit deposits money to the chequebook account.
func
(
c
hbook
*
Chequebook
)
Deposit
(
amount
*
big
.
Int
)
(
string
,
error
)
{
defer
c
hbook
.
lock
.
Unlock
()
c
hbook
.
lock
.
Lock
()
return
c
hbook
.
deposit
(
amount
)
func
(
c
b
*
Chequebook
)
Deposit
(
amount
*
big
.
Int
)
(
string
,
error
)
{
defer
c
b
.
lock
.
Unlock
()
c
b
.
lock
.
Lock
()
return
c
b
.
deposit
(
amount
)
}
// deposit deposits amount to the chequebook account.
// The caller must hold
self.
lock.
func
(
c
hbook
*
Chequebook
)
deposit
(
amount
*
big
.
Int
)
(
string
,
error
)
{
// The caller must hold lock.
func
(
c
b
*
Chequebook
)
deposit
(
amount
*
big
.
Int
)
(
string
,
error
)
{
// since the amount is variable here, we do not use sessions
depositTransactor
:=
bind
.
NewKeyedTransactor
(
c
hbook
.
prvKey
)
depositTransactor
:=
bind
.
NewKeyedTransactor
(
c
b
.
prvKey
)
depositTransactor
.
Value
=
amount
chbookRaw
:=
&
contract
.
ChequebookRaw
{
Contract
:
c
hbook
.
contract
}
chbookRaw
:=
&
contract
.
ChequebookRaw
{
Contract
:
c
b
.
contract
}
tx
,
err
:=
chbookRaw
.
Transfer
(
depositTransactor
)
if
err
!=
nil
{
c
hbook
.
log
.
Warn
(
"Failed to fund chequebook"
,
"amount"
,
amount
,
"balance"
,
chbook
.
balance
,
"target"
,
chbook
.
buffer
,
"err"
,
err
)
c
b
.
log
.
Warn
(
"Failed to fund chequebook"
,
"amount"
,
amount
,
"balance"
,
cb
.
balance
,
"target"
,
cb
.
buffer
,
"err"
,
err
)
return
""
,
err
}
// assume that transaction is actually successful, we add the amount to balance right away
c
hbook
.
balance
.
Add
(
chbook
.
balance
,
amount
)
c
hbook
.
log
.
Trace
(
"Deposited funds to chequebook"
,
"amount"
,
amount
,
"balance"
,
chbook
.
balance
,
"target"
,
chbook
.
buffer
)
c
b
.
balance
.
Add
(
cb
.
balance
,
amount
)
c
b
.
log
.
Trace
(
"Deposited funds to chequebook"
,
"amount"
,
amount
,
"balance"
,
cb
.
balance
,
"target"
,
cb
.
buffer
)
return
tx
.
Hash
()
.
Hex
(),
nil
}
// AutoDeposit (re)sets interval time and amount which triggers sending funds to the
// chequebook. Contract backend needs to be set if threshold is not less than buffer, then
// deposit will be triggered on every new cheque issued.
func
(
c
hbook
*
Chequebook
)
AutoDeposit
(
interval
time
.
Duration
,
threshold
,
buffer
*
big
.
Int
)
{
defer
c
hbook
.
lock
.
Unlock
()
c
hbook
.
lock
.
Lock
()
c
hbook
.
threshold
=
threshold
c
hbook
.
buffer
=
buffer
c
hbook
.
autoDeposit
(
interval
)
func
(
c
b
*
Chequebook
)
AutoDeposit
(
interval
time
.
Duration
,
threshold
,
buffer
*
big
.
Int
)
{
defer
c
b
.
lock
.
Unlock
()
c
b
.
lock
.
Lock
()
c
b
.
threshold
=
threshold
c
b
.
buffer
=
buffer
c
b
.
autoDeposit
(
interval
)
}
// autoDeposit starts a goroutine that periodically sends funds to the chequebook
// contract caller holds the lock the go routine terminates if Chequebook.quit is closed.
func
(
c
hbook
*
Chequebook
)
autoDeposit
(
interval
time
.
Duration
)
{
if
c
hbook
.
quit
!=
nil
{
close
(
c
hbook
.
quit
)
c
hbook
.
quit
=
nil
func
(
c
b
*
Chequebook
)
autoDeposit
(
interval
time
.
Duration
)
{
if
c
b
.
quit
!=
nil
{
close
(
c
b
.
quit
)
c
b
.
quit
=
nil
}
// if threshold >= balance autodeposit after every cheque issued
if
interval
==
time
.
Duration
(
0
)
||
c
hbook
.
threshold
!=
nil
&&
chbook
.
buffer
!=
nil
&&
chbook
.
threshold
.
Cmp
(
chbook
.
buffer
)
>=
0
{
if
interval
==
time
.
Duration
(
0
)
||
c
b
.
threshold
!=
nil
&&
cb
.
buffer
!=
nil
&&
cb
.
threshold
.
Cmp
(
cb
.
buffer
)
>=
0
{
return
}
ticker
:=
time
.
NewTicker
(
interval
)
c
hbook
.
quit
=
make
(
chan
bool
)
quit
:=
c
hbook
.
quit
c
b
.
quit
=
make
(
chan
bool
)
quit
:=
c
b
.
quit
go
func
()
{
for
{
...
...
@@ -383,15 +382,15 @@ func (chbook *Chequebook) autoDeposit(interval time.Duration) {
case
<-
quit
:
return
case
<-
ticker
.
C
:
c
hbook
.
lock
.
Lock
()
if
c
hbook
.
balance
.
Cmp
(
chbook
.
buffer
)
<
0
{
amount
:=
new
(
big
.
Int
)
.
Sub
(
c
hbook
.
buffer
,
chbook
.
balance
)
txhash
,
err
:=
c
hbook
.
deposit
(
amount
)
c
b
.
lock
.
Lock
()
if
c
b
.
balance
.
Cmp
(
cb
.
buffer
)
<
0
{
amount
:=
new
(
big
.
Int
)
.
Sub
(
c
b
.
buffer
,
cb
.
balance
)
txhash
,
err
:=
c
b
.
deposit
(
amount
)
if
err
==
nil
{
c
hbook
.
txhash
=
txhash
c
b
.
txhash
=
txhash
}
}
c
hbook
.
lock
.
Unlock
()
c
b
.
lock
.
Unlock
()
}
}
}()
...
...
@@ -404,8 +403,8 @@ type Outbox struct {
}
// NewOutbox creates an outbox.
func
NewOutbox
(
c
hbook
*
Chequebook
,
beneficiary
common
.
Address
)
*
Outbox
{
return
&
Outbox
{
c
hbook
,
beneficiary
}
func
NewOutbox
(
c
b
*
Chequebook
,
beneficiary
common
.
Address
)
*
Outbox
{
return
&
Outbox
{
c
b
,
beneficiary
}
}
// Issue creates cheque.
...
...
@@ -445,7 +444,7 @@ type Inbox struct {
// NewInbox creates an Inbox. An Inboxes is not persisted, the cumulative sum is updated
// from blockchain when first cheque is received.
func
NewInbox
(
prvKey
*
ecdsa
.
PrivateKey
,
contractAddr
,
beneficiary
common
.
Address
,
signer
*
ecdsa
.
PublicKey
,
abigen
bind
.
ContractBackend
)
(
self
*
Inbox
,
err
error
)
{
func
NewInbox
(
prvKey
*
ecdsa
.
PrivateKey
,
contractAddr
,
beneficiary
common
.
Address
,
signer
*
ecdsa
.
PublicKey
,
abigen
bind
.
ContractBackend
)
(
*
Inbox
,
error
)
{
if
signer
==
nil
{
return
nil
,
fmt
.
Errorf
(
"signer is null"
)
}
...
...
@@ -461,7 +460,7 @@ func NewInbox(prvKey *ecdsa.PrivateKey, contractAddr, beneficiary common.Address
}
sender
:=
transactOpts
.
From
self
=
&
Inbox
{
inbox
:
=
&
Inbox
{
contract
:
contractAddr
,
beneficiary
:
beneficiary
,
sender
:
sender
,
...
...
@@ -470,8 +469,8 @@ func NewInbox(prvKey *ecdsa.PrivateKey, contractAddr, beneficiary common.Address
cashed
:
new
(
big
.
Int
)
.
Set
(
common
.
Big0
),
log
:
log
.
New
(
"contract"
,
contractAddr
),
}
self
.
log
.
Trace
(
"New chequebook inbox initialized"
,
"beneficiary"
,
self
.
beneficiary
,
"signer"
,
hexutil
.
Bytes
(
crypto
.
FromECDSAPub
(
signer
)))
return
inbox
.
log
.
Trace
(
"New chequebook inbox initialized"
,
"beneficiary"
,
inbox
.
beneficiary
,
"signer"
,
hexutil
.
Bytes
(
crypto
.
FromECDSAPub
(
signer
)))
return
inbox
,
nil
}
func
(
i
*
Inbox
)
String
()
string
{
...
...
@@ -489,13 +488,15 @@ func (i *Inbox) Stop() {
}
// Cash attempts to cash the current cheque.
func
(
i
*
Inbox
)
Cash
()
(
txhash
string
,
err
error
)
{
if
i
.
cheque
!=
nil
{
txhash
,
err
=
i
.
cheque
.
Cash
(
i
.
session
)
i
.
log
.
Trace
(
"Cashing in chequebook cheque"
,
"amount"
,
i
.
cheque
.
Amount
,
"beneficiary"
,
i
.
beneficiary
)
i
.
cashed
=
i
.
cheque
.
Amount
func
(
i
*
Inbox
)
Cash
()
(
string
,
error
)
{
if
i
.
cheque
==
nil
{
return
""
,
nil
}
return
txhash
,
err
:=
i
.
cheque
.
Cash
(
i
.
session
)
i
.
log
.
Trace
(
"Cashing in chequebook cheque"
,
"amount"
,
i
.
cheque
.
Amount
,
"beneficiary"
,
i
.
beneficiary
)
i
.
cashed
=
i
.
cheque
.
Amount
return
txhash
,
err
}
// AutoCash (re)sets maximum time and amount which triggers cashing of the last uncashed
...
...
@@ -509,7 +510,7 @@ func (i *Inbox) AutoCash(cashInterval time.Duration, maxUncashed *big.Int) {
// autoCash starts a loop that periodically clears the last cheque
// if the peer is trusted. Clearing period could be 24h or a week.
// The caller must hold
self.
lock.
// The caller must hold lock.
func
(
i
*
Inbox
)
autoCash
(
cashInterval
time
.
Duration
)
{
if
i
.
quit
!=
nil
{
close
(
i
.
quit
)
...
...
@@ -632,7 +633,7 @@ func (ch *Cheque) Cash(session *contract.ChequebookSession) (string, error) {
// ValidateCode checks that the on-chain code at address matches the expected chequebook
// contract code. This is used to detect suicided chequebooks.
func
ValidateCode
(
ctx
context
.
Context
,
b
Backend
,
address
common
.
Address
)
(
ok
bool
,
err
error
)
{
func
ValidateCode
(
ctx
context
.
Context
,
b
Backend
,
address
common
.
Address
)
(
bool
,
error
)
{
code
,
err
:=
b
.
CodeAt
(
ctx
,
address
,
nil
)
if
err
!=
nil
{
return
false
,
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment