/
api_ft.go
91 lines (78 loc) · 3.01 KB
/
api_ft.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
// Copyright 2018 The SET Team Authors
// This file is part of the SET project.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package sdk
import (
"math/big"
"github.com/Second-Earth/setchain/params"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/Second-Earth/setchain/common"
"github.com/Second-Earth/setchain/rpc"
"github.com/Second-Earth/setchain/types"
)
// SendRawTransaction send signed tx
func (api *API) SendRawTransaction(rawTx []byte) (common.Hash, error) {
hash := new(common.Hash)
err := api.client.Call(hash, "set_sendRawTransaction", hexutil.Bytes(rawTx))
return *hash, err
}
// GetCurrentBlock get current block info
func (api *API) GetCurrentBlock(fullTx bool) (map[string]interface{}, error) {
block := map[string]interface{}{}
err := api.client.Call(&block, "set_getCurrentBlock", fullTx)
return block, err
}
// GetBlockByHash get block info
func (api *API) GetBlockByHash(hash common.Hash, fullTx bool) (map[string]interface{}, error) {
block := map[string]interface{}{}
err := api.client.Call(&block, "set_getBlockByHash", hash, fullTx)
return block, err
}
// GetBlockByNumber get block info
func (api *API) GetBlockByNumber(number int64, fullTx bool) (map[string]interface{}, error) {
block := map[string]interface{}{}
err := api.client.Call(&block, "set_getBlockByNumber", rpc.BlockNumber(number), fullTx)
return block, err
}
// GetTransactionByHash get tx info by hash
func (api *API) GetTransactionByHash(hash common.Hash) (*types.RPCTransaction, error) {
tx := &types.RPCTransaction{}
err := api.client.Call(tx, "set_getTransactionByHash", hash)
return tx, err
}
// GetTransactionReceiptByHash get tx info by hash
func (api *API) GetTransactionReceiptByHash(hash common.Hash) (*types.RPCReceipt, error) {
receipt := &types.RPCReceipt{}
err := api.client.Call(receipt, "set_getTransactionReceipt", hash)
return receipt, err
}
// GasPrice get gas price
func (api *API) GasPrice() (*big.Int, error) {
gasprice := big.NewInt(0)
err := api.client.Call(gasprice, "set_gasPrice")
return gasprice, err
}
// GetChainConfig get chain config
func (api *API) GetChainConfig() (*params.ChainConfig, error) {
cfg := ¶ms.ChainConfig{}
err := api.client.Call(cfg, "set_getChainConfig")
return cfg, err
}
// // GetGenesis get chain config
// func (api *API) GetGenesis() (*params.ChainConfig, error) {
// cfg := ¶ms.ChainConfig{}
// err := api.client.Call(cfg, "set_getGenesis")
// return cfg, err
// }