Skip to content

Commit

Permalink
chore: add utilities function to near lake framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Himitsuko committed Nov 30, 2022
1 parent d0b54b9 commit 6141582
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
35 changes: 30 additions & 5 deletions types/action_view.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package types

import "encoding/json"
import (
"encoding/base64"
"encoding/json"
)

type ActionView map[string]interface{}
type ActionArgs string

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"`
MethodName string `json:"method_name"`
Args ActionArgs `json:"args"`
Gas *BigInt `json:"gas"`
Deposit *BigInt `json:"deposit"`
}

type Transfer struct {
Expand Down Expand Up @@ -56,3 +60,24 @@ func (actionView *ActionView) GetFunctionCall() *FunctionCall {
}
return nil
}

func (args *ActionArgs) Decode() (string, error) {
decodedData, err := base64.StdEncoding.DecodeString(string(*args))
if err != nil {
return "{}", err
}
return string(decodedData), nil
}

func ConvertActionView(i interface{}) *ActionView {
data, err := json.Marshal(i)
if err != nil {
return nil
}
action := ActionView{}
err = json.Unmarshal(data, &action)
if err != nil {
return nil
}
return &action
}
27 changes: 20 additions & 7 deletions types/signed_transaction_view.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
package types

type TransactionAction string

const (
FunctionCallAction = "FunctionCall"
TransferAction = "Transfer"
)

type SignedTransactionView struct {
SignerId string `json:"signer_id"`
PublicKey string `json:"public_key"`
Nonce uint64 `json:"nonce"`
ReceiverId string `json:"receiver_id"`
Actions []map[string]interface{} `json:"actions"`
Signature string `json:"signature"`
Hash string `json:"hash"`
SignerId string `json:"signer_id"`
PublicKey string `json:"public_key"`
Nonce uint64 `json:"nonce"`
ReceiverId string `json:"receiver_id"`
Actions []interface{} `json:"actions"`
Signature string `json:"signature"`
Hash string `json:"hash"`
}

func (s SignedTransactionView) LoopActions(f func(interface{})) {
for _, action := range s.Actions {
f(action)
}
}

0 comments on commit 6141582

Please sign in to comment.