diff --git a/.gitignore b/.gitignore index ea1472e..8e00c45 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ output/ +.DS_Store diff --git a/neoutils/ont.go b/neoutils/ont.go index bd9a610..190bfb6 100644 --- a/neoutils/ont.go +++ b/neoutils/ont.go @@ -35,8 +35,8 @@ 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(contract string, method string, args string, gasPrice int, gasLimit int, wif string) (string, error) { + raw, err := ontmobile.BuildInvocationTransaction(contract, method, args, uint(gasPrice), uint(gasLimit), wif) if err != nil { return "", err } @@ -44,8 +44,9 @@ func BuildOntologyInvocationTransaction(contractHex string, operation string, ar 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, contract string, method string, args string, gasPrice int, gasLimit int, wif string) (string, error) { + raw, err := ontmobile.BuildInvocationTransaction(contract, method, args, uint(gasPrice), uint(gasLimit), wif) if err != nil { return "", err } @@ -57,14 +58,3 @@ func OntologyInvoke(endpoint string, contractHex string, operation string, args return txid, nil } - -type Parameter = ontmobile.Parameter -type ParameterType = ontmobile.ParameterType - -const ( - Address = ontmobile.Address - String = ontmobile.String - Integer = ontmobile.Integer - Fixed8 = ontmobile.Fixed8 - Array = ontmobile.Array -) diff --git a/neoutils/ont_test.go b/neoutils/ont_test.go index 47abdbd..5a82068 100644 --- a/neoutils/ont_test.go +++ b/neoutils/ont_test.go @@ -1,6 +1,7 @@ package neoutils_test import ( + "encoding/json" "log" "math" "testing" @@ -8,6 +9,15 @@ import ( "github.com/o3labs/neo-utils/neoutils" ) +type parameterJSONArrayForm struct { + A []parameterJSONForm `json:"array"` +} + +type parameterJSONForm struct { + T string `json:"type"` + V interface{} `json:"value"` +} + func TestONTTransfer(t *testing.T) { for i := 1; i <= 100; i++ { @@ -56,24 +66,26 @@ func TestBuildOntologyInvocation(t *testing.T) { return } - account, _ := neoutils.GenerateFromWIF(wif) - address := account.Address + account, _ := neoutils.GenerateFromWIF(wif) + address := account.Address - addr := neoutils.Parameter{neoutils.Address, address} - val := neoutils.Parameter{neoutils.String, "Hi there"} + addr := parameterJSONForm{T: "Address", V: address} + val := parameterJSONForm{T: "String", V: "Hi there"} - args := []neoutils.Parameter{addr, val} + jsondat := ¶meterJSONArrayForm{A: []parameterJSONForm{addr, val}} + argData, _ := json.Marshal(jsondat) + argString := string(argData) - gasPrice := uint(500) - gasLimit := uint(20000) + gasPrice := int(500) + gasLimit := int(20000) - txData, err := neoutils.BuildOntologyInvocationTransaction("c168e0fb1a2bddcd385ad013c2c98358eca5d4dc", "put", args, gasPrice, gasLimit, wif) - if err != nil { - log.Printf("Error creating invocation transaction: %s", err) - t.Fail() - } else { - log.Printf("Raw transaction: %s", txData) - } + txData, err := neoutils.BuildOntologyInvocationTransaction("c168e0fb1a2bddcd385ad013c2c98358eca5d4dc", "put", argString, gasPrice, gasLimit, wif) + if err != nil { + log.Printf("Error creating invocation transaction: %s", err) + t.Fail() + } else { + log.Printf("Raw transaction: %s", txData) + } } func TestOntologyInvoke(t *testing.T) { @@ -83,24 +95,26 @@ func TestOntologyInvoke(t *testing.T) { return } - account, _ := neoutils.GenerateFromWIF(wif) - address := account.Address + account, _ := neoutils.GenerateFromWIF(wif) + address := account.Address - addr := neoutils.Parameter{neoutils.Address, address} - val := neoutils.Parameter{neoutils.String, "Hi there"} + addr := parameterJSONForm{T: "Address", V: address} + val := parameterJSONForm{T: "String", V: "Hi there"} - args := []neoutils.Parameter{addr, val} + jsondat := ¶meterJSONArrayForm{A: []parameterJSONForm{addr, val}} + argData, _ := json.Marshal(jsondat) + argString := string(argData) - gasPrice := uint(500) - gasLimit := uint(20000) + gasPrice := int(500) + gasLimit := int(20000) endpoint := "http://polaris2.ont.io:20336" - txid, err := neoutils.OntologyInvoke(endpoint, "c168e0fb1a2bddcd385ad013c2c98358eca5d4dc", "put", args, gasPrice, gasLimit, wif) - if err != nil { - log.Printf("Error creating invocation transaction: %s", err) - t.Fail() - } else { + txid, err := neoutils.OntologyInvoke(endpoint, "c168e0fb1a2bddcd385ad013c2c98358eca5d4dc", "put", argString, gasPrice, gasLimit, wif) + if err != nil { + log.Printf("Error creating invocation transaction: %s", err) + t.Fail() + } else { log.Printf("tx id = %s", txid) - } + } }