Skip to content

Commit e8b4fe6

Browse files
Prep for release (#22)
* Added one more proxy example. Changed to finalized block hash for fork hash * Added missing balance transfer to sdk * Added new Watcher and new Logger abstraction * Added retrty mechanism to rpc calls * Updated docs * Updated Readme * Updated documentation
1 parent 801dff8 commit e8b4fe6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+560
-383
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ To enable logging add this to the `main` function.
1717
// Set log level based on the environment variable
1818
level, err := logrus.ParseLevel(os.Getenv("LOG_LEVEL"))
1919
if err != nil {
20-
level = logrus.InfoLevel // Default to INFO if parsing fails
20+
level = logrus.DebugLevel // Default to Debug if parsing fails
2121
}
2222
logrus.SetLevel(level)
2323
logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true})

documentation/src/SUMMARY.md

+10-11
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@
99
- [Balance](./account_balance.md)
1010
- [Enum](./enum.md)
1111
- [Block](./block.md)
12-
- [All Transaction](block_transaction_all.md)
13-
- [Transaction Filtered by App Id](block_transaction_by_app_id.md)
14-
- [Transaction Filtered by Tx Hash](block_transaction_by_hash.md)
15-
- [Transaction Filtered by Tx Index](block_transaction_by_index.md)
16-
- [Transaction Filtered by Tx Signer](block_transaction_by_signer.md)
17-
- [All Data Submission](block_data_submission_all.md)
18-
- [Data Submission Filtered by App Id](block_data_submission_by_app_id.md)
19-
- [Data Submission Filtered by Tx Hash](block_data_submission_by_hash.md)
20-
- [Data Submission Filtered by Tx Index](block_data_submission_by_index.md)
21-
- [Data Submission Filtered by Signer](block_data_submission_by_signer.md)
12+
- [All Transactions](block_transaction_all.md)
13+
- [Transactions Filtered by App Id](block_transaction_by_app_id.md)
14+
- [Transactions Filtered by Tx Hash](block_transaction_by_hash.md)
15+
- [Transactions Filtered by Tx Index](block_transaction_by_index.md)
16+
- [Transactions Filtered by Tx Signer](block_transaction_by_signer.md)
17+
- [All Data Submissions](block_data_submission_all.md)
18+
- [Data Submissions Filtered by App Id](block_data_submission_by_app_id.md)
19+
- [Data Submissions Filtered by Tx Hash](block_data_submission_by_hash.md)
20+
- [Data Submissions Filtered by Tx Index](block_data_submission_by_index.md)
21+
- [Data Submissions Filtered by Signer](block_data_submission_by_signer.md)
2222
- [Block Events](block_events.md)
2323
- [Transaction](./transaction.md)
2424
- [Execute](./transaction_execute.md)
25-
- [Execute And Watch](./transaction_execute_and_watch.md)
2625
- [Execute And Watch Inclusion](./transaction_execute_and_watch_inclusion.md)
2726
- [Execute And Watch Finalization](./transaction_execute_and_watch_finalization.md)
2827
- [Options](./transaction_options.md)

documentation/src/block_data_submission_all.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# All Block Data Submission
1+
# All Block Data Submissions
22

33
```go
44
{{#include ./../../examples/block_data_submission_all.go}}

documentation/src/block_data_submission_by_app_id.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Block Data Submission Filtered By App Id
1+
# Block Data Submissions Filtered By App Id
22

33
```go
44
{{#include ./../../examples/block_data_submission_by_app_id.go}}

documentation/src/block_data_submission_by_hash.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Block Data Submission Filtered By Transaction Hash
1+
# Block Data Submissions Filtered By Transaction Hash
22

33
```go
44
{{#include ./../../examples/block_data_submission_by_hash.go}}

documentation/src/block_data_submission_by_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Block Data Submission Filtered By Transaction Index
1+
# Block Data Submissions Filtered By Transaction Index
22

33
```go
44
{{#include ./../../examples/block_data_submission_by_index.go}}

documentation/src/block_data_submission_by_signer.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Block Data Submission Filtered By Signer
1+
# Block Data Submissions Filtered By Signer
22

33
```go
44
{{#include ./../../examples/block_data_submission_by_signer.go}}

documentation/src/block_transaction_all.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# All Block Transaction
1+
# All Block Transactions
22

33
```go
44
{{#include ./../../examples/block_transaction_all.go}}

documentation/src/block_transaction_by_app_id.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Block Transaction Filtered By App Id
1+
# Block Transactions Filtered By App Id
22

33
```go
44
{{#include ./../../examples/block_transaction_by_app_id.go}}

documentation/src/block_transaction_by_hash.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Block Transaction Filtered By Transaction Hash
1+
# Block Transactions Filtered By Transaction Hash
22

33
```go
44
{{#include ./../../examples/block_transaction_by_hash.go}}

documentation/src/block_transaction_by_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Block Transaction Filtered By Transaction Index
1+
# Block Transactions Filtered By Transaction Index
22

33
```go
44
{{#include ./../../examples/block_transaction_by_index.go}}

documentation/src/block_transaction_by_signer.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Block Transaction Filtered By Signer
1+
# Block Transactions Filtered By Signer
22

33
```go
44
{{#include ./../../examples/block_transaction_by_signer.go}}

documentation/src/installation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ go get github.com/availproject/[email protected]
3535
```bash
3636
# Creates a new project with name myproject
3737
go mod init myproject
38-
# Fetches Avail-GO SDK v0.2.0-rc5. This might not be the newest version so make sure to check out the latest github avail-go-sdk release.
38+
# Fetches Avail-GO SDK v0.2.0. This might not be the newest version so make sure to check out the latest github avail-go-sdk release.
3939
# Link to Github: https://github.com/availproject/avail-go-sdk/releases
40-
go get github.com/availproject/[email protected]-rc5
40+
go get github.com/availproject/[email protected]
4141
```
4242

4343
#### First Time Running

documentation/src/start.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# SDK Version
22

3-
This Documentation is based upon avail-go version v0.2.0-rc7
3+
This Documentation is based upon avail-go version v0.2.0

documentation/src/transaction_execute_and_watch.md

-5
This file was deleted.

examples/account_balance.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func RunAccountBalance() {
1616
PanicOnError(err)
1717

1818
// Via Storage RPC
19-
storageAt, err := sdk.Client.StorageAt(primitives.NewNone[primitives.H256]())
19+
storageAt, err := sdk.Client.StorageAt(primitives.None[primitives.H256]())
2020
PanicOnError(err)
2121

2222
storage := syPallet.StorageAccount{}

examples/batch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func RunBatch() {
144144
tx := sdk.Tx.Utility.BatchAll(callsToExecute)
145145
res, err := tx.ExecuteAndWatchInclusion(acc, SDK.NewTransactionOptions().WithAppId(0))
146146
PanicOnError(err)
147-
AssertEq(res.IsSuccessful(), prim.NewSome(false), "Transaction is supposed to fail")
147+
AssertEq(res.IsSuccessful(), prim.Some(false), "Transaction is supposed to fail")
148148

149149
fmt.Println("Batch All call done")
150150
}

examples/block_events.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func RunBlockEvents() {
5555

5656
// Printout All Tx Events
5757
for _, ev := range txEvents {
58-
AssertEq(ev.TxIndex(), prim.NewSome(txIndex), "Tx Index is not the same")
58+
AssertEq(ev.TxIndex(), prim.Some(txIndex), "Tx Index is not the same")
5959
fmt.Println(fmt.Sprintf(`Pallet Name: %v, Pallet Index: %v, Event Name: %v, Event Index: %v, Event Position: %v, Tx Index: %v`, ev.PalletName, ev.PalletIndex, ev.EventName, ev.EventIndex, ev.Position, ev.TxIndex()))
6060
}
6161

examples/proxy.go

+53-18
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ import (
1414
)
1515

1616
func RunProxy() {
17-
RunNormalProxy()
18-
RunPureProxy()
17+
RunProxyNormal()
18+
RunProxyPure()
19+
RunProxyFailure()
1920

2021
fmt.Println("RunProxy finished correctly.")
2122
}
2223

23-
func RunNormalProxy() {
24+
func RunProxyNormal() {
2425
sdk, err := SDK.NewSDK(SDK.LocalEndpoint)
2526
PanicOnError(err)
2627

@@ -36,41 +37,39 @@ func RunNormalProxy() {
3637
PanicOnError(err)
3738
AssertTrue(res.IsSuccessful().UnsafeUnwrap(), "Transaction has to succeed")
3839

39-
// Finding the Proxy Added Event
40+
// Finding the ProxyAdded Event
4041
eventMyb := SDK.EventFindFirst(res.Events.UnsafeUnwrap(), pxPallet.EventProxyAdded{})
4142
event := eventMyb.UnsafeUnwrap().UnsafeUnwrap()
4243
fmt.Println(fmt.Sprintf(`Delegatee: %v, Delegator %v, ProxyTpe %v, Delay: %v`, event.Delegatee.ToHuman(), event.Delegator.ToHuman(), event.ProxyTpe.ToHuman(), event.Delay))
4344

44-
call := pallets.ToCall(baPallet.CallTransferKeepAlive{Dest: proxyAccountMulti, Value: SDK.OneAvail()})
45-
4645
// Executing the Proxy.Proxy() call
47-
tx = sdk.Tx.Proxy.Proxy(mainAccountMulti, primitives.NewNone[metadata.ProxyType](), call)
46+
call := pallets.ToCall(baPallet.CallTransferKeepAlive{Dest: proxyAccountMulti, Value: SDK.OneAvail()})
47+
tx = sdk.Tx.Proxy.Proxy(mainAccountMulti, primitives.None[metadata.ProxyType](), call)
4848
res, err = tx.ExecuteAndWatchInclusion(proxyAccount, SDK.NewTransactionOptions())
4949
PanicOnError(err)
5050
AssertTrue(res.IsSuccessful().UnsafeUnwrap(), "Transaction has to succeed")
5151

52-
// Checking for EventProxyExecuted event.
52+
// Finding ProxyExecuted event.
5353
event2Myb := SDK.EventFindFirst(res.Events.UnsafeUnwrap(), pxPallet.EventProxyExecuted{})
5454
event2 := event2Myb.UnsafeUnwrap().UnsafeUnwrap()
55-
AssertEq(event2.Result.VariantIndex, 0, "Event must OK")
56-
fmt.Println(fmt.Sprintf(`Dispatch Result: %v`, event2.Result.ToString()))
55+
AssertEq(event2.Result.VariantIndex, 0, "Proxy must be successful")
5756

5857
// Removing Proxy
5958
tx = sdk.Tx.Proxy.RemoveProxy(proxyAccountMulti, proxyType, 0)
6059
res, err = tx.ExecuteAndWatchInclusion(mainAccount, SDK.NewTransactionOptions())
6160
PanicOnError(err)
6261
AssertTrue(res.IsSuccessful().UnsafeUnwrap(), "Transaction has to succeed")
6362

64-
// Checking for EventProxyExecuted event.
63+
// Finding for EventProxyRemoved event.
6564
event3Myb := SDK.EventFindFirst(res.Events.UnsafeUnwrap(), pxPallet.EventProxyRemoved{})
6665
event3 := event3Myb.UnsafeUnwrap().UnsafeUnwrap()
6766
AssertEq(event2.Result.VariantIndex, 0, "Event must OK")
6867
fmt.Println(fmt.Sprintf(`Delegatee: %v, Delegator %v, ProxyTpe %v, Delay: %v`, event3.Delegatee.ToHuman(), event3.Delegator.ToHuman(), event3.ProxyTpe.ToHuman(), event3.Delay))
6968

70-
fmt.Println("RunNormalProxy finished correctly.")
69+
fmt.Println("RunProxyNormal finished correctly.")
7170
}
7271

73-
func RunPureProxy() {
72+
func RunProxyPure() {
7473
sdk, err := SDK.NewSDK(SDK.LocalEndpoint)
7574
PanicOnError(err)
7675

@@ -82,11 +81,9 @@ func RunPureProxy() {
8281
tx := sdk.Tx.Proxy.CreatePure(proxyType, 0, index)
8382
res, err := tx.ExecuteAndWatchInclusion(mainAccount, SDK.NewTransactionOptions())
8483
PanicOnError(err)
85-
8684
AssertTrue(res.IsSuccessful().UnsafeUnwrap(), "Transaction has to succeed")
87-
AssertTrue(res.Events.IsSome(), "Events need to be decodable")
8885

89-
// Finding the Pure Created Event
86+
// Finding PureCreated Event
9087
eventMyb := SDK.EventFindFirst(res.Events.UnsafeUnwrap(), pxPallet.EventPureCreated{})
9188
event := eventMyb.UnsafeUnwrap().UnsafeUnwrap()
9289
fmt.Println(fmt.Sprintf(`Pure: %v, Who %v, ProxyType %v, Index: %v`, event.Pure.ToHuman(), event.Who.ToHuman(), event.ProxyTpe.ToHuman(), event.DisambiguationIndex))
@@ -95,7 +92,7 @@ func RunPureProxy() {
9592
// Executing the Proxy.Proxy() call
9693
key := fmt.Sprintf("MyKey%v", rand.Uint32())
9794
call := pallets.ToCall(daPallet.CallCreateApplicationKey{Key: []byte(key)})
98-
tx = sdk.Tx.Proxy.Proxy(pureProxy.ToMultiAddress(), primitives.NewNone[metadata.ProxyType](), call)
95+
tx = sdk.Tx.Proxy.Proxy(pureProxy.ToMultiAddress(), primitives.None[metadata.ProxyType](), call)
9996
res, err = tx.ExecuteAndWatchInclusion(mainAccount, SDK.NewTransactionOptions())
10097
PanicOnError(err)
10198
AssertTrue(res.IsSuccessful().UnsafeUnwrap(), "Transaction has to succeed")
@@ -106,5 +103,43 @@ func RunPureProxy() {
106103
AssertEq(event2.Result.VariantIndex, 0, "Event must OK")
107104
fmt.Println(fmt.Sprintf(`Dispatch Result: %v`, event2.Result.ToString()))
108105

109-
fmt.Println("RunPureProxy finished correctly.")
106+
fmt.Println("RunProxyPure finished correctly.")
107+
}
108+
109+
func RunProxyFailure() {
110+
sdk, err := SDK.NewSDK(SDK.LocalEndpoint)
111+
PanicOnError(err)
112+
113+
proxyAccount := SDK.Account.Bob()
114+
proxyAccountMulti := primitives.NewAccountIdFromKeyPair(proxyAccount).ToMultiAddress()
115+
mainAccount := SDK.Account.Ferdie()
116+
mainAccountMulti := primitives.NewAccountIdFromKeyPair(mainAccount).ToMultiAddress()
117+
118+
// Creating proxy
119+
proxyType := metadata.ProxyType{VariantIndex: 1} // NonTransfer
120+
tx := sdk.Tx.Proxy.AddProxy(proxyAccountMulti, proxyType, 0)
121+
res, err := tx.ExecuteAndWatchInclusion(mainAccount, SDK.NewTransactionOptions())
122+
PanicOnError(err)
123+
AssertTrue(res.IsSuccessful().UnsafeUnwrap(), "Transaction has to succeed")
124+
125+
// Executing the Proxy.Proxy() call
126+
call := pallets.ToCall(baPallet.CallTransferKeepAlive{Dest: proxyAccountMulti, Value: SDK.OneAvail()})
127+
tx = sdk.Tx.Proxy.Proxy(mainAccountMulti, primitives.None[metadata.ProxyType](), call)
128+
res, err = tx.ExecuteAndWatchInclusion(proxyAccount, SDK.NewTransactionOptions())
129+
PanicOnError(err)
130+
AssertTrue(res.IsSuccessful().UnsafeUnwrap(), "Transaction has to succeed")
131+
132+
// Finding ProxyExecuted event.
133+
event2Myb := SDK.EventFindFirst(res.Events.UnsafeUnwrap(), pxPallet.EventProxyExecuted{})
134+
event2 := event2Myb.UnsafeUnwrap().UnsafeUnwrap()
135+
AssertEq(event2.Result.VariantIndex, 1, "Proxy must fail")
136+
fmt.Println("Failure", event2.Result.Err.UnsafeUnwrap().ToHuman())
137+
138+
// Removing Proxy
139+
tx = sdk.Tx.Proxy.RemoveProxy(proxyAccountMulti, proxyType, 0)
140+
res, err = tx.ExecuteAndWatchInclusion(mainAccount, SDK.NewTransactionOptions())
141+
PanicOnError(err)
142+
AssertTrue(res.IsSuccessful().UnsafeUnwrap(), "Transaction has to succeed")
143+
144+
fmt.Println("RunProxyFailure finished correctly.")
110145
}

examples/rpc.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ func RunRpc() {
1313

1414
{
1515
// chain_GetBlock
16-
value, err := sdk.Client.Rpc.Chain.GetBlock(prim.NewNone[prim.H256]())
16+
value, err := sdk.Client.Rpc.Chain.GetBlock(prim.None[prim.H256]())
1717
PanicOnError(err)
1818
fmt.Println("Block Number:", value.Header.Number)
1919
}
2020

2121
{
2222
// chain_GetBlockHash
23-
value, err := sdk.Client.Rpc.Chain.GetBlockHash(prim.NewNone[uint32]())
23+
value, err := sdk.Client.Rpc.Chain.GetBlockHash(prim.None[uint32]())
2424
PanicOnError(err)
2525
fmt.Println("Block Hash:", value.ToHuman())
2626
}
@@ -34,7 +34,7 @@ func RunRpc() {
3434

3535
{
3636
// chain_GetHeader
37-
value, err := sdk.Client.Rpc.Chain.GetHeader(prim.NewNone[prim.H256]())
37+
value, err := sdk.Client.Rpc.Chain.GetHeader(prim.None[prim.H256]())
3838
PanicOnError(err)
3939
fmt.Println("Block Number:", value.Number)
4040
}

examples/storage.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func RunStorage() {
1717
blockHash, err := prim.NewH256FromHexString("0x9e813bb85fca217f8f3967bd4b550b05f7d559412571ca1dd621aa37343b300b")
1818
PanicOnError(err)
1919

20-
blockStorage, err := sdk.Client.StorageAt(prim.NewSome(blockHash))
20+
blockStorage, err := sdk.Client.StorageAt(prim.Some(blockHash))
2121
PanicOnError(err)
2222

2323
// Simple Storage

examples/transaction.go

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import "fmt"
44

55
func RunTransaction() {
66
RunTransactionExecute()
7-
RunTransactionExecuteAndWatch()
87
RunTransactionExecuteAndWatchFinalization()
98
RunTransactionExecuteAndWatchInclusion()
109
RunTransactionCustom()

examples/transaction_execute.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func RunTransactionExecute() {
2525
//
2626
// It's not necessary to use the builtin watcher. A custom watcher
2727
// might yield better results in some cases.
28-
watcher := SDK.NewWatcher(sdk.Client, txHash, SDK.Inclusion, 3, 3)
28+
watcher := SDK.NewWatcher(sdk.Client, txHash).WaitFor(SDK.Inclusion)
2929
mybTxDetails, err := watcher.Run()
3030
PanicOnError(err)
3131
AssertEq(mybTxDetails.IsSome(), true, "Watcher must have found the status for our transaction")
@@ -40,7 +40,7 @@ func RunTransactionExecute() {
4040
fmt.Println(fmt.Sprintf(`Pallet Name: %v, Pallet Index: %v, Event Name: %v, Event Index: %v, Event Position: %v, Tx Index: %v`, ev.PalletName, ev.PalletIndex, ev.EventName, ev.EventIndex, ev.Position, ev.TxIndex()))
4141
}
4242

43-
// Converts from generic transaction to a specific one
43+
// Converts generic event to a specific one
4444
eventMyb := SDK.EventFindFirst(txEvents, daPallet.EventDataSubmitted{})
4545
event := eventMyb.UnsafeUnwrap().UnsafeUnwrap()
4646
fmt.Println(fmt.Sprintf(`Pallet Name: %v, Event Name: %v, DataHash: %v, Who: %v`, event.PalletName(), event.EventName(), event.DataHash, event.Who.ToHuman()))

examples/transaction_execute_and_watch.go

-47
This file was deleted.

0 commit comments

Comments
 (0)