Skip to content

Commit 22f4cab

Browse files
Prep for release (#24)
* Added EventRemarked and CallFulfillcall * Added FetchKeysPaged for block storage * Added Transaction State RPC
1 parent 3bd218a commit 22f4cab

File tree

16 files changed

+261
-40
lines changed

16 files changed

+261
-40
lines changed

documentation/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@
3232
- [RPC](./rpc.md)
3333
- [Validator](./validator.md)
3434
- [Proxy](./proxy.md)
35+
- [Transaction State](./transaction_state.md)

documentation/src/installation.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ go version
2525
#### To Existing Project
2626

2727
```bash
28-
# Fetches Avail-GO SDK v0.2.3. This might not be the newest version so make sure to check out the latest github avail-go-sdk release.
28+
# Fetches Avail-GO SDK v0.2.4. This might not be the newest version so make sure to check out the latest github avail-go-sdk release.
2929
# Link to Github: https://github.com/availproject/avail-go-sdk/releases
30-
go get github.com/availproject/[email protected].3
30+
go get github.com/availproject/[email protected].4
3131
```
3232

3333
#### To A New Project
3434

3535
```bash
3636
# Creates a new project with name myproject
3737
go mod init myproject
38-
# Fetches Avail-GO SDK v0.2.3. 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.4. 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].3
40+
go get github.com/availproject/[email protected].4
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.3
3+
This Documentation is based upon avail-go version v0.2.4
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Transaction State
2+
3+
```go
4+
{{#include ./../../examples/transaction_state.go}}
5+
```

examples/mod.go

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func Run() {
1212
RunTransaction()
1313
RunValidator()
1414
RunProxy()
15+
RunTransactionState()
1516
}
1617

1718
func AssertTrue(v bool, message string) {

examples/transaction_state.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package examples
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
"github.com/availproject/avail-go-sdk/metadata"
8+
SDK "github.com/availproject/avail-go-sdk/sdk"
9+
)
10+
11+
func RunTransactionState() {
12+
sdk, err := SDK.NewSDK(SDK.LocalEndpoint)
13+
PanicOnError(err)
14+
15+
// Transaction will be signed, and sent.
16+
//
17+
// There is no guarantee that the transaction was executed at all. It might have been
18+
// dropped or discarded for various reasons. The caller is responsible for querying future
19+
// blocks in order to determine the execution status of that transaction.
20+
tx := sdk.Tx.DataAvailability.SubmitData([]byte("MyData"))
21+
txHash, err := tx.Execute(SDK.Account.Alice(), SDK.NewTransactionOptions().WithAppId(1))
22+
PanicOnError(err)
23+
fmt.Println("Tx Hash:", txHash)
24+
25+
details := []metadata.TransactionState{}
26+
for {
27+
details, err = sdk.Client.TransactionState(txHash, false)
28+
PanicOnError(err)
29+
if len(details) != 0 {
30+
break
31+
}
32+
33+
time.Sleep(time.Second)
34+
}
35+
AssertEq(len(details), 1, "")
36+
detail := details[0]
37+
fmt.Println(fmt.Sprintf(`Block Hash: %v, Block Height: %v, Tx Hash: %v, Tx Index: %v`, detail.BlockHash.ToHuman(), detail.BlockHeight, detail.TxHash.ToHuman(), detail.TxIndex))
38+
fmt.Println(fmt.Sprintf(`Pallet Index: %v, Call Index: %v, Tx Success: %v, Is Finalized: %v`, detail.PalletIndex, detail.CallIndex, detail.TxSuccess, detail.IsFinalized))
39+
40+
fmt.Println("RunTransactionState finished correctly.")
41+
}

interfaces/mod.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type EventT interface {
1010
}
1111

1212
type BlockStorageT interface {
13-
Fetch(storageEntryKey string) (primitives.Option[string], error)
13+
Fetch(key string) (primitives.Option[string], error)
1414
FetchKeys(key string) ([]string, error)
15+
FetchKeysPaged(key string, count uint32, startKey primitives.Option[string]) ([]string, error)
1516
}

metadata/pallets/nomination_pools/calls.go

-7
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,6 @@ func (this CallWithdrawUnbonded) CallName() string {
217217
// - `amount` - The amount of funds to delegate to the pool. This also acts of a sort of
218218
// deposit since the pools creator cannot fully unbond funds until the pool is being
219219
// destroyed.
220-
// - `index` - A disambiguation index for creating the account. Likely only useful when
221-
// creating multiple pools in the same extrinsic.
222220
// - `root` - The account to set as [`PoolRoles::root`].
223221
// - `nominator` - The account to set as the [`PoolRoles::nominator`].
224222
// - `bouncer` - The account to set as the [`PoolRoles::bouncer`].
@@ -458,11 +456,6 @@ func (this CallBondExtraOther) CallName() string {
458456
// claim their pending rewards. If a pool member wishes so, they can set this to
459457
// `PermissionlessAll` to allow any account to claim their rewards and bond extra to the
460458
// pool.
461-
//
462-
// # Arguments
463-
//
464-
// * `origin` - Member of a pool.
465-
// * `actor` - Account to claim reward. // improve this
466459
type CallSetClaimPermission struct {
467460
Permission metadata.PoolClaimPermission
468461
}

metadata/pallets/system/events.go

+22
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,25 @@ func (this EventKilledAccount) EventIndex() uint8 {
8989
func (this EventKilledAccount) EventName() string {
9090
return "KilledAccount"
9191
}
92+
93+
// On on-chain remark happened
94+
type EventRemarked struct {
95+
Sender primitives.AccountId
96+
Hash primitives.H256
97+
}
98+
99+
func (this EventRemarked) PalletIndex() uint8 {
100+
return PalletIndex
101+
}
102+
103+
func (this EventRemarked) PalletName() string {
104+
return PalletName
105+
}
106+
107+
func (this EventRemarked) EventIndex() uint8 {
108+
return 5
109+
}
110+
111+
func (this EventRemarked) EventName() string {
112+
return "Remarked"
113+
}

metadata/pallets/vector/calls.go

+24-13
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,33 @@ package vector
22

33
import (
44
"github.com/availproject/avail-go-sdk/metadata"
5-
. "github.com/availproject/avail-go-sdk/metadata/pallets"
65
prim "github.com/availproject/avail-go-sdk/primitives"
76
)
87

8+
type CallFulfillCall struct {
9+
FunctionId prim.H256
10+
Input []byte
11+
output []byte
12+
proof []byte
13+
slot uint64 `scale:"compact"`
14+
}
15+
16+
func (this CallFulfillCall) PalletIndex() uint8 {
17+
return PalletIndex
18+
}
19+
20+
func (this CallFulfillCall) PalletName() string {
21+
return PalletName
22+
}
23+
24+
func (this CallFulfillCall) CallIndex() uint8 {
25+
return 0
26+
}
27+
28+
func (this CallFulfillCall) CallName() string {
29+
return "fulfill_call"
30+
}
31+
932
// Send a batch of dispatch calls.
1033
//
1134
// May be called from any origin except `None`.
@@ -30,15 +53,3 @@ func (this CallSendMessage) CallIndex() uint8 {
3053
func (this CallSendMessage) CallName() string {
3154
return "send_message"
3255
}
33-
34-
func (this *CallSendMessage) ToCall() prim.Call {
35-
return ToCall(this)
36-
}
37-
38-
func (this *CallSendMessage) ToPayload() metadata.Payload {
39-
return ToPayload(this)
40-
}
41-
42-
func (this *CallSendMessage) DecodeExtrinsic(tx *prim.DecodedExtrinsic) bool {
43-
return Decode(this, tx)
44-
}

metadata/types.go

+11
Original file line numberDiff line numberDiff line change
@@ -1629,3 +1629,14 @@ func (this *ProxyType) Decode(decoder *prim.Decoder) error {
16291629

16301630
return nil
16311631
}
1632+
1633+
type TransactionState struct {
1634+
BlockHash prim.H256
1635+
BlockHeight uint32
1636+
TxHash prim.H256
1637+
TxIndex uint32
1638+
TxSuccess bool
1639+
PalletIndex uint8
1640+
CallIndex uint8
1641+
IsFinalized bool
1642+
}

sdk/client.go

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ func (this *Client) FinalizedBlockHash() (prim.H256, error) {
6666
return this.Rpc.Chain.GetFinalizedHead()
6767
}
6868

69+
func (this *Client) TransactionState(txHash prim.H256, finalized bool) ([]meta.TransactionState, error) {
70+
return this.Rpc.Transaction.State(txHash, finalized)
71+
}
72+
6973
func (this *Client) EventsAt(at prim.Option[prim.H256]) (EventRecords, error) {
7074
eventsRaw, err := this.Rpc.State.GetEvents(at)
7175
if err != nil {

sdk/rpc.go

+24-14
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,26 @@ import (
88
)
99

1010
type RPC struct {
11-
client *Client
12-
System systemRPC
13-
State stateRPC
14-
Chain chainRPC
15-
ChainSpec chainSpecRPC
16-
Kate kateRPC
17-
Author authorRPC
11+
client *Client
12+
System systemRPC
13+
State stateRPC
14+
Chain chainRPC
15+
ChainSpec chainSpecRPC
16+
Kate kateRPC
17+
Author authorRPC
18+
Transaction transactionRPC
1819
}
1920

2021
func newRPC(client *Client) RPC {
2122
return RPC{
22-
client: client,
23-
System: systemRPC{client: client},
24-
State: stateRPC{client: client},
25-
Chain: chainRPC{client: client},
26-
ChainSpec: chainSpecRPC{client: client},
27-
Kate: kateRPC{client: client},
28-
Author: authorRPC{client: client},
23+
client: client,
24+
System: systemRPC{client: client},
25+
State: stateRPC{client: client},
26+
Chain: chainRPC{client: client},
27+
ChainSpec: chainSpecRPC{client: client},
28+
Kate: kateRPC{client: client},
29+
Author: authorRPC{client: client},
30+
Transaction: transactionRPC{client: client},
2931
}
3032
}
3133

@@ -37,6 +39,14 @@ func (this *RPCParams) Add(value string) {
3739
this.Values = append(this.Values, value)
3840
}
3941

42+
func (this *RPCParams) AddBool(value bool) {
43+
if value == true {
44+
this.Add("true")
45+
} else {
46+
this.Add("false")
47+
}
48+
}
49+
4050
func (this *RPCParams) AddByteSlice(value []byte) {
4151
if len(value) == 0 {
4252
return

sdk/rpc_state.go

+28
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package sdk
22

33
import (
44
"encoding/json"
5+
"fmt"
6+
57
prim "github.com/availproject/avail-go-sdk/primitives"
68
)
79

@@ -53,6 +55,32 @@ func (this *stateRPC) GetKeys(key string, at prim.Option[prim.H256]) ([]string,
5355
return res, nil
5456
}
5557

58+
func (this *stateRPC) GetKeysPaged(key string, count uint32, startKey prim.Option[string], at prim.Option[prim.H256]) ([]string, error) {
59+
params := RPCParams{}
60+
params.Add("\"" + key + "\"")
61+
params.Add(fmt.Sprintf(`%v`, count))
62+
if startKey.IsSome() {
63+
params.Add("\"" + startKey.Unwrap() + "\"")
64+
} else {
65+
params.Add("null")
66+
}
67+
if at.IsSome() {
68+
params.AddH256(at.Unwrap())
69+
}
70+
71+
value, err := this.client.RequestWithRetry("state_getKeysPaged", params.Build())
72+
if err != nil {
73+
return nil, err
74+
}
75+
76+
res := []string{}
77+
if err := json.Unmarshal([]byte(value), &res); err != nil {
78+
return nil, newError(err, ErrorCode002)
79+
}
80+
81+
return res, nil
82+
}
83+
5684
func (this *stateRPC) GetMetadata(at prim.Option[prim.H256]) (string, error) {
5785
params := RPCParams{}
5886
if at.IsSome() {

0 commit comments

Comments
 (0)