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

Commit

Permalink
Merge pull request #41 from O3Labs/ont-mobile-fix
Browse files Browse the repository at this point in the history
Migrate from parameter array argument to json string
  • Loading branch information
Wyatt Mufson authored Jan 29, 2019
2 parents 5094c6e + cab3b8c commit 8ae0bc3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
output/
.DS_Store
20 changes: 5 additions & 15 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(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
}

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
}
Expand All @@ -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
)
68 changes: 41 additions & 27 deletions neoutils/ont_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package neoutils_test

import (
"encoding/json"
"log"
"math"
"testing"

"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++ {
Expand Down Expand Up @@ -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 := &parameterJSONArrayForm{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) {
Expand All @@ -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 := &parameterJSONArrayForm{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)
}
}
}

0 comments on commit 8ae0bc3

Please sign in to comment.