-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Himitsuko
committed
Nov 29, 2022
1 parent
033fe57
commit d0b54b9
Showing
4 changed files
with
154 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,58 @@ | ||
package types | ||
|
||
type ActionView struct { | ||
import "encoding/json" | ||
|
||
type ActionView map[string]interface{} | ||
|
||
type DeployContract struct { | ||
Code string `json:"code"` | ||
} | ||
|
||
type FunctionCall struct { | ||
MethodName string `json:"method_name"` | ||
Args string `json:"args"` | ||
Gas *BigInt `json:"gas"` | ||
Deposit *BigInt `json:"deposit"` | ||
} | ||
|
||
type Transfer struct { | ||
Deposit *BigInt `json:"deposit"` | ||
} | ||
|
||
type Stake struct { | ||
Stake *BigInt `json:"stake"` | ||
PublicKey string `json:"public_key"` | ||
} | ||
|
||
func (actionView *ActionView) IsDeployContract() bool { | ||
_, ok := (*actionView)["DeployContract"] | ||
return ok | ||
} | ||
|
||
func (actionView *ActionView) IsFunctionCall() bool { | ||
_, ok := (*actionView)["FunctionCall"] | ||
return ok | ||
} | ||
|
||
func (actionView *ActionView) IsTransfer() bool { | ||
_, ok := (*actionView)["Transfer"] | ||
return ok | ||
} | ||
|
||
func (actionView *ActionView) IsStake() bool { | ||
_, ok := (*actionView)["Stake"] | ||
return ok | ||
} | ||
|
||
func (actionView *ActionView) GetFunctionCall() *FunctionCall { | ||
if actionView.IsFunctionCall() { | ||
data, err := json.Marshal((*actionView)["FunctionCall"]) | ||
if err != nil { | ||
return nil | ||
} | ||
fc := FunctionCall{} | ||
err = json.Unmarshal(data, &fc) | ||
return &fc | ||
} | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,46 @@ | ||
package types | ||
|
||
type ExecutionOutcomeView struct { | ||
Logs []string `json:"logs"` | ||
ReceiptIds []string `json:"receipt_ids"` | ||
GasBurnt uint64 `json:"gas_burnt"` | ||
TokensBurnt *BigInt `json:"tokens_burnt"` | ||
ExecutorId string `json:"executor_id"` | ||
Status map[string]interface{} `json:"status"` | ||
Metadata ExecutionMetadataView `json:"metadata"` | ||
Logs []string `json:"logs"` | ||
ReceiptIds []string `json:"receipt_ids"` | ||
GasBurnt uint64 `json:"gas_burnt"` | ||
TokensBurnt *BigInt `json:"tokens_burnt"` | ||
ExecutorId string `json:"executor_id"` | ||
Status Status `json:"status"` | ||
Metadata ExecutionMetadataView `json:"metadata"` | ||
} | ||
|
||
type Status map[string]interface{} | ||
|
||
func (status Status) IsUnknown() bool { | ||
_, ok := status["Unknown"] | ||
return ok | ||
} | ||
|
||
func (status Status) IsFailure() bool { | ||
_, ok := status["Failure"] | ||
return ok | ||
} | ||
|
||
func (status Status) IsSuccess() bool { | ||
_, ok1 := status["SuccessValue"] | ||
_, ok2 := status["SuccessReceiptId"] | ||
|
||
return ok1 || ok2 | ||
} | ||
|
||
func (status Status) SuccessValue() *string { | ||
_, ok := status["SuccessValue"] | ||
if status.IsSuccess() && ok { | ||
return status["SuccessValue"].(*string) | ||
} | ||
return nil | ||
} | ||
|
||
func (status Status) SuccessReceiptId() *string { | ||
_, ok := status["SuccessReceiptId"] | ||
if status.IsSuccess() && ok { | ||
return status["SuccessReceiptId"].(*string) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,61 @@ | ||
package types | ||
|
||
import "encoding/json" | ||
|
||
type ReceiptView struct { | ||
PredecessorId string `json:"predecessor_id"` | ||
ReceiverId string `json:"receiver_id"` | ||
ReceiptId string `json:"receipt_id"` | ||
Receipt map[string]interface{} `json:"receipt"` | ||
PredecessorId string `json:"predecessor_id"` | ||
ReceiverId string `json:"receiver_id"` | ||
ReceiptId string `json:"receipt_id"` | ||
Receipt Receipt `json:"receipt"` | ||
} | ||
|
||
type DataReceiverView struct { | ||
DataId string `json:"data_id"` | ||
ReceiverId string `json:"receiver_id"` | ||
} | ||
|
||
type Data struct { | ||
DataId string | ||
Data []uint8 | ||
} | ||
|
||
type Action struct { | ||
SignerId string `json:"signer_id"` | ||
SignerPublicKey string `json:"signer_public_key"` | ||
GasPrice *BigInt `json:"gas_price"` | ||
OutputDataReceivers []DataReceiverView `json:"output_data_receivers"` | ||
InputDataIds []string `json:"input_data_ids"` | ||
Actions []ActionView `json:"actions"` | ||
} | ||
|
||
type Receipt map[string]interface{} | ||
|
||
func (receipt Receipt) IsAction() bool { | ||
_, ok := receipt["Action"] | ||
return ok | ||
} | ||
|
||
func (receipt Receipt) IsData() bool { | ||
_, ok := receipt["Data"] | ||
return ok | ||
} | ||
|
||
func (receipt Receipt) GetAction() *Action { | ||
if receipt.IsAction() { | ||
data, err := json.Marshal(receipt["Action"]) | ||
if err != nil { | ||
return nil | ||
} | ||
action := Action{} | ||
err = json.Unmarshal(data, &action) | ||
return &action | ||
} | ||
return nil | ||
} | ||
|
||
func (receipt Receipt) GetData() *Data { | ||
if receipt.IsData() { | ||
return receipt["Data"].(*Data) | ||
} | ||
return nil | ||
} |