Skip to content

Commit

Permalink
Merge branch 'master' into illia-malachyn/763-refactor-code-duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-malachyn authored Nov 4, 2024
2 parents 00c810a + e84608b commit e2f4c9d
Show file tree
Hide file tree
Showing 28 changed files with 624 additions and 237 deletions.
2 changes: 1 addition & 1 deletion access/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func (h *httpHandler) getExecutionResults(
u := h.mustBuildURL("/execution_results", opts...)

q := u.Query()
q.Add("block_ids", strings.Join(blockIDs, ","))
q.Add("block_id", strings.Join(blockIDs, ","))
u.RawQuery = q.Encode()

var results []models.ExecutionResult
Expand Down
2 changes: 1 addition & 1 deletion access/http/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ func TestHandler_GetExecResult(t *testing.T) {

u, _ := url.Parse("/execution_results")
q := u.Query()
q.Add("block_ids", strings.Join(ids, ","))
q.Add("block_id", strings.Join(ids, ","))
u.RawQuery = q.Encode()

req.SetData(*u, fixture)
Expand Down
24 changes: 20 additions & 4 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: all
all: get-blocks get-accounts get-events get-collection get-network-parameters get-transactions execute-script send-transaction create-account add-account-key deploy-contract storage-usage transaction-arguments single-party single-party-multisig multi-party multi-party-multisig user-signature user-signature-validate-all user-signature-validate-any http-grpc-clients modify-account
all: get-blocks get-accounts get-events get-collection get-network-parameters get-transactions execute-script send-transactions create-account add-account-key deploy-contract storage-usage transaction-arguments single-party single-party-multisig multi-party multi-party-multisig user-signature user-signature-validate-all user-signature-validate-any http-grpc-clients modify-account get-execution-data

.PHONY: create-account
create-account:
Expand Down Expand Up @@ -47,7 +47,7 @@ multi-party-multisig:

.PHONY: user-signature
user-signature:
go run ./user_signature/main.go
go run ./verify_signature/user_signature/main.go

.PHONY: get-blocks
get-blocks:
Expand Down Expand Up @@ -77,8 +77,8 @@ get-transactions:
execute-script:
go run ./execute_script/main.go

.PHONY: send-transaction
send-transaction:
.PHONY: send-transactions
send-transactions:
go run ./send_transactions/main.go

.PHONY: user-signature-validate-all
Expand All @@ -96,3 +96,19 @@ http-grpc-clients:
.PHONY: modify-account
modify-account:
go run ./modify_account/main.go

.PHONY: get-execution-data
get-execution-data:
go run ./get_execution_data/main.go

.PHONY: stream-events
stream-events:
go run ./stream_events/main.go

.PHONY: stream-events-reconnect
stream-events-reconnect:
go run ./stream_events_reconnect/main.go

.PHONY: stream-execution-data
stream-execution-data:
go run ./stream_execution_data/main.go
4 changes: 2 additions & 2 deletions examples/deploy_contract/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func GenerateMintScript(nftCodeAddr flow.Address) []byte {
import GreatToken from 0x%s
transaction {
prepare(acct: auth(Storage) &Account) {
prepare(acct: auth(Storage, Capabilities) &Account) {
let minter = acct.storage.borrow<&GreatToken.GreatNFTMinter>(from: /storage/GreatNFTMinter)!
if let nft <- acct.storage.load<@GreatToken.GreatNFT>(from: /storage/GreatNFT) {
destroy nft
Expand All @@ -236,7 +236,7 @@ func GenerateGetNFTIDScript(nftCodeAddr, userAddr flow.Address) []byte {
template := `
import GreatToken from 0x%s
pub fun main(): Int {
access(all) fun main(): Int {
let acct = getAccount(0x%s)
let nft = acct.capabilities.borrow<&GreatToken.GreatNFT>(/public/GreatNFT)!
return nft.id()
Expand Down
6 changes: 3 additions & 3 deletions examples/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"time"

jsoncdc "github.com/onflow/cadence/encoding/json"
"github.com/onflow/flow-cli/flowkit/config"
"github.com/onflow/flowkit/config"
"github.com/spf13/afero"

"github.com/onflow/flow-go-sdk"
Expand All @@ -38,7 +38,7 @@ import (
"github.com/onflow/flow-go-sdk/templates"

"github.com/onflow/cadence"
"github.com/onflow/flow-cli/flowkit/config/json"
"github.com/onflow/flowkit/config/json"

"github.com/onflow/cadence/sema"
)
Expand Down Expand Up @@ -110,7 +110,7 @@ func RandomTransaction(flowClient access.Client) *flow.Transaction {
tx := flow.NewTransaction().
SetPayer(serviceAcctAddr).
SetProposalKey(serviceAcctAddr, serviceAcctKey.Index, serviceAcctKey.SequenceNumber).
SetScript([]byte("transaction { prepare(auth: AuthAccount) {} }")).
SetScript([]byte("transaction { prepare(signer: auth(Storage) &Account) {} }")).
AddAuthorizer(serviceAcctAddr).
SetReferenceBlockID(GetReferenceBlockId(flowClient))

Expand Down
38 changes: 26 additions & 12 deletions examples/execute_script/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package main

import (
"context"
"errors"
"fmt"

"github.com/onflow/flow-go-sdk/access/http"
Expand All @@ -41,7 +42,7 @@ func demo() {
examples.Handle(err)

script := []byte(`
pub fun main(a: Int): Int {
access(all) fun main(a: Int): Int {
return a + 10
}
`)
Expand All @@ -52,10 +53,10 @@ func demo() {
fmt.Printf("\nValue: %s", value.String())

complexScript := []byte(`
pub struct User {
pub var balance: UFix64
pub var address: Address
pub var name: String
access(all) struct User {
access(all) var balance: UFix64
access(all) var address: Address
access(all) var name: String
init(name: String, address: Address, balance: UFix64) {
self.name = name
Expand All @@ -64,7 +65,7 @@ func demo() {
}
}
pub fun main(name: String): User {
access(all) fun main(name: String): User {
return User(
name: name,
address: 0x1,
Expand All @@ -78,7 +79,7 @@ func demo() {
}

type User struct {
balance uint64
balance string
address flow.Address
name string
}
Expand All @@ -88,15 +89,28 @@ func printComplexScript(value cadence.Value, err error) {
fmt.Printf("\nString value: %s", value.String())

s := value.(cadence.Struct)
balanceCdc, ok := s.FieldsMappedByName()["balance"].(cadence.UFix64)
if !ok {
examples.Handle(errors.New("incorrect balance"))
}
addressCdc, ok := s.FieldsMappedByName()["address"].(cadence.Address)
if !ok {
examples.Handle(errors.New("incorrect address"))
}
nameCdc, ok := s.FieldsMappedByName()["name"].(cadence.String)
if !ok {
examples.Handle(errors.New("incorrect name"))
}

u := User{
balance: s.Fields[0].ToGoValue().(uint64),
address: s.Fields[1].ToGoValue().([flow.AddressLength]byte),
name: s.Fields[2].ToGoValue().(string),
balance: balanceCdc.String(),
address: flow.BytesToAddress(addressCdc.Bytes()),
name: nameCdc.String(),
}

fmt.Printf("\nName: %s", u.name)
fmt.Printf("\nAddress: %s", u.address.String())
fmt.Printf("\nBalance: %d", u.balance)
fmt.Printf("\nAddress: 0x%s", u.address.String())
fmt.Printf("\nBalance: %s", u.balance)
}

func prepareDemo() {
Expand Down
30 changes: 25 additions & 5 deletions examples/flow.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,31 @@
}
},
"contracts": {
"FlowServiceAccount": "f8d6e0586b0a20c7",
"FlowFees": "e5a8b7f23e8b548f",
"FlowStorageFees": "f8d6e0586b0a20c7",
"FlowToken": "0ae53cb6e3f42a79",
"FungibleToken": "ee82856bf20e2aa6"
"FlowServiceAccount": {
"aliases": {
"emulator": "f8d6e0586b0a20c7"
}
},
"FlowFees": {
"aliases": {
"emulator": "e5a8b7f23e8b548f"
}
},
"FlowStorageFees": {
"aliases": {
"emulator": "f8d6e0586b0a20c7"
}
},
"FlowToken": {
"aliases": {
"emulator": "0ae53cb6e3f42a79"
}
},
"FungibleToken": {
"aliases": {
"emulator": "ee82856bf20e2aa6"
}
}
},
"networks": {
"emulator": "127.0.0.1:3569",
Expand Down
8 changes: 4 additions & 4 deletions examples/get_events/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ func preapreDemo() (*flow.Account, *flow.Transaction) {

// Deploy a contract with an event defined
contract := `
pub contract EventDemo {
pub event Add(x: Int, y: Int, sum: Int)
access(all) contract EventDemo {
access(all) event Add(x: Int, y: Int, sum: Int)
pub fun add(x: Int, y: Int) {
access(all) fun add(x: Int, y: Int) {
let sum = x + y
emit Add(x: x, y: y, sum: sum)
}
Expand All @@ -105,7 +105,7 @@ func preapreDemo() (*flow.Account, *flow.Transaction) {
import EventDemo from 0x%s
transaction {
prepare(auth: AuthAccount) {}
prepare(signer: auth(Storage) &Account) {}
execute {
EventDemo.add(x: 2, y: 3)
}
Expand Down
5 changes: 2 additions & 3 deletions examples/get_execution_data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ func main() {

func demo() {
ctx := context.Background()
flowClient, err := grpc.NewClient("access-003.devnet46.nodes.onflow.org:9000")
flowClient, err := grpc.NewClient(grpc.TestnetHost)
examples.Handle(err)

// block, err := flowClient.GetLatestBlock(ctx, true)
block, err := flowClient.GetBlockByID(ctx, flow.HexToID("7582cc6e1bb5ca1784e309ca63013e9b7ecf34b74bf7fdb029aa0faa0deb7958err"))
block, err := flowClient.GetLatestBlock(ctx, true)
examples.Handle(err)
fmt.Printf("Block Height: %d\n", block.Height)
fmt.Printf("Block ID: %s\n", block.ID)
Expand Down
70 changes: 57 additions & 13 deletions examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ toolchain go1.22.4
replace github.com/onflow/flow-go-sdk => ../

require (
github.com/onflow/cadence v1.2.1
github.com/onflow/flow-cli/flowkit v1.11.0
github.com/onflow/flow-go-sdk v0.41.17
github.com/onflow/cadence v1.2.2
github.com/onflow/flow-go-sdk v1.2.2
github.com/onflow/flowkit v1.19.0
github.com/spf13/afero v1.11.0
google.golang.org/grpc v1.63.2
)
Expand All @@ -19,51 +19,93 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/kms v1.15.7 // indirect
github.com/SaveTheRbtz/mph v0.1.1-0.20240117162131-4166ec7869bc // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/ethereum/go-ethereum v1.13.5 // indirect
github.com/ethereum/go-ethereum v1.13.10 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fxamacker/cbor/v2 v2.4.1-0.20230228173756-c0c9f774e40c // indirect
github.com/fxamacker/circlehash v0.3.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/uint256 v1.3.0 // indirect
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/jsonschema v0.7.0 // indirect
github.com/k0kubun/pp/v3 v3.2.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/k0kubun/pp v3.0.1+incompatible // indirect
github.com/kevinburke/go-bindata v3.24.0+incompatible // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/logrusorgru/aurora/v4 v4.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-multibase v0.2.0 // indirect
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/onflow/atree v0.8.0 // indirect
github.com/onflow/crypto v0.25.1 // indirect
github.com/onflow/crypto v0.25.2 // indirect
github.com/onflow/flow-core-contracts/lib/go/templates v1.4.0 // indirect
github.com/onflow/flow-ft/lib/go/templates v1.0.1 // indirect
github.com/onflow/flow-go v0.38.0-preview.0.0.20241022154145-6a254edbec23 // indirect
github.com/onflow/flow-nft/lib/go/templates v1.2.1 // indirect
github.com/onflow/flow/protobuf/go/flow v0.4.7 // indirect
github.com/onflow/go-ethereum v1.14.7 // indirect
github.com/onflow/sdks v0.6.0-preview.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/psiemens/sconfig v0.1.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/texttheater/golang-levenshtein/levenshtein v0.0.0-20200805054039-cae8b0eaed6c // indirect
github.com/turbolent/prettier v0.0.0-20220320183459-661cc755135d // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v4 v4.3.11 // indirect
github.com/vmihailenco/tagparser v0.1.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/zeebo/blake3 v0.2.3 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/goleak v1.3.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
gonum.org/v1/gonum v0.14.0 // indirect
Expand All @@ -73,5 +115,7 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.3.0 // indirect
)
Loading

0 comments on commit e2f4c9d

Please sign in to comment.