Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(stdlibs): remove Hash, GetTimestamp, FormatTimestamp from std #657

Merged
merged 3 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/gno.land/p/demo/groups/vote_set.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package groups

import (
"std"
"time"

"gno.land/p/demo/maths"
)
Expand Down Expand Up @@ -94,8 +95,8 @@ type VoteSession struct {
Name string
Creator std.Address
Body string
Start std.Time
Deadline std.Time
Start time.Time
Deadline time.Time
Status SessionStatus
Committee *Committee
Votes VoteSet
Expand Down
48 changes: 0 additions & 48 deletions gnovm/pkg/gnolang/hash_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gnolang

import (
"crypto/sha256"
"encoding/binary"
"encoding/hex"
)

Expand Down Expand Up @@ -56,50 +55,3 @@ func HashBytes(bz []byte) (res Hashlet) {
copy(res[:], hash[:HashSize])
return
}

func leafHash(bz []byte) (res Hashlet) {
buf := make([]byte, 1+len(bz))
buf[0] = 0x00
copy(buf[1:], bz)
res = HashBytes(buf)
return
}

func innerHash(h1, h2 Hashlet) (res Hashlet) {
buf := make([]byte, 1+HashSize*2)
buf[0] = 0x01
copy(buf[1:1+HashSize], h1[:])
copy(buf[1+HashSize:], h2[:])
res = HashBytes(buf)
return
}

//----------------------------------------
// misc

func varintBytes(u int64) []byte {
var buf [10]byte
n := binary.PutVarint(buf[:], u)
return buf[0:n]
}

func sizedBytes(bz []byte) []byte {
bz2 := make([]byte, len(bz)+10)
n := binary.PutVarint(bz2[:10], int64(len(bz)))
copy(bz2[n:n+len(bz)], bz)
return bz2[:n+len(bz)]
}

func isASCIIText(bz []byte) bool {
if len(bz) == 0 {
return false
}
for _, b := range bz {
if 32 <= b && b <= 126 {
// good
} else {
return false
}
}
return true
}
14 changes: 0 additions & 14 deletions gnovm/stdlibs/std/time.gno

This file was deleted.

57 changes: 0 additions & 57 deletions gnovm/stdlibs/stdlibs.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,30 +170,6 @@ func InjectPackage(store gno.Store, pn *gno.PackageNode) {
m.PushValue(res0)
},
)
pn.DefineNative("Hash",
gno.Flds( // params
"bz", "[]byte",
),
gno.Flds( // results
"hash", "[20]byte",
),
func(m *gno.Machine) {
arg0 := m.LastBlock().GetParams1().TV
bz := []byte(nil)
if arg0.V != nil {
slice := arg0.V.(*gno.SliceValue)
array := slice.GetBase(m.Store)
bz = array.GetReadonlyBytes()
}
hash := gno.HashBytes(bz)
res0 := gno.Go2GnoValue(
m.Alloc,
m.Store,
reflect.ValueOf([20]byte(hash)),
)
m.PushValue(res0)
},
)
pn.DefineNative("CurrentRealmPath",
gno.Flds( // params
),
Expand Down Expand Up @@ -379,39 +355,6 @@ func InjectPackage(store gno.Store, pn *gno.PackageNode) {
m.PushValue(res0)
},
)
// XXX DEPRECATED, use stdlibs/time instead
pn.DefineNative("GetTimestamp",
gno.Flds( // params
),
gno.Flds( // results
"", "Time",
),
func(m *gno.Machine) {
ctx := m.Context.(ExecContext)
res0 := typedInt64(ctx.Timestamp)
timeT := store.GetType(gno.DeclaredTypeID("std", "Time"))
res0.T = timeT
m.PushValue(res0)
},
)
pn.DefineNative("FormatTimestamp",
gno.Flds( // params
"timestamp", "Time",
"format", "string",
),
gno.Flds( // results
"", "string",
),
func(m *gno.Machine) {
arg0, arg1 := m.LastBlock().GetParams2()
timestamp := arg0.TV.GetInt64()
format := arg1.TV.GetString()
t := time.Unix(timestamp, 0).Round(0).UTC()
result := t.Format(format)
res0 := typedString(m.Alloc.NewString(result))
m.PushValue(res0)
},
)
pn.DefineNative("EncodeBech32",
gno.Flds( // params
"prefix", "string",
Expand Down
10 changes: 0 additions & 10 deletions gnovm/stdlibs/stdshim/stdshim.gno
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@ func GetBanker(bankerType BankerType) Banker {
return nil
}

func GetTimestamp() Time {
panic(shimWarn)
return 0
}

func FormatTimestamp(timestamp Time, format string) string {
panic(shimWarn)
return ""
}

func EncodeBech32(prefix string, bytes [20]byte) (addr Address) {
panic(shimWarn)
return ""
Expand Down
14 changes: 0 additions & 14 deletions gnovm/stdlibs/stdshim/time.gno

This file was deleted.

12 changes: 0 additions & 12 deletions gnovm/tests/files/std1.gno

This file was deleted.