-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
107 lines (92 loc) · 3.06 KB
/
types.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
// Copyright (c) 2018 The VeChainThor developers
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>
package accounts
import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/miniBamboo/workshare/api/transactions"
"github.com/miniBamboo/workshare/runtime"
"github.com/miniBamboo/workshare/workshare"
)
//Account for marshal account
type Account struct {
Balance math.HexOrDecimal256 `json:"balance"`
Energy math.HexOrDecimal256 `json:"energy"`
HasCode bool `json:"hasCode"`
}
//CallData represents contract-call body
type CallData struct {
Value *math.HexOrDecimal256 `json:"value"`
Data string `json:"data"`
Gas uint64 `json:"gas"`
GasPrice *math.HexOrDecimal256 `json:"gasPrice"`
Caller *workshare.Address `json:"caller"`
}
type CallResult struct {
Data string `json:"data"`
Events []*transactions.Event `json:"events"`
Transfers []*transactions.Transfer `json:"transfers"`
GasUsed uint64 `json:"gasUsed"`
Reverted bool `json:"reverted"`
VMError string `json:"vmError"`
}
func convertCallResultWithInputGas(vo *runtime.Output, inputGas uint64) *CallResult {
gasUsed := inputGas - vo.LeftOverGas
var (
vmError string
reverted bool
)
if vo.VMErr != nil {
reverted = true
vmError = vo.VMErr.Error()
}
events := make([]*transactions.Event, len(vo.Events))
transfers := make([]*transactions.Transfer, len(vo.Transfers))
for j, txEvent := range vo.Events {
event := &transactions.Event{
Address: txEvent.Address,
Data: hexutil.Encode(txEvent.Data),
}
event.Topics = make([]workshare.Bytes32, len(txEvent.Topics))
for k, topic := range txEvent.Topics {
event.Topics[k] = topic
}
events[j] = event
}
for j, txTransfer := range vo.Transfers {
transfer := &transactions.Transfer{
Sender: txTransfer.Sender,
Recipient: txTransfer.Recipient,
Amount: (*math.HexOrDecimal256)(txTransfer.Amount),
}
transfers[j] = transfer
}
return &CallResult{
Data: hexutil.Encode(vo.Data),
Events: events,
Transfers: transfers,
GasUsed: gasUsed,
Reverted: reverted,
VMError: vmError,
}
}
type Clause struct {
To *workshare.Address `json:"to"`
Value *math.HexOrDecimal256 `json:"value"`
Data string `json:"data"`
}
//Clauses array of clauses.
type Clauses []Clause
//BatchCallData executes a batch of codes
type BatchCallData struct {
Clauses Clauses `json:"clauses"`
Gas uint64 `json:"gas"`
GasPrice *math.HexOrDecimal256 `json:"gasPrice"`
ProvedWork *math.HexOrDecimal256 `json:"provedWork"`
Caller *workshare.Address `json:"caller"`
GasPayer *workshare.Address `json:"gasPayer"`
Expiration uint32 `json:"expiration"`
BlockRef string `json:"blockRef"`
}
type BatchCallResults []*CallResult