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 #40 from O3Labs/ont-invoke
Browse files Browse the repository at this point in the history
Ont invoke
  • Loading branch information
Wyatt Mufson committed Jan 28, 2019
2 parents a4e1a4d + 5a48710 commit 5094c6e
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
34 changes: 34 additions & 0 deletions neoutils/ont.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
60 changes: 60 additions & 0 deletions neoutils/ont_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}

0 comments on commit 5094c6e

Please sign in to comment.