forked from NethermindEth/starknet.go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
149 lines (124 loc) · 4.15 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
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
package types
import (
"fmt"
"math/big"
"strconv"
"github.com/NethermindEth/juno/core/felt"
)
type NumAsHex string
type AddInvokeTransactionOutput struct {
TransactionHash *felt.Felt `json:"transaction_hash"`
}
type AddDeclareResponse struct {
Code string `json:"code"`
TransactionHash string `json:"transaction_hash"`
ClassHash string `json:"class_hash"`
}
type AddDeployResponse struct {
Code string `json:"code"`
TransactionHash string `json:"transaction_hash"`
ContractAddress string `json:"address"`
}
// // TODO: remove
// type DeployRequest struct {
// Type string `json:"type"`
// ContractAddressSalt string `json:"contract_address_salt"`
// ConstructorCalldata []string `json:"constructor_calldata"`
// ContractDefinition rpc.ContractClass `json:"contract_definition"`
// }
type DeployAccountRequest struct {
MaxFee *big.Int `json:"max_fee"`
// Version of the transaction scheme, should be set to 0 or 1
Version *big.Int `json:"version"`
// Signature
Signature Signature `json:"signature"`
// Nonce should only be set with Transaction V1
Nonce *big.Int `json:"nonce,omitempty"`
Type string `json:"type"`
ContractAddressSalt string `json:"contract_address_salt"`
ConstructorCalldata []string `json:"constructor_calldata"`
ClassHash string `json:"class_hash"`
}
// FunctionCall function call information
type FunctionCall struct {
ContractAddress *felt.Felt `json:"contract_address"`
EntryPointSelector *felt.Felt `json:"entry_point_selector,omitempty"`
// Calldata The parameters passed to the function
Calldata []*felt.Felt `json:"calldata"`
}
type Signature []*big.Int
// todo(): what is this used for?
type FunctionInvoke struct {
MaxFee *big.Int `json:"max_fee"`
// Version of the transaction scheme, should be set to 0 or 1
Version *big.Int `json:"version"`
// Signature
Signature Signature `json:"signature"`
// Nonce should only be set with Transaction V1
Nonce *big.Int `json:"nonce,omitempty"`
// Defines the transaction type to invoke
Type string `json:"type,omitempty"`
SenderAddress *felt.Felt `json:"sender_address"`
EntryPointSelector string `json:"entry_point_selector,omitempty"`
// Calldata The parameters passed to the function
Calldata []string `json:"calldata"`
}
type FeeEstimate struct {
// GasConsumed the Ethereum gas cost of the transaction (see https://docs.starknet.io/docs/Fees/fee-mechanism for more info)
GasConsumed NumAsHex `json:"gas_consumed"`
// GasPrice the gas price (in gwei) that was used in the cost estimation
GasPrice NumAsHex `json:"gas_price"`
// OverallFee the estimated fee for the transaction (in gwei), product of gas_consumed and gas_price
OverallFee NumAsHex `json:"overall_fee"`
}
// ExecuteDetails provides some details about the execution.
type ExecuteDetails struct {
MaxFee *big.Int
Nonce *big.Int
}
type TransactionState string
const (
TransactionAcceptedOnL1 TransactionState = "ACCEPTED_ON_L1"
TransactionAcceptedOnL2 TransactionState = "ACCEPTED_ON_L2"
TransactionNotReceived TransactionState = "NOT_RECEIVED"
TransactionPending TransactionState = "PENDING"
TransactionReceived TransactionState = "RECEIVED"
TransactionRejected TransactionState = "REJECTED"
)
func (ts *TransactionState) UnmarshalJSON(data []byte) error {
unquoted, err := strconv.Unquote(string(data))
if err != nil {
return err
}
switch unquoted {
case "ACCEPTED_ON_L2":
*ts = TransactionAcceptedOnL2
case "ACCEPTED_ON_L1":
*ts = TransactionAcceptedOnL1
case "NOT_RECEIVED":
*ts = TransactionNotReceived
case "PENDING":
*ts = TransactionPending
case "RECEIVED":
*ts = TransactionReceived
case "REJECTED":
*ts = TransactionRejected
default:
return fmt.Errorf("unsupported status: %s", data)
}
return nil
}
func (ts TransactionState) MarshalJSON() ([]byte, error) {
return []byte(strconv.Quote(string(ts))), nil
}
func (s TransactionState) String() string {
return string(s)
}
func (s TransactionState) IsTransactionFinal() bool {
if s == TransactionAcceptedOnL2 ||
s == TransactionAcceptedOnL1 ||
s == TransactionRejected {
return true
}
return false
}