-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththorgo.go
56 lines (46 loc) · 1.94 KB
/
thorgo.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
package thorgo
import (
"github.com/darrenvechain/thorgo/accounts"
"github.com/darrenvechain/thorgo/blocks"
"github.com/darrenvechain/thorgo/crypto/tx"
"github.com/darrenvechain/thorgo/thorest"
"github.com/darrenvechain/thorgo/transactions"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
)
type Thor struct {
Blocks *blocks.Blocks
Client *thorest.Client
}
func New(url string) *Thor {
c := thorest.NewClientFromURL(url)
return &Thor{Client: c, Blocks: blocks.New(c)}
}
func NewFromClient(c *thorest.Client) *Thor {
return &Thor{Client: c, Blocks: blocks.New(c)}
}
// Account can be used to query account information such as balance, code, storage, etc.
// It also provides a way to interact with contracts.
func (t *Thor) Account(address common.Address) *accounts.Visitor {
return accounts.New(t.Client, address)
}
// Transaction provides utility functions to fetch or wait for transactions and their receipts.
func (t *Thor) Transaction(hash common.Hash) *transactions.Visitor {
return transactions.New(t.Client, hash)
}
// Transactor creates a new transaction builder which makes it easier to build, simulate and send transactions.
func (t *Thor) Transactor(clauses []*tx.Clause) *transactions.Transactor {
return transactions.NewTransactor(t.Client, clauses)
}
// Events sets up a query builder to fetch smart contract solidity events.
func (t *Thor) Events(criteria []thorest.EventCriteria, filters *thorest.LogFilters) ([]thorest.EventLog, error) {
return t.Client.FilterEvents(criteria, filters)
}
// Transfers sets up a query builder to fetch VET transfers.
func (t *Thor) Transfers(criteria []thorest.TransferCriteria, filters *thorest.LogFilters) ([]thorest.TransferLog, error) {
return t.Client.FilterTransfers(criteria, filters)
}
// Deployer makes it easier to deploy contracts.
func (t *Thor) Deployer(bytecode []byte, abi *abi.ABI) *accounts.Deployer {
return accounts.NewDeployer(t.Client, bytecode, abi)
}