-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMakefile
More file actions
144 lines (128 loc) · 6.46 KB
/
Copy pathMakefile
File metadata and controls
144 lines (128 loc) · 6.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Configure environment constants
ACCOUNT_KEYS_FILENAME = "./account-keys.csv"
FLOW_JSON = script/flow.json
FLOW_JSON_NETWORK = localnet
FLOW_JSON_SIGNER = localnet-service-account
FLOW_CLI_FLAGS = -n $(FLOW_JSON_NETWORK) -f $(FLOW_JSON) --signer $(FLOW_JSON_SIGNER)
ROSETTA_ENV = localnet
ROSETTA_HOST_URL = "http://127.0.0.1:8080"
COMPILER_FLAGS := CGO_CFLAGS="-O2 -D__BLST_PORTABLE__"
.PHONY: all build
all: build
.PHONY: go-build
go-build:
${COMPILER_FLAGS} go build -o server cmd/server/server.go
.PHONY: go-test
go-test:
go test -v github.com/onflow/rosetta/state/...
go test -v github.com/onflow/rosetta/script/...
# Compile (but don't run) the build-tagged localnet test so it can't rot.
go test -tags localnet -run '^$$' github.com/onflow/rosetta/localnettest/...
# End-to-end localnet compatibility test (script/README.md). Requires a flow-go
# localnet up at 127.0.0.1:4001, the flow CLI, jq, and python3 with click +
# requests; skips cleanly if any are absent. Build-tagged out of go-test.
.PHONY: localnet-test
localnet-test:
go test -tags localnet -v -timeout 20m github.com/onflow/rosetta/localnettest/...
.PHONY: gen-originator-account
gen-originator-account:
KEYS=$$(go run ./cmd/genkey/genkey.go -csv); \
PUBLIC_FLOW_KEY=$$(echo $$KEYS | cut -d',' -f1); \
PUBLIC_ROSETTA_KEY=$$(echo $$KEYS | cut -d',' -f2); \
PRIVATE_KEY=$$(echo $$KEYS | cut -d',' -f3); \
echo "Created keys:"; \
echo "Flow Key: $$PUBLIC_FLOW_KEY"; \
echo "Rosetta Key: $$PUBLIC_ROSETTA_KEY"; \
echo "Private Key: $$PRIVATE_KEY"; \
address=$$(flow accounts create --sig-algo ECDSA_secp256k1 --key $$PUBLIC_FLOW_KEY $(FLOW_CLI_FLAGS) | grep "Address" | cut -d' ' -f2 | cut -c3-);\
echo "Address created: $$address"; \
jq --arg account_name "$(ACCOUNT_NAME)" --arg address "$$address" --arg private_key "$$PRIVATE_KEY" \
'.accounts[$$account_name] = {address: $$address, key: {type: "hex", index: 0, signatureAlgorithm: "ECDSA_secp256k1", hashAlgorithm: "SHA3_256", privateKey: $$private_key}}' \
"${FLOW_JSON}" > flow.json.tmp && mv flow.json.tmp "${FLOW_JSON}" || { echo "Failed to update ${FLOW_JSON} with jq"; exit 1; }; \
jq --arg address "$$address" '.originators += [$$address]' "${ROSETTA_ENV}.json" > env.json.tmp && mv env.json.tmp "${ROSETTA_ENV}.json"; \
echo "$(ACCOUNT_NAME),$$KEYS,0x$$address" >> $(ACCOUNT_KEYS_FILENAME); \
echo "Updated $(FLOW_JSON), $(ROSETTA_ENV).json and $(ACCOUNT_KEYS_FILENAME)";
.PHONY: fund-accounts
fund-accounts:
while IFS=',' read -r col1 col2 col3 col4 address; do \
address=$$(echo $$address | xargs); \
echo "Seeding account with address: $$address"; \
flow transactions send script/cadence/transactions/basic-transfer.cdc $$address 100.0 $(FLOW_CLI_FLAGS); \
done < account-keys.csv
.PHONY: create-originator-derived-account
create-originator-derived-account:
KEYS=$$(go run ./cmd/genkey/genkey.go -csv); \
NEW_ACCOUNT_PUBLIC_FLOW_KEY=$$(echo $$KEYS | cut -d',' -f1); \
NEW_ACCOUNT_PUBLIC_ROSETTA_KEY=$$(echo $$KEYS | cut -d',' -f2); \
NEW_ACCOUNT_PRIVATE_KEY=$$(echo $$KEYS | cut -d',' -f3); \
echo "Created keys for $(NEW_ACCOUNT_NAME)"; \
echo "Flow Key: $$NEW_ACCOUNT_PUBLIC_FLOW_KEY"; \
echo "Rosetta Key: $$NEW_ACCOUNT_PUBLIC_ROSETTA_KEY"; \
echo "Private Key: $$NEW_ACCOUNT_PRIVATE_KEY"; \
ROOT_ORIGINATOR_PUBLIC_KEY=$$(grep '$(ORIGINATOR_NAME)' $(ACCOUNT_KEYS_FILENAME) | cut -d ',' -f2); \
ROOT_ORIGINATOR_PRIVATE_KEY=$$(grep '$(ORIGINATOR_NAME)' $(ACCOUNT_KEYS_FILENAME) | cut -d ',' -f4 ); \
ROOT_ORIGINATOR_ADDRESS=$$(grep '$(ORIGINATOR_NAME)' $(ACCOUNT_KEYS_FILENAME) | cut -d ',' -f5); \
echo "Originator address: $$ROOT_ORIGINATOR_ADDRESS"; \
TX_HASH=$$(python3 rosetta_handler.py rosetta-create-derived-account $(ROSETTA_HOST_URL) $$ROOT_ORIGINATOR_ADDRESS $$ROOT_ORIGINATOR_PUBLIC_KEY $$ROOT_ORIGINATOR_PRIVATE_KEY $$NEW_ACCOUNT_PUBLIC_ROSETTA_KEY) && \
ADDRESS=$$(flow transactions get $$TX_HASH -f $(FLOW_JSON) -n $(ROSETTA_ENV) -o json | jq -r '.events[] | select(.type == "flow.AccountCreated") | .values.value.fields[] | select(.name == "address") | .value.value') && \
echo "TX_HASH: $$TX_HASH , ADDRESS: $$ADDRESS" && \
echo "$(NEW_ACCOUNT_NAME),$$NEW_ACCOUNT_PUBLIC_FLOW_KEY,$$NEW_ACCOUNT_PUBLIC_ROSETTA_KEY,$$NEW_ACCOUNT_PRIVATE_KEY,$$ADDRESS" >> $(ACCOUNT_KEYS_FILENAME);
.PHONY: rosetta-transfer-funds
rosetta-transfer-funds:
PAYER_PUBLIC_KEY=$$(grep '$(PAYER_NAME)' $(ACCOUNT_KEYS_FILENAME) | cut -d ',' -f2); \
PAYER_PRIVATE_KEY=$$(grep '$(PAYER_NAME)' $(ACCOUNT_KEYS_FILENAME) | cut -d ',' -f4 ); \
PAYER_ADDRESS=$$(grep '$(PAYER_NAME)' $(ACCOUNT_KEYS_FILENAME) | cut -d ',' -f5); \
echo "Payer address: $$PAYER_ADDRESS"; \
RECIPIENT_ADDRESS=$$(grep '$(RECIPIENT_NAME)' $(ACCOUNT_KEYS_FILENAME) | cut -d ',' -f5); \
echo "Recipient address: $$RECIPIENT_ADDRESS"; \
TX_HASH=$$(python3 rosetta_handler.py rosetta-transfer-funds $(ROSETTA_HOST_URL) $$PAYER_ADDRESS $$PAYER_PUBLIC_KEY $$PAYER_PRIVATE_KEY $$RECIPIENT_ADDRESS $$AMOUNT) && \
echo "Funding sent: $$TX_HASH";
# Use this target to verify that the accounts configured in the Rosetta environment JSON have the specified contracts deployed
.PHONY: verify-configured-contract-addresses
verify-configured-contract-addresses:
EXPECTED_CONTRACTS=$$(jq -r '.contracts | to_entries | map("\(.key | gsub("_";""))=\(.value)") | .[]' $(ROSETTA_ENV).json); \
for contract in $$EXPECTED_CONTRACTS; do \
KEY=$$(echo $$contract | cut -d= -f1); \
VALUE=$$(echo $$contract | cut -d= -f2); \
if [ "$$VALUE" = "0000000000000000" ]; then \
continue; \
fi; \
CONTRACTS_FOUND=$$(flow accounts get $$VALUE -f $(FLOW_JSON) -n $(ROSETTA_ENV) -o json | \
jq -r '.contracts | join(",") '); \
found=false ; \
for contract in $$(echo $$CONTRACTS_FOUND | tr ',' ' '); do \
lowercase_contract_name=$$(echo $$contract | tr '[:upper:]' '[:lower:]'); \
if [ "$$KEY" = "$$lowercase_contract_name" ]; then \
found=true ; \
break; \
fi; \
done; \
if [ "$$found" = "false" ]; then \
echo "Contract $$KEY configured in $(ROSETTA_ENV).json is not deployed to configured address $$VALUE" ;\
fi; \
done ;
.PHONY: build
build: go-test go-build
.PHONY: deps
deps:
go mod download -x
.PHONY: fix-lint
fix-lint:
golangci-lint run -v --fix ./...
.PHONY: lint
lint:
@go mod tidy
@staticcheck ./...
.PHONY: proto
proto:
@echo ">> Generating model/model.pb.go"
@protoc --proto_path=model --go_out=model \
--go_opt=paths=source_relative model/model.proto
.PHONY: test-reset
test-reset:
rm -rf data
.PHONY: test-cleanup
test-cleanup: test-reset
rm -f flow.json
rm -f account-keys.csv
rm -rf flow-go