mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 13:41:37 +00:00
Merge pull request #1533 from nspcc-dev/examples/itoa
examples: add an example of binary.Itoa usage
This commit is contained in:
commit
a5b6598024
2 changed files with 6 additions and 27 deletions
|
@ -25,6 +25,7 @@ func newApp() *cli.App {
|
|||
ctl.Name = "neo-go"
|
||||
ctl.Version = config.Version
|
||||
ctl.Usage = "Official Go client for Neo"
|
||||
ctl.ErrWriter = os.Stdout
|
||||
|
||||
ctl.Commands = append(ctl.Commands, server.NewCommands()...)
|
||||
ctl.Commands = append(ctl.Commands, smartcontract.NewCommands()...)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package timer
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/binary"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/engine"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||
|
@ -31,7 +32,8 @@ func _deploy(isUpdate bool) {
|
|||
return
|
||||
}
|
||||
storage.Put(ctx, ticksKey, defaultTicks)
|
||||
runtime.Log("Timer set to " + itoa(defaultTicks) + " ticks.")
|
||||
i := binary.Itoa(defaultTicks, 10)
|
||||
runtime.Log("Timer set to " + i + " ticks.")
|
||||
}
|
||||
|
||||
// Migrate migrates the contract.
|
||||
|
@ -55,7 +57,8 @@ func Tick() bool {
|
|||
return engine.AppCall(runtime.GetExecutingScriptHash(), "selfDestroy").(bool)
|
||||
}
|
||||
storage.Put(ctx, ticksKey, ticksLeft)
|
||||
runtime.Log(itoa(ticksLeft.(int)) + " ticks left.")
|
||||
i := binary.Itoa(ticksLeft.(int), 10)
|
||||
runtime.Log(i + " ticks left.")
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -69,28 +72,3 @@ func SelfDestroy() bool {
|
|||
runtime.Log("Destroyed.")
|
||||
return true
|
||||
}
|
||||
|
||||
// itoa converts int to string
|
||||
func itoa(i int) string {
|
||||
digits := "0123456789"
|
||||
var (
|
||||
res string
|
||||
isNegative bool
|
||||
)
|
||||
if i < 0 {
|
||||
i = -i
|
||||
isNegative = true
|
||||
}
|
||||
for {
|
||||
r := i % 10
|
||||
res = digits[r:r+1] + res
|
||||
i = i / 10
|
||||
if i == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if isNegative {
|
||||
res = "-" + res
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue