diff --git a/neoutils/ont.go b/neoutils/ont.go index 182d742..bd9a610 100644 --- a/neoutils/ont.go +++ b/neoutils/ont.go @@ -34,3 +34,37 @@ 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 []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 +} + +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 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) + } +}