Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

Commit

Permalink
Migrate from parameter array argument to json string
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyatt Mufson committed Jan 28, 2019
1 parent 5094c6e commit d773808
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
output/
.DS_Store
25 changes: 12 additions & 13 deletions neoutils/ont.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ func ClaimONG(endpoint string, gasPrice int, gasLimit int, wif string) (string,
return txid, nil
}

func BuildOntologyInvocationTransaction(contractHex string, operation string, args []ontmobile.Parameter, gasPrice uint, gasLimit uint, wif string) (string, error) {
raw, err := ontmobile.BuildInvocationTransaction(contractHex, operation, args, gasPrice, gasLimit, wif)
func BuildOntologyInvocationTransaction(contractHex string, operation string, argString string, gasPrice uint, gasLimit uint, wif string) (string, error) {
raw, err := ontmobile.BuildInvocationTransaction(contractHex, operation, argString, gasPrice, gasLimit, wif)
if err != nil {
return "", err
}

return raw, nil
}

func OntologyInvoke(endpoint string, contractHex string, operation string, args []Parameter, gasPrice uint, gasLimit uint, wif string) (string, error) {
raw, err := ontmobile.BuildInvocationTransaction(contractHex, operation, args, gasPrice, gasLimit, wif)
// OntologyInvoke : Invoke a neovm contract in Ontology
func OntologyInvoke(endpoint string, contractHex string, operation string, argString string, gasPrice uint, gasLimit uint, wif string) (string, error) {
raw, err := ontmobile.BuildInvocationTransaction(contractHex, operation, argString, gasPrice, gasLimit, wif)
if err != nil {
return "", err
}
Expand All @@ -58,13 +59,11 @@ func OntologyInvoke(endpoint string, contractHex string, operation string, args
return txid, nil
}

type Parameter = ontmobile.Parameter
type ParameterType = ontmobile.ParameterType
type ParameterJSONArrayForm struct {
A []ParameterJSONForm `json:"array"`
}

const (
Address = ontmobile.Address
String = ontmobile.String
Integer = ontmobile.Integer
Fixed8 = ontmobile.Fixed8
Array = ontmobile.Array
)
type ParameterJSONForm struct {
T string `json:"type"`
V interface{} `json:"value"`
}
21 changes: 13 additions & 8 deletions neoutils/ont_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"log"
"math"
"testing"
"encoding/json"

"github.com/o3labs/neo-utils/neoutils"
)
Expand Down Expand Up @@ -59,15 +60,17 @@ func TestBuildOntologyInvocation(t *testing.T) {
account, _ := neoutils.GenerateFromWIF(wif)
address := account.Address

addr := neoutils.Parameter{neoutils.Address, address}
val := neoutils.Parameter{neoutils.String, "Hi there"}
addr := neoutils.ParameterJSONForm{T: "Address", V: address}
val := neoutils.ParameterJSONForm{T: "String", V: "Hi there"}

args := []neoutils.Parameter{addr, val}
jsondat := &neoutils.ParameterJSONArrayForm{A: []neoutils.ParameterJSONForm{addr, val}}
argData, _ := json.Marshal(jsondat)
argString := string(argData)

gasPrice := uint(500)
gasLimit := uint(20000)

txData, err := neoutils.BuildOntologyInvocationTransaction("c168e0fb1a2bddcd385ad013c2c98358eca5d4dc", "put", args, gasPrice, gasLimit, wif)
txData, err := neoutils.BuildOntologyInvocationTransaction("c168e0fb1a2bddcd385ad013c2c98358eca5d4dc", "put", argString, gasPrice, gasLimit, wif)
if err != nil {
log.Printf("Error creating invocation transaction: %s", err)
t.Fail()
Expand All @@ -86,17 +89,19 @@ func TestOntologyInvoke(t *testing.T) {
account, _ := neoutils.GenerateFromWIF(wif)
address := account.Address

addr := neoutils.Parameter{neoutils.Address, address}
val := neoutils.Parameter{neoutils.String, "Hi there"}
addr := neoutils.ParameterJSONForm{T: "Address", V: address}
val := neoutils.ParameterJSONForm{T: "String", V: "Hi there"}

args := []neoutils.Parameter{addr, val}
jsondat := &neoutils.ParameterJSONArrayForm{A: []neoutils.ParameterJSONForm{addr, val}}
argData, _ := json.Marshal(jsondat)
argString := string(argData)

gasPrice := uint(500)
gasLimit := uint(20000)

endpoint := "http://polaris2.ont.io:20336"

txid, err := neoutils.OntologyInvoke(endpoint, "c168e0fb1a2bddcd385ad013c2c98358eca5d4dc", "put", args, gasPrice, gasLimit, wif)
txid, err := neoutils.OntologyInvoke(endpoint, "c168e0fb1a2bddcd385ad013c2c98358eca5d4dc", "put", argString, gasPrice, gasLimit, wif)
if err != nil {
log.Printf("Error creating invocation transaction: %s", err)
t.Fail()
Expand Down

0 comments on commit d773808

Please sign in to comment.