-
Notifications
You must be signed in to change notification settings - Fork 6
/
seth.go
768 lines (665 loc) · 19.3 KB
/
seth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
package seth
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"log"
"math/big"
"reflect"
"time"
"unsafe"
"github.com/newalchemylimited/seth/keccak"
"github.com/tinylib/msgp/msgp"
)
// HashString produces a Hash that corresponds
// to the Keccak-256 hash of the given string
func HashString(s string) Hash {
b := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
Data: (*reflect.StringHeader)(unsafe.Pointer(&s)).Data,
Len: len(s),
Cap: len(s),
}))
return HashBytes(b)
}
// HashBytes produces the Keccak-256 hash of the given bytes
func HashBytes(b []byte) Hash {
return Hash(keccak.Sum256(b))
}
var (
// ERC20Transfer is hash of the canonical ERC20 Transfer event
ERC20Transfer = HashString("Transfer(address,address,uint256)")
// ERC20Approve is the hash of the canonical ERC20 Approve event
ERC20Approve = HashString("Approval(address,address,uint256)")
)
type Transport interface {
Execute(req *RPCRequest, res *RPCResponse) error
}
type Client struct {
tport Transport
nextid uintptr
}
func NewClient(dial func() (io.ReadWriteCloser, error)) *Client {
tp := &RPCTransport{
dial: dial,
pending: make(map[int]*pending),
}
return NewClientTransport(tp)
}
func NewHTTPClient(url string) *Client {
return NewClientTransport(&HTTPTransport{URL: url})
}
func NewClientTransport(tp Transport) *Client {
return &Client{tport: tp}
}
// Data is just binary that can decode Ethereum's silly quoted hex
type Data []byte
func (d *Data) String() string {
if d == nil {
return "<nil>"
}
return string(hexstring(*d, false))
}
func (d Data) MarshalText() ([]byte, error) {
return hexstring(d, false), nil
}
func (d *Data) UnmarshalText(b []byte) error {
s, err := hexparse(b)
if err != nil {
return err
}
*d = s
return nil
}
// Bytes is like Data, but can be be greater than 32 bytes in length
type Bytes []byte
func (b *Bytes) String() string {
if b == nil {
return "<nil>"
}
return string(hexstring(*b, false))
}
func (b Bytes) MarshalText() ([]byte, error) {
return hexstring(b, false), nil
}
func (b *Bytes) UnmarshalText(bx []byte) error {
s, err := hexparse(bx)
if err != nil {
return err
}
*b = s
return nil
}
// Int is a big.Int that can decode Ethereum's silly quoted hex
type Int big.Int
// NewInt allocates and returns a new Int set to x.
func NewInt(x int64) *Int { return (*Int)(big.NewInt(x)) }
// Big is a convenience method for (*big.Int)(i).
func (i *Int) Big() *big.Int {
return (*big.Int)(i)
}
// Scan implements fmt.Scanner
func (i *Int) Scan(s fmt.ScanState, verb rune) error {
// don't let a leading '0x' cause %x to silently
// return 0; use a more generic prefix and let
// (*big.Int).Scan figure it out
if verb == 'x' {
verb = 'v'
}
return i.Big().Scan(s, verb)
}
// Cmp compares this Int to x. See big.Int.Cmp.
func (i *Int) Cmp(x *Int) int {
return i.Big().Cmp(x.Big())
}
func (i *Int) IsZero() bool {
return i.Big().Sign() == 0
}
func (i *Int) Int64() int64 {
return i.Big().Int64()
}
func (i *Int) SetInt64(v int64) {
i.Big().SetInt64(v)
}
func (i *Int) Uint64() uint64 {
return i.Big().Uint64()
}
func (i *Int) SetUint64(v uint64) {
i.Big().SetUint64(v)
}
func (i *Int) Copy() Int {
var out big.Int
out.Set((*big.Int)(i))
return Int(out)
}
func (i *Int) EncodeMsg(w *msgp.Writer) error {
return w.WriteBytes(i.Big().Bytes())
}
func (i *Int) DecodeMsg(r *msgp.Reader) error {
buf, err := r.ReadBytes(nil)
if err != nil {
return err
}
i.Big().SetBytes(buf)
return nil
}
func (i *Int) MarshalMsg(b []byte) ([]byte, error) {
return msgp.AppendBytes(b, i.Big().Bytes()), nil
}
func (i *Int) UnmarshalMsg(b []byte) ([]byte, error) {
buf, rest, err := msgp.ReadBytesBytes(b, nil)
if err != nil {
return rest, err
}
i.Big().SetBytes(buf)
return rest, nil
}
func (i *Int) String() string {
if i == nil {
return "<nil>"
}
return string(hexstring(i.Big().Bytes(), true))
}
// MarshalText implements encoding.TextMarshaler.
func (i Int) MarshalText() ([]byte, error) {
return hexstring(i.Big().Bytes(), true), nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (i *Int) UnmarshalJSON(b []byte) error {
if bytes.Equal(b, rawnull) {
return nil
}
if len(b) >= 2 && b[0] == '"' && b[len(b)-1] == '"' {
return i.UnmarshalText(b[1 : len(b)-1])
}
return i.UnmarshalText(b)
}
// UnmarshalText implements encoding.TextUnmarshaler.
func (i *Int) UnmarshalText(b []byte) error {
if !hexprefix(b) {
return i.Big().UnmarshalText(b)
}
buf, err := hexparse(b)
if err != nil {
return err
}
i.Big().SetBytes(buf)
return nil
}
func (i *Int) FromString(s string) error {
return i.UnmarshalText([]byte(s))
}
func (i *Int) Msgsize() int {
n := (i.Big().BitLen() + 7) / 8
return msgp.BytesPrefixSize + n
}
// Uint64 is a uint64 that marshals as a hex-encoded number.
type Uint64 uint64
func ParseInt(s string) (*Int, error) {
n := new(Int)
if err := n.FromString(s); err != nil {
return nil, err
}
return n, nil
}
// MarshalText implements encoding.TextMarshaler.
func (i Uint64) MarshalText() ([]byte, error) {
var n Int
n.SetUint64(uint64(i))
return n.MarshalText()
}
// UnmarshalJSON implements json.Unmarshaler.
func (i *Uint64) UnmarshalJSON(b []byte) error {
if bytes.Equal(b, rawnull) {
return nil
}
if len(b) >= 2 && b[0] == '"' && b[len(b)-1] == '"' {
return i.UnmarshalText(b[1 : len(b)-1])
}
return i.UnmarshalText(b)
}
// UnmarshalText implements encoding.TextUnmarshaler.
func (i *Uint64) UnmarshalText(b []byte) error {
var n Int
if err := n.UnmarshalText(b); err != nil {
return err
}
if !n.Big().IsUint64() {
return errors.New("overflow: " + string(b))
}
*i = Uint64(n.Uint64())
return nil
}
//go:generate msgp
//msgp:shim json.RawMessage as:string using:string/json.RawMessage
// Address represent an Ethereum address
type Address [20]byte
// ParseAddress parses an address.
func ParseAddress(s string) (*Address, error) {
a := new(Address)
if err := a.FromString(s); err != nil {
return nil, err
}
return a, nil
}
func (a *Address) String() string {
return string(hexstring(a[:], false))
}
func (a *Address) FromString(s string) error {
return hexdecode(a[:], []byte(s))
}
// Scan implements fmt.Scanner (uses the verb %a)
func (a *Address) Scan(s fmt.ScanState, x rune) error {
if x != 'a' {
return fmt.Errorf("rune %q not valid verb for address", x)
}
tok, err := s.Token(false, nil)
if err != nil {
return err
}
return hexdecode(a[:], tok)
}
func (a Address) MarshalText() ([]byte, error) {
return hexstring(a[:], false), nil
}
func (a *Address) UnmarshalText(b []byte) error {
return hexdecode(a[:], b)
}
// Zero returns whether this is the zero address.
func (a *Address) Zero() bool {
return a == nil || *a == Address{}
}
// Hash represents a Keccak256 hash
type Hash [32]byte
// ParseHash parses a hash.
func ParseHash(s string) (*Hash, error) {
h := new(Hash)
if err := h.FromString(s); err != nil {
return nil, err
}
return h, nil
}
// String produces the hash as a 0x-prefixed hex string
func (h *Hash) String() string {
return string(hexstring(h[:], false))
}
func (h *Hash) FromString(s string) error {
return hexdecode(h[:], []byte(s))
}
func (h Hash) MarshalText() ([]byte, error) {
return hexstring(h[:], false), nil
}
func (h *Hash) UnmarshalText(b []byte) error {
return hexdecode(h[:], b)
}
// Scan implements fmt.Scanner (uses %h verb)
func (h *Hash) Scan(s fmt.ScanState, verb rune) error {
if verb != 'h' {
return fmt.Errorf("verb %q invalid for hash", verb)
}
tok, err := s.Token(false, nil)
if err != nil {
return err
}
return hexdecode(h[:], tok)
}
// Block represents and Ethereum block
type Block struct {
Number *Uint64 `json:"number"` // block number, or nil if pending
Hash *Hash `json:"hash"` // block hash, or nil if pending
Parent Hash `json:"parentHash"` // parent block hash
Nonce Uint64 `json:"nonce"`
UncleHash Hash `json:"sha3Uncles"` // hash of uncles in block
Bloom Data `json:"logsBloom,omitempty"` // bloom filter of logs, or nil if pending
TxRoot Hash `json:"transactionsRoot"` // root of transaction trie of block
StateRoot Hash `json:"stateRoot"` // root of final state trie of block
ReceiptsRoot Hash `json:"receiptsRoot"` // root of receipts trie of block
Miner Address `json:"miner"`
GasLimit Uint64 `json:"gasLimit"`
GasUsed Uint64 `json:"gasUsed"`
Transactions []json.RawMessage `json:"transactions"` // transactions; either hex strings of hashes, or actual tx bodies
Uncles []Hash `json:"uncles"` // array of uncle hashes
Difficulty *Int `json:"difficulty"`
TotalDifficulty *Int `json:"totalDifficulty"`
Timestamp Uint64 `json:"timestamp"`
Extra Data `json:"extraData,omitempty"`
}
// Time turns the block timestamp into a time.Time
func (b *Block) Time() time.Time {
return time.Unix(int64(b.Timestamp), 0)
}
// Transactions returns the list of block transactions, given
// that b.Transactions is a set of serialized transactions, and
// not just a set of tx hashes.
func (b *Block) ParseTransactions() ([]Transaction, error) {
out := make([]Transaction, len(b.Transactions))
for i := range b.Transactions {
err := json.Unmarshal(b.Transactions[i], &out[i])
if err != nil {
return nil, err
}
}
return out, nil
}
// RPCRequest is a request to be sent to an RPC server.
type RPCRequest struct {
Version string `json:"jsonrpc"`
Method string `json:"method"`
Params []json.RawMessage `json:"params"`
ID int `json:"id"`
}
// RPCError is an error returned by a server
type RPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data"`
}
func (e *RPCError) Error() string {
return fmt.Sprintf("%s (code %d) %s", e.Message, e.Code, e.Data)
}
// RPCResponse is a response returned by an RPC server.
type RPCResponse struct {
ID int `json:"id"`
Version string `json:"jsonrpc"`
Result json.RawMessage `json:"result"`
Error RPCError `json:"error"`
}
// ProtocolVersion gets the protocol version of the node.
func (c *Client) ProtocolVersion() (string, error) {
var version string
if err := c.Do("eth_protocolVersion", nil, &version); err != nil {
return "", err
}
return version, nil
}
// SyncStatus indicates the syncing status of the node.
type SyncStatus struct {
Starting Uint64 `json:"startingBlock"` // Starting block of sync.
Current Uint64 `json:"currentBlock"` // Current block of sync.
Highest Uint64 `json:"highestBlock"` // Highest block of sync, estimated.
}
// Syncing returns the syncing status of the node, or nil if not syncing.
func (c *Client) Syncing() (*SyncStatus, error) {
var raw json.RawMessage
if err := c.Do("eth_syncing", nil, &raw); err != nil {
return nil, err
} else if bytes.Equal(raw, rawfalse) {
return nil, nil
}
status := new(SyncStatus)
if err := json.Unmarshal(raw, status); err != nil {
return nil, err
}
return status, nil
}
// Coinbase returns the client coinbase address.
func (c *Client) Coinbase() (*Address, error) {
addr := new(Address)
if err := c.Do("eth_coinbase", nil, addr); err != nil {
return nil, err
}
return addr, nil
}
// Mining returns whether the node is actively mining blocks.
func (c *Client) Mining() (bool, error) {
var mining bool
if err := c.Do("eth_mining", nil, &mining); err != nil {
return false, err
}
return mining, nil
}
// Hashrate gets the number of hashes per second that the node is mining with.
func (c *Client) Hashrate() (int64, error) {
var rate Uint64
if err := c.Do("eth_hashrate", nil, &rate); err != nil {
return 0, err
}
return int64(rate), nil
}
// GasPrice gets the gas price in wei.
func (c *Client) GasPrice() (int64, error) {
var wei Uint64
if err := c.Do("eth_gasPrice", nil, &wei); err != nil {
return 0, err
}
return int64(wei), nil
}
// Accounts gets the accounts owned by the client.
func (c *Client) Accounts() ([]Address, error) {
var out []Address
if err := c.Do("eth_accounts", nil, &out); err != nil {
return nil, err
}
return out, nil
}
// BlockNumber gets the number of the most recent block.
func (c *Client) BlockNumber() (int64, error) {
var block Uint64
if err := c.Do("eth_blockNumber", nil, &block); err != nil {
return 0, err
}
return int64(block), nil
}
// Pending returns the list of pending transactions.
func (c *Client) Pending() ([]Transaction, error) {
b, err := c.GetBlock(-1, true)
if err != nil {
return nil, err
}
return b.ParseTransactions()
}
var rawtrue = json.RawMessage("true")
var rawfalse = json.RawMessage("false")
var rawpending = json.RawMessage(`"pending"`)
var rawlatest = json.RawMessage(`"latest"`)
var rawearliest = json.RawMessage(`"earliest"`)
var rawnull = json.RawMessage("null")
// Block specifiers.
const (
Pending = int64(-2) // Pending block.
Latest = int64(-1) // Latest block.
Earliest = int64(0) // Earliest block.
)
// itobs converts an int to a block specifier.
func itobs(i int64) json.RawMessage {
switch i {
case Pending:
return rawpending
case Latest:
return rawlatest
case Earliest:
return rawearliest
}
return itox(i)
}
// GetNonceAt gets the account nonce for a specific address
// and at a specific block number.
func (c *Client) GetNonceAt(addr *Address, blocknum int64) (int64, error) {
var params [2]json.RawMessage
buf, _ := json.Marshal(addr)
params[0] = buf
params[1] = itobs(blocknum)
var num Int
err := c.Do("eth_getTransactionCount", params[:], &num)
return num.Int64(), err
}
// GetNonce gets the account nonce for an address in the latest block.
func (c *Client) GetNonce(addr *Address) (int64, error) {
return c.GetNonceAt(addr, Latest)
}
// GetBalanceAt gets the balance for a specific address
// and at a specific block number.
func (c *Client) GetBalanceAt(addr *Address, blocknum int64) (Int, error) {
var params [2]json.RawMessage
buf, _ := json.Marshal(addr)
params[0] = buf
params[1] = itobs(blocknum)
wei := Int{}
err := c.Do("eth_getBalance", params[:], &wei)
return wei, err
}
// GetBalance gets the balance of an address in wei at the latest block.
func (c *Client) GetBalance(addr *Address) (Int, error) {
return c.GetBalanceAt(addr, Latest)
}
// GetBlock gets a block by block number. If 'txs' is true,
// the block includes all the transactions in the block; otherwise
// it only includes the transaction hashes.
func (c *Client) GetBlock(num int64, txs bool) (*Block, error) {
params := make([]json.RawMessage, 2)
params[0] = itobs(num)
if txs {
params[1] = rawtrue
} else {
params[1] = rawfalse
}
out := Block{}
err := c.Do("eth_getBlockByNumber", params, &out)
if err != nil {
return nil, err
}
return &out, nil
}
// GetTransaction gets a transaction by its hash
func (c *Client) GetTransaction(h *Hash) (*Transaction, error) {
buf, _ := json.Marshal(h)
o := new(Transaction)
err := c.Do("eth_getTransactionByHash", []json.RawMessage{buf}, o)
if err != nil {
return nil, err
}
return o, nil
}
// Latest returns the latest block
func (c *Client) Latest(txs bool) (*Block, error) {
return c.GetBlock(Latest, txs)
}
// BlockIterator manages a channel that
// yields blocks in block number order.
type BlockIterator struct {
c *Client
out chan *Block
done chan struct{}
}
// Stop causes the block itertation to stop.
// It should only be called once.
func (b *BlockIterator) Stop() {
close(b.done)
}
func (b *BlockIterator) getLoop(block int64, txs bool) {
for {
select {
case <-b.done:
close(b.out)
return
default:
v, err := b.c.GetBlock(block, txs)
if err != nil {
if err != ErrNotFound {
log.Printf("error getting block %d: %s", block, err)
}
time.Sleep(1 * time.Second)
continue
}
b.out <- v
block++
}
}
}
// Next returns the next block in the chain. The channel will
// be closed when Stop() is called.
func (b *BlockIterator) Next() <-chan *Block { return b.out }
// IterateBlocks creates a BlockIterator that starts at the
// given block number.
func (c *Client) IterateBlocks(from int64, txs bool) *BlockIterator {
b := &BlockIterator{c: c, out: make(chan *Block, 64), done: make(chan struct{})}
go b.getLoop(from, txs)
return b
}
// Receipt is a transaction receipt
type Receipt struct {
Hash Hash `json:"transactionHash"`
Index Uint64 `json:"transactionIndex"`
BlockHash Hash `json:"blockHash"`
BlockNumber Uint64 `json:"blockNumber"`
GasUsed Uint64 `json:"gasUsed"`
Cumulative Uint64 `json:"cumulativeGasUsed"`
Address *Address `json:"contractAddress"` // contract created, or none if not a contract creation
Status Uint64 `json:"status"`
Logs []Log `json:"logs"`
}
// Threw returns whether the transaction threw.
func (r *Receipt) Threw() bool {
return r.Status == 0
}
// GetCodeAt gets the code for the given address at the given block.
func (c *Client) GetCodeAt(addr *Address, blocknum int64) ([]byte, error) {
var params [2]json.RawMessage
buf, _ := json.Marshal(addr)
params[0] = buf
params[1] = itobs(blocknum)
var out Data
err := c.Do("eth_getCode", params[:], &out)
if err != nil {
return nil, err
}
return []byte(out), nil
}
// GetCode gets the code for the given address in the latest block.
func (c *Client) GetCode(addr *Address) ([]byte, error) {
return c.GetCodeAt(addr, Latest)
}
// GetReceipt gets a receipt for a given transaction hash.
func (c *Client) GetReceipt(tx *Hash) (*Receipt, error) {
buf, _ := json.Marshal(tx)
out := &Receipt{}
err := c.Do("eth_getTransactionReceipt", []json.RawMessage{buf}, out)
if err != nil {
return nil, err
}
return out, nil
}
// Log is an Ethereum log (or, in Solidity, an "event")
type Log struct {
Removed bool `json:"removed"`
LogIndex *Uint64 `json:"logIndex"` // nil if pending; same for following fields
TxIndex *Uint64 `json:"transactionIndex"`
TxHash *Hash `json:"transactionHash"`
BlockHash *Hash `json:"blockHash"`
BlockNumber *Uint64 `json:"blockNumber"`
Address Address `json:"address"`
Data Data `json:"data"` // serialized log arguments
Topics []Data `json:"topics"` // indexed log arguments
}
// TokenTransfer represents an ERC20 token transfer event
type TokenTransfer struct {
Block int64 // block number
TxHeight int // index of transaction in block
Token Address // address of contract
From Address // 'from' argument in transfer
To Address // 'to' argument in transfer
Amount Int // value amount
}
func flatten(i *Int) int64 {
return (*big.Int)(i).Int64()
}
func setdata(i *Int, b []byte) {
(*big.Int)(i).SetBytes(b)
}
// ParseTransfer tries to parse this log as
// an ERC20 token transfer event, with the signature
// event Transfer(address indexed from, address indexed to, uint256 value);
func (r *Receipt) ParseTransfer(l *Log) (TokenTransfer, bool) {
if len(l.Topics) != 3 || len(l.Topics[1]) != 32 || len(l.Topics[2]) != 32 {
return TokenTransfer{}, false
}
if !bytes.Equal(l.Topics[0], ERC20Transfer[:]) {
return TokenTransfer{}, false
}
tt := TokenTransfer{Block: int64(r.BlockNumber), TxHeight: int(r.Index), Token: l.Address}
copy(tt.From[:], l.Topics[1][12:]) // these are addresses; first 12 bytes should be zeros
copy(tt.To[:], l.Topics[2][12:])
setdata(&tt.Amount, l.Data)
return tt, true
}