Skip to content

Commit

Permalink
Merge branch 'main' into kouteki-patch2
Browse files Browse the repository at this point in the history
  • Loading branch information
leohhhn authored Nov 7, 2024
2 parents b448bf9 + 0f67d35 commit 0f08e8e
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 58 deletions.
3 changes: 2 additions & 1 deletion cmd/gnoblog-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package main

import (
"context"
"github.com/gnolang/gno/tm2/pkg/commands"
"os"

"github.com/gnolang/gno/tm2/pkg/commands"
)

func main() {
Expand Down
65 changes: 36 additions & 29 deletions cmd/gnoblog-cli/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import (
"context"
"flag"
"fmt"
"github.com/adrg/frontmatter"
"github.com/gnolang/gno/tm2/pkg/commands"
"io"
"log/slog"
"os"
"strings"
"time"

"github.com/adrg/frontmatter"
"github.com/gnolang/gno/gno.land/pkg/gnoclient"
"github.com/gnolang/gno/gno.land/pkg/sdk/vm"
"github.com/gnolang/gno/gnovm/pkg/gnoenv"
"github.com/gnolang/gno/tm2/pkg/commands"
)

type cliCfg struct {
Expand Down Expand Up @@ -178,7 +179,32 @@ func execPost(io commands.IO, args []string, cfg *cliCfg) error {
}

func post(c gnoclient.Client, cfg *cliCfg, paths ...string) error {
msgs := make([]gnoclient.MsgCall, 0, len(paths))
msgs := make([]vm.MsgCall, 0, len(paths))

// Get account info
account, err := c.Signer.Info()
if err != nil {
return fmt.Errorf("getting signer info failed: %w", err)
}

address := account.GetAddress()

signingAcc, _, err := c.QueryAccount(address)
if err != nil {
return fmt.Errorf("query account %q failed: %w", account, err)
}

nonce := signingAcc.GetSequence()
accNumber := signingAcc.GetAccountNumber()

// Set up base config
baseTxCfg := gnoclient.BaseTxCfg{
GasFee: cfg.GasFee,
GasWanted: cfg.GasWanted,
AccountNumber: accNumber,
SequenceNumber: nonce,
Memo: "Posted from gnoblog-cli",
}

// Save title for printing to cli
var postTitle string
Expand Down Expand Up @@ -220,10 +246,11 @@ func post(c gnoclient.Client, cfg *cliCfg, paths ...string) error {
continue
}

// Pack calls to the chain
callCfg := gnoclient.MsgCall{
PkgPath: cfg.BlogRealmPath,
FuncName: verb,
callMsg := vm.MsgCall{
Caller: address,
Send: nil,
PkgPath: cfg.BlogRealmPath,
Func: verb,
Args: []string{
post.Slug,
post.Title,
Expand All @@ -233,35 +260,15 @@ func post(c gnoclient.Client, cfg *cliCfg, paths ...string) error {
strings.Join(post.Tags, ","),
},
}
msgs = append(msgs, callCfg)

msgs = append(msgs, callMsg)
postTitle = post.Title
}

if len(msgs) == 0 {
return fmt.Errorf("%w, exiting", ErrNoNewOrChangedPosts)
}

account, err := c.Signer.Info()
if err != nil {
return fmt.Errorf("getting signer info failed: %w", err)
}

signingAcc, _, err := c.QueryAccount(account.GetAddress())
if err != nil {
return fmt.Errorf("query account %q failed: %w", account, err)
}

nonce := signingAcc.GetSequence()
accNumber := signingAcc.GetAccountNumber()

baseTxCfg := gnoclient.BaseTxCfg{
GasFee: cfg.GasFee,
GasWanted: cfg.GasWanted,
AccountNumber: accNumber,
SequenceNumber: nonce,
Memo: "Posted from gnoblog-cli",
}

_, err = c.Call(baseTxCfg, msgs...)
if err != nil {
return err
Expand Down
56 changes: 28 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module github.com/gnolang/blog

go 1.22
go 1.22.0

toolchain go1.22.3
toolchain go1.23.3

require (
github.com/adrg/frontmatter v0.2.0
github.com/gnolang/gno v0.1.1
github.com/gnolang/gno v0.2.0
github.com/stretchr/testify v1.9.0
)

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.3 // indirect
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/btcsuite/btcd/btcutil v1.1.6 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
Expand All @@ -25,36 +25,36 @@ require (
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // 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/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/peterbourgon/ff/v3 v3.4.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/rs/xid v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // 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
github.com/zondax/ledger-go v1.0.0 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.31.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect
go.opentelemetry.io/otel/sdk v1.31.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.31.0 // indirect
go.opentelemetry.io/otel/trace v1.31.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/multierr v1.11.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/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
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 0f08e8e

Please sign in to comment.