Skip to content

Commit

Permalink
Merge branch 'feat/airdrop' of https://github.com/irreverentsimplicit…
Browse files Browse the repository at this point in the history
…y/gno into feat/airdrop
  • Loading branch information
irreverentsimplicity committed Aug 23, 2024
2 parents 889791b + 2f04c37 commit ce9c360
Show file tree
Hide file tree
Showing 43 changed files with 1,439 additions and 124 deletions.
47 changes: 24 additions & 23 deletions contribs/gnofaucet/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.22
toolchain go1.22.4

require (
github.com/gnolang/faucet v0.2.1
github.com/gnolang/gno v0.1.0-nightly.20240627
github.com/gnolang/faucet v0.3.1
github.com/gnolang/gno v0.1.1
github.com/stretchr/testify v1.9.0
go.uber.org/zap v1.27.0
golang.org/x/time v0.5.0
Expand All @@ -19,37 +19,38 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216 // indirect
github.com/go-chi/chi/v5 v5.0.12 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-chi/chi/v5 v5.1.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/peterbourgon/ff/v3 v3.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/cors v1.11.0 // indirect
github.com/rs/xid v1.5.0 // indirect
go.opentelemetry.io/otel v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.26.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
go.opentelemetry.io/otel/sdk v1.27.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.27.0 // indirect
go.opentelemetry.io/otel/trace v1.27.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/sdk v1.28.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap/exp v0.2.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
94 changes: 48 additions & 46 deletions contribs/gnofaucet/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/stdlibs/std/chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Returns the original signer of the transaction.

#### Usage
```go
caller := std.GetOrigSend()
caller := std.GetOrigCaller()
```
---

Expand Down
89 changes: 89 additions & 0 deletions examples/gno.land/p/demo/entropy/entropy.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Entropy generates fully deterministic, cost-effective, and hard to guess
// numbers.
//
// It is designed both for single-usage, like seeding math/rand or for being
// reused which increases the entropy and its cost effectiveness.
//
// Disclaimer: this package is unsafe and won't prevent others to guess values
// in advance.
//
// It uses the Bernstein's hash djb2 to be CPU-cycle efficient.
package entropy

import (
"math"
"std"
"time"
)

type Instance struct {
value uint32
}

func New() *Instance {
r := Instance{value: 5381}
r.addEntropy()
return &r
}

func FromSeed(seed uint32) *Instance {
r := Instance{value: seed}
r.addEntropy()
return &r
}

func (i *Instance) Seed() uint32 {
return i.value
}

func (i *Instance) djb2String(input string) {
for _, c := range input {
i.djb2Uint32(uint32(c))
}
}

// super fast random algorithm.
// http://www.cse.yorku.ca/~oz/hash.html
func (i *Instance) djb2Uint32(input uint32) {
i.value = (i.value << 5) + i.value + input
}

// AddEntropy uses various runtime variables to add entropy to the existing seed.
func (i *Instance) addEntropy() {
// FIXME: reapply the 5381 initial value?

// inherit previous entropy
// nothing to do

// handle callers
{
caller1 := std.GetCallerAt(1).String()
i.djb2String(caller1)
caller2 := std.GetCallerAt(2).String()
i.djb2String(caller2)
}

// height
{
height := std.GetHeight()
if height >= math.MaxUint32 {
height -= math.MaxUint32
}
i.djb2Uint32(uint32(height))
}

// time
{
secs := time.Now().Second()
i.djb2Uint32(uint32(secs))
nsecs := time.Now().Nanosecond()
i.djb2Uint32(uint32(nsecs))
}

// FIXME: compute other hard-to-guess but deterministic variables, like real gas?
}

func (i *Instance) Value() uint32 {
i.addEntropy()
return i.value
}
Loading

0 comments on commit ce9c360

Please sign in to comment.