From 3462f7bea94d2bbd1f605d66fe1fcc339268da91 Mon Sep 17 00:00:00 2001 From: Wyatt Mufson Date: Sun, 27 Jan 2019 18:14:02 -0800 Subject: [PATCH 1/3] Add build invocation and invoke for ontology --- neoutils/ont.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/neoutils/ont.go b/neoutils/ont.go index 182d742..c40289f 100644 --- a/neoutils/ont.go +++ b/neoutils/ont.go @@ -34,3 +34,26 @@ 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) + if err != nil { + return "", err + } + + return raw, nil +} + +func OntologyInvoke(endpoint string, 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) + if err != nil { + return "", err + } + + txid, err := ontmobile.SendRawTransaction(endpoint, raw) + if err != nil { + return "", err + } + + return txid, nil +} From 564d02c17cb249cfd39dda1c1e32e941823f155f Mon Sep 17 00:00:00 2001 From: Wyatt Mufson Date: Sun, 27 Jan 2019 18:39:56 -0800 Subject: [PATCH 2/3] Added functioning tests for ontology build and invoke --- neoutils/ont.go | 13 +++++++++- neoutils/ont_test.go | 60 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/neoutils/ont.go b/neoutils/ont.go index c40289f..6858d41 100644 --- a/neoutils/ont.go +++ b/neoutils/ont.go @@ -44,7 +44,7 @@ func BuildOntologyInvocationTransaction(contractHex string, operation string, ar return raw, nil } -func OntologyInvoke(endpoint string, contractHex string, operation string, args []ontmobile.Parameter, gasPrice uint, gasLimit uint, wif string) (string, error) { +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) if err != nil { return "", err @@ -57,3 +57,14 @@ func OntologyInvoke(endpoint string, contractHex string, operation string, args return txid, nil } + +type Parameter = ontmobile.Parameter +type ParameterType = ontmobile.ParameterType + +const ( + Address ParameterType = 0 + String ParameterType = 1 + Integer ParameterType = 2 + Fixed8 ParameterType = 3 + Array ParameterType = 4 +) diff --git a/neoutils/ont_test.go b/neoutils/ont_test.go index 3f4f898..47abdbd 100644 --- a/neoutils/ont_test.go +++ b/neoutils/ont_test.go @@ -34,6 +34,10 @@ func TestONTTransfer(t *testing.T) { func TestClaimONG(t *testing.T) { endpoint := "http://dappnode2.ont.io:20336" wif, _ := neoutils.NEP2Decrypt("", "") + if wif == "" { + log.Printf("No wif") + return + } gasPrice := int(500) gasLimit := int(20000) @@ -44,3 +48,59 @@ func TestClaimONG(t *testing.T) { } log.Printf("tx id =%v", txid) } + +func TestBuildOntologyInvocation(t *testing.T) { + wif := "" + if wif == "" { + log.Printf("No wif") + return + } + + account, _ := neoutils.GenerateFromWIF(wif) + address := account.Address + + addr := neoutils.Parameter{neoutils.Address, address} + val := neoutils.Parameter{neoutils.String, "Hi there"} + + args := []neoutils.Parameter{addr, val} + + gasPrice := uint(500) + gasLimit := uint(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) + } +} + +func TestOntologyInvoke(t *testing.T) { + wif := "" + if wif == "" { + log.Printf("No wif") + return + } + + account, _ := neoutils.GenerateFromWIF(wif) + address := account.Address + + addr := neoutils.Parameter{neoutils.Address, address} + val := neoutils.Parameter{neoutils.String, "Hi there"} + + args := []neoutils.Parameter{addr, val} + + gasPrice := uint(500) + gasLimit := uint(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 { + log.Printf("tx id = %s", txid) + } +} From 5a487103e033f42a353c41abed5f09214d6485ed Mon Sep 17 00:00:00 2001 From: Wyatt Mufson Date: Sun, 27 Jan 2019 18:42:35 -0800 Subject: [PATCH 3/3] Set parameter types to the ones defined in ontmobile --- neoutils/ont.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/neoutils/ont.go b/neoutils/ont.go index 6858d41..bd9a610 100644 --- a/neoutils/ont.go +++ b/neoutils/ont.go @@ -62,9 +62,9 @@ type Parameter = ontmobile.Parameter type ParameterType = ontmobile.ParameterType const ( - Address ParameterType = 0 - String ParameterType = 1 - Integer ParameterType = 2 - Fixed8 ParameterType = 3 - Array ParameterType = 4 + Address = ontmobile.Address + String = ontmobile.String + Integer = ontmobile.Integer + Fixed8 = ontmobile.Fixed8 + Array = ontmobile.Array )