diff --git a/avail-go/examples/README.md b/avail-go/README.md similarity index 99% rename from avail-go/examples/README.md rename to avail-go/README.md index 3738165c3..b79988ff7 100644 --- a/avail-go/examples/README.md +++ b/avail-go/README.md @@ -1,5 +1,7 @@ # Avail Go SDK documentation / examples +We are using [avail-go-sdk](https://github.com/availproject/avail-go-sdk) for running the examples + ## Running Examples in the Docs Directory To run the examples provided in the `/examples` directory, follow these steps: diff --git a/avail-go/examples/balance_allow_death/main.go b/avail-go/examples/balance_allow_death/main.go index 6441264d3..b6d8d69e3 100644 --- a/avail-go/examples/balance_allow_death/main.go +++ b/avail-go/examples/balance_allow_death/main.go @@ -1,12 +1,13 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/tx" - "avail-go-sdk/src/sdk/types" "math" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/tx" + "github.com/availproject/avail-go-sdk/src/sdk/types" + "fmt" ) diff --git a/avail-go/examples/balance_transfer_all/main.go b/avail-go/examples/balance_transfer_all/main.go index 4d74d97ac..cdd2e3beb 100644 --- a/avail-go/examples/balance_transfer_all/main.go +++ b/avail-go/examples/balance_transfer_all/main.go @@ -1,9 +1,9 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/tx" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/tx" "fmt" ) diff --git a/avail-go/examples/balances_keep_alive/main.go b/avail-go/examples/balances_keep_alive/main.go index 561649178..9caad092b 100644 --- a/avail-go/examples/balances_keep_alive/main.go +++ b/avail-go/examples/balances_keep_alive/main.go @@ -1,12 +1,13 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/tx" - "avail-go-sdk/src/sdk/types" "math" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/tx" + "github.com/availproject/avail-go-sdk/src/sdk/types" + "fmt" ) diff --git a/avail-go/examples/connect/main.go b/avail-go/examples/connect/main.go index ccfb67cfe..d816036cb 100644 --- a/avail-go/examples/connect/main.go +++ b/avail-go/examples/connect/main.go @@ -1,9 +1,10 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" "fmt" + + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" ) // The following example shows how to connect to a node and display some basic information. diff --git a/avail-go/examples/da_create_application_key/main.go b/avail-go/examples/da_create_application_key/main.go index 409d6ab6b..168ce8636 100644 --- a/avail-go/examples/da_create_application_key/main.go +++ b/avail-go/examples/da_create_application_key/main.go @@ -1,9 +1,9 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/tx" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/tx" "fmt" ) diff --git a/avail-go/examples/da_data_submit/main.go b/avail-go/examples/da_data_submit/main.go index ddce46a25..2ac9a8475 100644 --- a/avail-go/examples/da_data_submit/main.go +++ b/avail-go/examples/da_data_submit/main.go @@ -1,9 +1,9 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/tx" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/tx" "fmt" ) diff --git a/avail-go/examples/da_data_submit_watch/main.go b/avail-go/examples/da_data_submit_watch/main.go index 7bba15292..d296beaa5 100644 --- a/avail-go/examples/da_data_submit_watch/main.go +++ b/avail-go/examples/da_data_submit_watch/main.go @@ -1,9 +1,9 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/tx" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/tx" "fmt" ) diff --git a/avail-go/examples/da_set_application_key/main.go b/avail-go/examples/da_set_application_key/main.go index 2d5711e35..937cecf71 100644 --- a/avail-go/examples/da_set_application_key/main.go +++ b/avail-go/examples/da_set_application_key/main.go @@ -1,9 +1,9 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/tx" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/tx" "fmt" ) diff --git a/avail-go/examples/da_submit_block_length/main.go b/avail-go/examples/da_submit_block_length/main.go index 577df62e0..7b164670a 100644 --- a/avail-go/examples/da_submit_block_length/main.go +++ b/avail-go/examples/da_submit_block_length/main.go @@ -1,9 +1,9 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/tx" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/tx" "fmt" ) diff --git a/avail-go/examples/da_submit_data_fee_modifier/main.go b/avail-go/examples/da_submit_data_fee_modifier/main.go index 6d1e9bafa..9d8b84a2a 100644 --- a/avail-go/examples/da_submit_data_fee_modifier/main.go +++ b/avail-go/examples/da_submit_data_fee_modifier/main.go @@ -1,11 +1,12 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/tx" "math/big" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/tx" + "fmt" ) diff --git a/avail-go/examples/existential/main.go b/avail-go/examples/existential/main.go index bcba9c889..de10696e7 100644 --- a/avail-go/examples/existential/main.go +++ b/avail-go/examples/existential/main.go @@ -1,9 +1,10 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" "fmt" + + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" ) func main() { diff --git a/avail-go/examples/go.mod b/avail-go/examples/go.mod index 536d7dba4..5712c010a 100644 --- a/avail-go/examples/go.mod +++ b/avail-go/examples/go.mod @@ -1,8 +1,8 @@ -module avail-go-sdk-examples +module examples go 1.21.0 -require avail-go-sdk v0.0.0 +require github.com/availproject/avail-go-sdk v0.1.1 require ( github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect @@ -30,5 +30,3 @@ require ( gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) - -replace avail-go-sdk => ../../avail-go diff --git a/avail-go/examples/go.sum b/avail-go/examples/go.sum index 6f9ebbf6a..335866d1b 100644 --- a/avail-go/examples/go.sum +++ b/avail-go/examples/go.sum @@ -2,6 +2,8 @@ github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRr github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= +github.com/availproject/avail-go-sdk v0.1.1 h1:8mo7H4BYVY4hzafhpXHfUgXTImPXdmQuunZKM3/WgnM= +github.com/availproject/avail-go-sdk v0.1.1/go.mod h1:2LX1D4jRJhLAozmUF8Fzrh8FUA0WhjT1VpUykZsUqDM= github.com/btcsuite/btcd v0.22.0-beta h1:LTDpDKUM5EeOFBPM8IXpinEcmZ6FWfNZbE3lfrfdnWo= github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k= github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU= diff --git a/avail-go/examples/listenNewBlocks/main.go b/avail-go/examples/listenNewBlocks/main.go index 264d0b956..8fac06de3 100644 --- a/avail-go/examples/listenNewBlocks/main.go +++ b/avail-go/examples/listenNewBlocks/main.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" ) // The following example shows how to connect to a node and listen for a new blocks diff --git a/avail-go/examples/properties/main.go b/avail-go/examples/properties/main.go index 399d0a56d..eac47d1ee 100644 --- a/avail-go/examples/properties/main.go +++ b/avail-go/examples/properties/main.go @@ -1,10 +1,11 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/types" "fmt" + + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/types" ) func main() { diff --git a/avail-go/examples/rpc/author_rotate/main.go b/avail-go/examples/rpc/author_rotate/main.go index 7de0c6bc6..b8f584b90 100644 --- a/avail-go/examples/rpc/author_rotate/main.go +++ b/avail-go/examples/rpc/author_rotate/main.go @@ -1,11 +1,12 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/call" "fmt" "log" + + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/call" ) func main() { diff --git a/avail-go/examples/rpc/chain_finalizedHead/main.go b/avail-go/examples/rpc/chain_finalizedHead/main.go index 751cd1935..c1286a9c7 100644 --- a/avail-go/examples/rpc/chain_finalizedHead/main.go +++ b/avail-go/examples/rpc/chain_finalizedHead/main.go @@ -1,11 +1,12 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/rpc" - "avail-go-sdk/src/sdk" "fmt" "log" + + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/rpc" + "github.com/availproject/avail-go-sdk/src/sdk" ) func main() { diff --git a/avail-go/examples/rpc/chain_getBlock/main.go b/avail-go/examples/rpc/chain_getBlock/main.go index fda587803..229f19e5c 100644 --- a/avail-go/examples/rpc/chain_getBlock/main.go +++ b/avail-go/examples/rpc/chain_getBlock/main.go @@ -1,11 +1,12 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/rpc" - "avail-go-sdk/src/sdk" "fmt" "log" + + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/rpc" + "github.com/availproject/avail-go-sdk/src/sdk" ) func main() { diff --git a/avail-go/examples/rpc/chain_getBlockHash/main.go b/avail-go/examples/rpc/chain_getBlockHash/main.go index 8175d46a9..7c13e88f8 100644 --- a/avail-go/examples/rpc/chain_getBlockHash/main.go +++ b/avail-go/examples/rpc/chain_getBlockHash/main.go @@ -1,11 +1,12 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/rpc" - "avail-go-sdk/src/sdk" "fmt" "log" + + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/rpc" + "github.com/availproject/avail-go-sdk/src/sdk" ) func main() { diff --git a/avail-go/examples/rpc/chain_getHeader/main.go b/avail-go/examples/rpc/chain_getHeader/main.go index ad61997fa..3e99605a3 100644 --- a/avail-go/examples/rpc/chain_getHeader/main.go +++ b/avail-go/examples/rpc/chain_getHeader/main.go @@ -1,11 +1,12 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/rpc" - "avail-go-sdk/src/sdk" "fmt" "log" + + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/rpc" + "github.com/availproject/avail-go-sdk/src/sdk" ) func main() { diff --git a/avail-go/examples/rpc/kate_queryProof/main.go b/avail-go/examples/rpc/kate_queryProof/main.go index 4a4acea22..fb4c73563 100644 --- a/avail-go/examples/rpc/kate_queryProof/main.go +++ b/avail-go/examples/rpc/kate_queryProof/main.go @@ -1,14 +1,15 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/rpc" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/call" - "avail-go-sdk/src/sdk/tx" "encoding/json" "fmt" "log" + + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/rpc" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/call" + "github.com/availproject/avail-go-sdk/src/sdk/tx" ) func main() { diff --git a/avail-go/examples/rpc/kate_queryProofData/main.go b/avail-go/examples/rpc/kate_queryProofData/main.go index f5376df7e..27d0de2f2 100644 --- a/avail-go/examples/rpc/kate_queryProofData/main.go +++ b/avail-go/examples/rpc/kate_queryProofData/main.go @@ -4,11 +4,11 @@ import ( "fmt" "log" - "avail-go-sdk/src/config" - "avail-go-sdk/src/rpc" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/call" - "avail-go-sdk/src/sdk/tx" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/rpc" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/call" + "github.com/availproject/avail-go-sdk/src/sdk/tx" ) func main() { diff --git a/avail-go/examples/rpc/kate_queryRows/main.go b/avail-go/examples/rpc/kate_queryRows/main.go index 243ee2448..f6629248c 100644 --- a/avail-go/examples/rpc/kate_queryRows/main.go +++ b/avail-go/examples/rpc/kate_queryRows/main.go @@ -3,10 +3,10 @@ package main import ( "fmt" - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/call" - "avail-go-sdk/src/sdk/tx" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/call" + "github.com/availproject/avail-go-sdk/src/sdk/tx" ) func main() { diff --git a/avail-go/examples/staking_bond/main.go b/avail-go/examples/staking_bond/main.go index f3a8adf67..648f1c83a 100644 --- a/avail-go/examples/staking_bond/main.go +++ b/avail-go/examples/staking_bond/main.go @@ -1,9 +1,9 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/tx" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/tx" "fmt" ) diff --git a/avail-go/examples/staking_bond_extra/main.go b/avail-go/examples/staking_bond_extra/main.go index 0363f233a..7cc07960c 100644 --- a/avail-go/examples/staking_bond_extra/main.go +++ b/avail-go/examples/staking_bond_extra/main.go @@ -1,9 +1,9 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/tx" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/tx" "fmt" ) diff --git a/avail-go/examples/staking_chill/main.go b/avail-go/examples/staking_chill/main.go index 0f3127019..a426869b2 100644 --- a/avail-go/examples/staking_chill/main.go +++ b/avail-go/examples/staking_chill/main.go @@ -1,9 +1,9 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/tx" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/tx" "fmt" ) diff --git a/avail-go/examples/staking_chill_other/main.go b/avail-go/examples/staking_chill_other/main.go index 5aebeed25..45b60ff41 100644 --- a/avail-go/examples/staking_chill_other/main.go +++ b/avail-go/examples/staking_chill_other/main.go @@ -1,9 +1,9 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/tx" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/tx" "fmt" ) diff --git a/avail-go/examples/staking_nominate/main.go b/avail-go/examples/staking_nominate/main.go index b6ddeb254..6aae38043 100644 --- a/avail-go/examples/staking_nominate/main.go +++ b/avail-go/examples/staking_nominate/main.go @@ -1,9 +1,9 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/tx" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/tx" "fmt" ) diff --git a/avail-go/examples/staking_unbond/main.go b/avail-go/examples/staking_unbond/main.go index a739caa17..abbb9bd6e 100644 --- a/avail-go/examples/staking_unbond/main.go +++ b/avail-go/examples/staking_unbond/main.go @@ -1,12 +1,13 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/tx" - "avail-go-sdk/src/sdk/types" "math/big" + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/tx" + "github.com/availproject/avail-go-sdk/src/sdk/types" + "fmt" ) diff --git a/avail-go/examples/staking_validate/main.go b/avail-go/examples/staking_validate/main.go index d184e4f8d..acdecb8b4 100644 --- a/avail-go/examples/staking_validate/main.go +++ b/avail-go/examples/staking_validate/main.go @@ -1,10 +1,11 @@ package main import ( - "avail-go-sdk/src/config" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/tx" "fmt" + + "github.com/availproject/avail-go-sdk/src/config" + "github.com/availproject/avail-go-sdk/src/sdk" + "github.com/availproject/avail-go-sdk/src/sdk/tx" ) func main() { diff --git a/avail-go/go.mod b/avail-go/go.mod deleted file mode 100644 index e4dfb0d5d..000000000 --- a/avail-go/go.mod +++ /dev/null @@ -1,35 +0,0 @@ -module avail-go-sdk - -go 1.21.0 - -require ( - github.com/centrifuge/go-substrate-rpc-client/v4 v4.2.1 - github.com/ethereum/go-ethereum v1.10.20 - github.com/vedhavyas/go-subkey v1.0.4 - github.com/vedhavyas/go-subkey/v2 v2.0.0 - golang.org/x/crypto v0.7.0 -) - -require ( - github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect - github.com/cosmos/go-bip39 v1.0.0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/deckarep/golang-set v1.8.0 // indirect - github.com/decred/base58 v1.0.4 // indirect - github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect - github.com/go-stack/stack v1.8.1 // indirect - github.com/gorilla/websocket v1.5.0 // indirect - github.com/gtank/merlin v0.1.1 // indirect - github.com/gtank/ristretto255 v0.1.2 // indirect - github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b // indirect - github.com/pierrec/xxHash v0.1.5 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/rs/cors v1.8.2 // indirect - github.com/stretchr/objx v0.1.1 // indirect - github.com/stretchr/testify v1.7.2 // indirect - golang.org/x/sys v0.6.0 // indirect - gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) - -// replace github.com/centrifuge/go-substrate-rpc-client/v4 => /Users/kailaskr/gsrpc diff --git a/avail-go/go.sum b/avail-go/go.sum deleted file mode 100644 index d5460e81a..000000000 --- a/avail-go/go.sum +++ /dev/null @@ -1,85 +0,0 @@ -github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM= -github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4= -github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8= -github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= -github.com/btcsuite/btcd v0.22.0-beta h1:LTDpDKUM5EeOFBPM8IXpinEcmZ6FWfNZbE3lfrfdnWo= -github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k= -github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU= -github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pYCvA5t0RPmAaLUhREsKuKd+SLhxFbFeQ= -github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o= -github.com/centrifuge/go-substrate-rpc-client/v4 v4.2.1 h1:io49TJ8IOIlzipioJc9pJlrjgdJvqktpUWYxVY5AUjE= -github.com/centrifuge/go-substrate-rpc-client/v4 v4.2.1/go.mod h1:k61SBXqYmnZO4frAJyH3iuqjolYrYsq79r8EstmklDY= -github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= -github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= -github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4= -github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo= -github.com/decred/base58 v1.0.4 h1:QJC6B0E0rXOPA8U/kw2rP+qiRJsUaE2Er+pYb3siUeA= -github.com/decred/base58 v1.0.4/go.mod h1:jJswKPEdvpFpvf7dsDvFZyLT22xZ9lWqEByX38oGd9E= -github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= -github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= -github.com/ethereum/go-ethereum v1.10.20 h1:75IW830ClSS40yrQC1ZCMZCt5I+zU16oqId2SiQwdQ4= -github.com/ethereum/go-ethereum v1.10.20/go.mod h1:LWUN82TCHGpxB3En5HVmLLzPD7YSrEUFmFfN1nKkVN0= -github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E= -github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= -github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= -github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= -github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa h1:Q75Upo5UN4JbPFURXZ8nLKYUvF85dyFRop/vQ0Rv+64= -github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= -github.com/gtank/merlin v0.1.1 h1:eQ90iG7K9pOhtereWsmyRJ6RAwcP4tHTDBHXNg+u5is= -github.com/gtank/merlin v0.1.1/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= -github.com/gtank/ristretto255 v0.1.2 h1:JEqUCPA1NvLq5DwYtuzigd7ss8fwbYay9fi4/5uMzcc= -github.com/gtank/ristretto255 v0.1.2/go.mod h1:Ph5OpO6c7xKUGROZfWVLiJf9icMDwUeIvY4OmlYW69o= -github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643/go.mod h1:43+3pMjjKimDBf5Kr4ZFNGbLql1zKkbImw+fZbw3geM= -github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b h1:QrHweqAtyJ9EwCaGHBu1fghwxIPiopAHV06JlXrMHjk= -github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b/go.mod h1:xxLb2ip6sSUts3g1irPVHyk/DGslwQsNOo9I7smJfNU= -github.com/pierrec/xxHash v0.1.5 h1:n/jBpwTHiER4xYvK3/CdPVnLDPchj8eTJFFLUb4QHBo= -github.com/pierrec/xxHash v0.1.5/go.mod h1:w2waW5Zoa/Wc4Yqe0wgrIYAGKqRMf7czn2HNKXmuL+I= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U= -github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= -github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= -github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= -github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -github.com/tklauser/go-sysconf v0.3.5 h1:uu3Xl4nkLzQfXNsWn15rPc/HQCJKObbt1dKJeWp3vU4= -github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI= -github.com/tklauser/numcpus v0.2.2 h1:oyhllyrScuYI6g+h/zUvNXNp1wy7x8qQy3t/piefldA= -github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZFu0T9wgjM= -github.com/vedhavyas/go-subkey v1.0.4 h1:QwjBZx4w7qXC2lmqol2jJfhaNXPI9BsgLZiMiCwqGDU= -github.com/vedhavyas/go-subkey v1.0.4/go.mod h1:aOIil/KS9hJlnr9ZSQKSoXdu/MbnkCxG4x9IOlLsMtI= -github.com/vedhavyas/go-subkey/v2 v2.0.0 h1:LemDIsrVtRSOkp0FA8HxP6ynfKjeOj3BY2U9UNfeDMA= -github.com/vedhavyas/go-subkey/v2 v2.0.0/go.mod h1:95aZ+XDCWAUUynjlmi7BtPExjXgXxByE0WfBwbmIRH4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= -gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/avail-go/src/config/config.go b/avail-go/src/config/config.go deleted file mode 100644 index 1915384a1..000000000 --- a/avail-go/src/config/config.go +++ /dev/null @@ -1,59 +0,0 @@ -package config - -import ( - "encoding/json" - "flag" - "fmt" - "io" - "log" - "os" -) - -type Config struct { - Seed string `json:"seed"` - ApiURL string `json:"api_url"` - Size int `json:"size"` - AppID int `json:"app_id"` - Dest string `json:"dest"` - Amount uint64 `json:"amount"` - SessionKeys string `json:"session_keys"` -} - -func (c *Config) GetConfig(configFileName string) error { - jsonFile, err := os.Open(configFileName) - if err != nil { - return err - } - defer jsonFile.Close() - - byteValue, err := io.ReadAll(jsonFile) - if err != nil { - return err - } - - err = json.Unmarshal(byteValue, c) - if err != nil { - return err - } - - return nil -} - -func LoadConfig() (*Config, error) { - var configJSON string - flag.StringVar(&configJSON, "config", "", "config json file") - flag.Parse() - - if configJSON == "" { - log.Println("No config file provided. Exiting...") - os.Exit(0) - } - - var config Config - err := config.GetConfig(configJSON) - if err != nil { - return nil, fmt.Errorf("cannot get config: %v", err) - } - - return &config, nil -} diff --git a/avail-go/src/extrinsic/era.go b/avail-go/src/extrinsic/era.go deleted file mode 100644 index 7e3e1e7d3..000000000 --- a/avail-go/src/extrinsic/era.go +++ /dev/null @@ -1,163 +0,0 @@ -package extrinsic - -import ( - "errors" - "math" - "strconv" - - "github.com/centrifuge/go-substrate-rpc-client/v4/scale" - "github.com/centrifuge/go-substrate-rpc-client/v4/types" -) - -// ExtrinsicEra indicates either a mortal or immortal extrinsic -type ExtrinsicEra struct { - IsImmortalEra bool - // AsImmortalEra ImmortalEra - IsMortalEra bool - AsMortalEra MortalEra -} - -func (e *ExtrinsicEra) Decode(decoder scale.Decoder) error { - first, err := decoder.ReadOneByte() - if err != nil { - return err - } - - if first == 0 { - e.IsImmortalEra = true - return nil - } - - second, err := decoder.ReadOneByte() - if err != nil { - return err - } - - encoded := uint64(first) + (uint64(second) << 8) - period := 2 << (encoded % (1 << 4)) - quantizeFactor := period >> 12 - - if quantizeFactor <= 1 { - quantizeFactor = 1 - } - - phase := (encoded >> 4) * uint64(quantizeFactor) - - if period >= 4 && phase < uint64(period) { - e.IsMortalEra = true - e.AsMortalEra = MortalEra{ - First: types.U64(period), - Second: types.U64(phase), - } - return nil - } - - return errors.New("invalid era") -} - -func (e ExtrinsicEra) Encode(encoder scale.Encoder) error { - if e.IsImmortalEra { - return encoder.PushByte(0) - } - - // let quantize_factor = (*period as u64 >> 12).max(1); - quantizeFactor := e.AsMortalEra.First >> 12 - - if quantizeFactor <= 1 { - quantizeFactor = 1 - } - - // let encoded = (period.trailing_zeros() - 1).max(1).min(15) as u16 | - // ((phase / quantize_factor) << 4) as u16; - trailingZeroes := getTrailingZeroes(e.AsMortalEra.First) - 1 - - if trailingZeroes <= 1 { - trailingZeroes = 1 - } - - if trailingZeroes >= 15 { - trailingZeroes = 15 - } - - r := types.U16((e.AsMortalEra.Second / quantizeFactor) << 4) - - encoded := trailingZeroes | r - - // encoded.encode_to(output); - return encoder.Encode(encoded) -} - -// MortalEra for an extrinsic, indicating period and phase -type MortalEra struct { - First types.U64 - Second types.U64 -} - -func NewMortalEra(currentBlock types.BlockNumber, blockHashCount types.U64) MortalEra { - // BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64; - np := getNextPowerOfTwo(blockHashCount, 2) - - var npb types.U64 - - if np > 2 { - npb = np / 2 - } - - // let period = period.checked_next_power_of_two().unwrap_or(1 << 16).max(4).min(1 << 16); - period := getNextPowerOfTwo(npb, 1<<16) - - if period <= 4 { - period = 4 - } - - if period >= 1<<16 { - period = 1 << 16 - } - - // let phase = current % period; - phase := types.U64(currentBlock) % period - - // let quantize_factor = (period >> 12).max(1); - quantizeFactor := period >> 12 - - if quantizeFactor <= 1 { - quantizeFactor = 1 - } - - // let quantized_phase = phase / quantize_factor * quantize_factor; - quantizedPhase := phase / quantizeFactor * quantizeFactor - - return MortalEra{period, quantizedPhase} -} - -func getNextPowerOfTwo(n types.U64, def types.U64) types.U64 { - bn := strconv.FormatInt(int64(n), 2) - numBits := len(bn) - - if (1 << (numBits - 1)) == n { - return n - } - - res := uint(1 << numBits) - - if res > math.MaxUint64 { - return def - } - - return types.U64(res) -} - -func getTrailingZeroes(n types.U64) types.U16 { - var count types.U16 - - for n > 0 { - if n%2 == 1 { - break - } - - n = n / 2 - count++ - } - - return count -} diff --git a/avail-go/src/extrinsic/extrinsic.go b/avail-go/src/extrinsic/extrinsic.go deleted file mode 100644 index c1c9a84d6..000000000 --- a/avail-go/src/extrinsic/extrinsic.go +++ /dev/null @@ -1,262 +0,0 @@ -package extrinsic - -import ( - "bytes" - "encoding/json" - "fmt" - "math/big" - "strings" - - "github.com/centrifuge/go-substrate-rpc-client/v4/scale" - "github.com/centrifuge/go-substrate-rpc-client/v4/signature" - "github.com/centrifuge/go-substrate-rpc-client/v4/types" - "github.com/centrifuge/go-substrate-rpc-client/v4/types/codec" -) - -type SignatureOptions struct { - Era ExtrinsicEra - Nonce types.UCompact - Tip types.UCompact - SpecVersion types.U32 - GenesisHash types.Hash - BlockHash types.Hash - AppID types.UCompact - TransactionVersion types.U32 -} -type ExtrinsicSignatureV4 struct { - Signer types.MultiAddress - Signature types.MultiSignature - Era ExtrinsicEra // extra via system::CheckEra - Nonce types.UCompact // extra via system::CheckNonce (Compact where Index is u32)) - Tip types.UCompact // extra via balances::TakeFees (Compact where Balance is u128)) - AppID types.UCompact // Avail specific AppID -} - -const ( - ExtrinsicBitSigned = 0x80 - ExtrinsicBitUnsigned = 0 - ExtrinsicUnmaskVersion = 0x7f - ExtrinsicDefaultVersion = 1 - ExtrinsicVersionUnknown = 0 // v0 is unknown - ExtrinsicVersion1 = 1 - ExtrinsicVersion2 = 2 - ExtrinsicVersion3 = 3 - ExtrinsicVersion4 = 4 -) - -// Extrinsic is a piece of Args bundled into a block that expresses something from the "external" (i.e. off-chain) -// world. There are, broadly speaking, two types of extrinsic: transactions (which tend to be signed) and -// inherents (which don't). -type Extrinsic struct { - // Version is the encoded version flag (which encodes the raw transaction version and signing information in one byte) - Version byte - // Signature is the ExtrinsicSignatureV4, it's presence depends on the Version flag - Signature ExtrinsicSignatureV4 - // Method is the call this extrinsic wraps - Method types.Call -} - -// NewExtrinsic creates a new Extrinsic from the provided Call -func NewExtrinsic(c types.Call) Extrinsic { - return Extrinsic{ - Version: ExtrinsicVersion4, - Method: c, - } -} - -// UnmarshalJSON fills Extrinsic with the JSON encoded byte array given by bz -func (e *Extrinsic) UnmarshalJSON(bz []byte) error { - var tmp string - if err := json.Unmarshal(bz, &tmp); err != nil { - return err - } - - // HACK 11 Jan 2019 - before https://github.com/paritytech/substrate/pull/1388 - // extrinsics didn't have the length, cater for both approaches. This is very - // inconsistent with any other `Vec` implementation - var l types.UCompact - err := codec.DecodeFromHex(tmp, &l) - if err != nil { - return err - } - - prefix, err := codec.EncodeToHex(l) - if err != nil { - return err - } - - // determine whether length prefix is there - if strings.HasPrefix(tmp, prefix) { - return codec.DecodeFromHex(tmp, e) - } - - // not there, prepend with compact encoded length prefix - dec, err := codec.HexDecodeString(tmp) - if err != nil { - return err - } - length := types.NewUCompactFromUInt(uint64(len(dec))) - bprefix, err := codec.Encode(length) - if err != nil { - return err - } - bprefix = append(bprefix, dec...) - return codec.Decode(bprefix, e) -} - -// MarshalJSON returns a JSON encoded byte array of Extrinsic -func (e Extrinsic) MarshalJSON() ([]byte, error) { - s, err := codec.EncodeToHex(e) - if err != nil { - return nil, err - } - return json.Marshal(s) -} - -// IsSigned returns true if the extrinsic is signed -func (e Extrinsic) IsSigned() bool { - return e.Version&ExtrinsicBitSigned == ExtrinsicBitSigned -} - -// Type returns the raw transaction version (not flagged with signing information) -func (e Extrinsic) Type() uint8 { - return e.Version & ExtrinsicUnmaskVersion -} - -// Sign adds a signature to the extrinsic -func (e *Extrinsic) Sign(signer signature.KeyringPair, o SignatureOptions) error { - if e.Type() != ExtrinsicVersion4 { - return fmt.Errorf("unsupported extrinsic version: %v (isSigned: %v, type: %v)", e.Version, e.IsSigned(), e.Type()) - } - - mb, err := codec.Encode(e.Method) - if err != nil { - return err - } - - era := o.Era - if !o.Era.IsMortalEra { - era = ExtrinsicEra{IsImmortalEra: true} - } - - payload := ExtrinsicPayloadV3{ - Method: mb, - Era: era, - Nonce: o.Nonce, - Tip: o.Tip, - AppID: o.AppID, - SpecVersion: o.SpecVersion, - TransactionVersion: o.TransactionVersion, - GenesisHash: o.GenesisHash, - BlockHash: o.BlockHash, - } - - signerPubKey, err := types.NewMultiAddressFromAccountID(signer.PublicKey) - - if err != nil { - return err - } - - sig, err := payload.Sign(signer) - if err != nil { - return err - } - - extSig := ExtrinsicSignatureV4{ - Signer: signerPubKey, - Signature: types.MultiSignature{IsSr25519: true, AsSr25519: sig}, - Era: era, - Nonce: o.Nonce, - Tip: o.Tip, - AppID: o.AppID, - } - - e.Signature = extSig - - // mark the extrinsic as signed - e.Version |= ExtrinsicBitSigned - - return nil -} - -func (e *Extrinsic) Decode(decoder scale.Decoder) error { - // compact length encoding (1, 2, or 4 bytes) (may not be there for Extrinsics older than Jan 11 2019) - _, err := decoder.DecodeUintCompact() - if err != nil { - return err - } - - // version, signature bitmask (1 byte) - err = decoder.Decode(&e.Version) - if err != nil { - return err - } - - // signature - if e.IsSigned() { - if e.Type() != ExtrinsicVersion4 { - return fmt.Errorf("unsupported extrinsic version: %v (isSigned: %v, type: %v)", e.Version, e.IsSigned(), - e.Type()) - } - - err = decoder.Decode(&e.Signature) - if err != nil { - return err - } - } - - // call - err = decoder.Decode(&e.Method) - if err != nil { - return err - } - - return nil -} - -func (e Extrinsic) Encode(encoder scale.Encoder) error { - if e.Type() != ExtrinsicVersion4 { - return fmt.Errorf("unsupported extrinsic version: %v (isSigned: %v, type: %v)", e.Version, e.IsSigned(), - e.Type()) - } - - // create a temporary buffer that will receive the plain encoded transaction (version, signature (optional), - // method/call) - var bb = bytes.Buffer{} - tempEnc := scale.NewEncoder(&bb) - - // encode the version of the extrinsic - err := tempEnc.Encode(e.Version) - if err != nil { - return err - } - - // encode the signature if signed - if e.IsSigned() { - err = tempEnc.Encode(e.Signature) - if err != nil { - return err - } - } - - // encode the method - err = tempEnc.Encode(e.Method) - if err != nil { - return err - } - - // take the temporary buffer to determine length, write that as prefix - eb := bb.Bytes() - err = encoder.EncodeUintCompact(*big.NewInt(0).SetUint64(uint64(len(eb)))) - if err != nil { - return err - } - - // write the actual encoded transaction - err = encoder.Write(eb) - if err != nil { - return err - } - - return nil -} diff --git a/avail-go/src/extrinsic/payload.go b/avail-go/src/extrinsic/payload.go deleted file mode 100644 index 6229372cb..000000000 --- a/avail-go/src/extrinsic/payload.go +++ /dev/null @@ -1,158 +0,0 @@ -package extrinsic - -import ( - "fmt" - - "github.com/centrifuge/go-substrate-rpc-client/v4/signature" - "github.com/centrifuge/go-substrate-rpc-client/v4/types" - "github.com/centrifuge/go-substrate-rpc-client/v4/types/codec" - "github.com/vedhavyas/go-subkey/scale" -) - -type ExtrinsicPayloadV3 struct { - Method types.BytesBare - Era ExtrinsicEra // extra via system::CheckEra - Nonce types.UCompact // extra via system::CheckNonce (Compact where Index is u32) - Tip types.UCompact // extra via balances::TakeFees (Compact where Balance is u128) - AppID types.UCompact - SpecVersion types.U32 // additional via system::CheckVersion - TransactionVersion types.U32 - GenesisHash types.Hash // additional via system::CheckGenesis - BlockHash types.Hash // additional via system::CheckEra -} - -// Sign the extrinsic payload with the given derivation path -func (e ExtrinsicPayloadV3) Sign(signer signature.KeyringPair) (types.Signature, error) { - b, err := codec.Encode(e) - if err != nil { - return types.Signature{}, err - } - - sig, err := signature.Sign(b, signer.URI) - return types.NewSignature(sig), err -} - -// Encode implements encoding for ExtrinsicPayloadV3, which just unwraps the bytes of ExtrinsicPayloadV3 without -// adding a compact length prefix -func (e ExtrinsicPayloadV3) Encode(encoder scale.Encoder) error { - err := encoder.Encode(e.Method) - if err != nil { - return err - } - - err = encoder.Encode(e.Era) - if err != nil { - return err - } - - err = encoder.Encode(e.Nonce) - if err != nil { - return err - } - - err = encoder.Encode(e.Tip) - if err != nil { - return err - } - - err = encoder.Encode(e.SpecVersion) - if err != nil { - return err - } - - err = encoder.Encode(e.GenesisHash) - if err != nil { - return err - } - - err = encoder.Encode(e.BlockHash) - if err != nil { - return err - } - err = encoder.Encode(e.AppID) - if err != nil { - return err - } - err = encoder.Encode(e.TransactionVersion) - if err != nil { - return err - } - - return nil -} - -// Decode does nothing and always returns an error. ExtrinsicPayloadV3 is only used for encoding, not for decoding -func (e *ExtrinsicPayloadV3) Decode(decoder scale.Decoder) error { - return fmt.Errorf("decoding of ExtrinsicPayloadV3 is not supported") -} - -type ExtrinsicPayloadV4 struct { - ExtrinsicPayloadV3 - TransactionVersion types.U32 - AppID types.UCompact -} - -// Sign the extrinsic payload with the given derivation path -func (e ExtrinsicPayloadV4) Sign(signer signature.KeyringPair) (types.Signature, error) { - b, err := codec.Encode(e) - if err != nil { - return types.Signature{}, err - } - - sig, err := signature.Sign(b, signer.URI) - return types.NewSignature(sig), err -} - -func (e ExtrinsicPayloadV4) Encode(encoder scale.Encoder) error { - err := encoder.Encode(e.Method) - if err != nil { - return err - } - - err = encoder.Encode(e.Era) - if err != nil { - return err - } - - err = encoder.Encode(e.Nonce) - if err != nil { - return err - } - - err = encoder.Encode(e.Tip) - if err != nil { - return err - } - - err = encoder.Encode(e.AppID) - if err != nil { - return err - } - - err = encoder.Encode(e.SpecVersion) - if err != nil { - return err - } - - err = encoder.Encode(e.TransactionVersion) - if err != nil { - return err - } - - err = encoder.Encode(e.GenesisHash) - if err != nil { - return err - } - - err = encoder.Encode(e.BlockHash) - if err != nil { - return err - } - - return nil -} - -// Decode does nothing and always returns an error. ExtrinsicPayloadV4 is only used for encoding, not for decoding -func (e *ExtrinsicPayloadV4) Decode(decoder scale.Decoder) error { - return fmt.Errorf("decoding of ExtrinsicPayloadV4 is not supported") -} diff --git a/avail-go/src/header/header.go b/avail-go/src/header/header.go deleted file mode 100644 index 06fb8266f..000000000 --- a/avail-go/src/header/header.go +++ /dev/null @@ -1,74 +0,0 @@ -package header - -import ( - avail "avail-go-sdk/src/sdk/types" - - "github.com/centrifuge/go-substrate-rpc-client/v4/scale" - "github.com/centrifuge/go-substrate-rpc-client/v4/types" -) - -type DataLookupIndexItem struct { - AppId avail.UCompact `json:"appId"` - Start avail.UCompact `json:"start"` -} -type DataLookup struct { - Size avail.UCompact `json:"size"` - Index []DataLookupIndexItem `json:"index"` -} - -type KateCommitment struct { - Rows avail.UCompact `json:"rows"` - Cols avail.UCompact `json:"cols"` - Commitment []types.U8 `json:"commitment"` - DataRoot types.Hash `json:"dataRoot"` -} - -type V3HeaderExtension struct { - AppLookup DataLookup `json:"appLookup"` - Commitment KateCommitment `json:"commitment"` -} - -type HeaderExtensionEnum struct { - V3 V3HeaderExtension `json:"V3"` -} - -type Header struct { - ParentHash types.Hash `json:"parentHash"` - Number types.BlockNumber `json:"number"` - StateRoot types.Hash `json:"stateRoot"` - ExtrinsicsRoot types.Hash `json:"extrinsicsRoot"` - Digest types.Digest `json:"digest"` - Extension HeaderExtensionEnum `json:"extension"` -} - -func (m HeaderExtensionEnum) Encode(encoder scale.Encoder) error { - var err, err1 error - - err = encoder.PushByte(2) - - if err != nil { - return err - } - err1 = encoder.Encode(m.V3) - if err1 != nil { - return err1 - } - return nil -} - -func (m *HeaderExtensionEnum) Decode(decoder scale.Decoder) error { - b, err := decoder.ReadOneByte() - - if err != nil { - return err - } - - if b == 2 { - err = decoder.Decode(&m.V3) - } - if err != nil { - return err - } - - return nil -} diff --git a/avail-go/src/rpc/block.go b/avail-go/src/rpc/block.go deleted file mode 100644 index 74ef4479b..000000000 --- a/avail-go/src/rpc/block.go +++ /dev/null @@ -1,91 +0,0 @@ -package rpc - -import ( - "avail-go-sdk/src/extrinsic" - "avail-go-sdk/src/header" - - "github.com/centrifuge/go-substrate-rpc-client/v4/client" - "github.com/centrifuge/go-substrate-rpc-client/v4/types" -) - -type SignedBlock struct { - Block Block `json:"block"` - Justification types.Justification `json:"justification"` -} - -// Block encoded with header and extrinsics -type Block struct { - Header header.Header `json:"header"` - Extrinsics []extrinsic.Extrinsic -} - -// GetBlock returns the header and body of the relay chain block with the given hash -func GetAvailBlock(blockHash types.Hash, client1 client.Client) (*SignedBlock, error) { - return getBlock(&blockHash, client1) -} - -func GetAvailBlockLatest(client1 client.Client) (*SignedBlock, error) { - return getBlock(nil, client1) -} - -func getBlock(blockHash *types.Hash, client1 client.Client) (*SignedBlock, error) { - var SignedBlock SignedBlock - err := client.CallWithBlockHash(client1, &SignedBlock, "chain_getBlock", blockHash) - if err != nil { - return nil, err - } - return &SignedBlock, err -} - -func GetFinalizedHead(client client.Client) (types.Hash, error) { - var res string - - err := client.Call(&res, "chain_getFinalizedHead") - if err != nil { - return types.Hash{}, err - } - - return types.NewHashFromHexString(res) -} - -func getBlockHash(client client.Client, blockNumber *uint64) (types.Hash, error) { - var res string - var err error - - if blockNumber == nil { - err = client.Call(&res, "chain_getBlockHash") - } else { - err = client.Call(&res, "chain_getBlockHash", *blockNumber) - } - - if err != nil { - return types.Hash{}, err - } - - return types.NewHashFromHexString(res) -} - -func GetBlockHash(client client.Client, blockNumber uint64) (types.Hash, error) { - return getBlockHash(client, &blockNumber) -} - -func GetBlockHashLatest(client client.Client) (types.Hash, error) { - return getBlockHash(client, nil) -} - -func getHeader(client1 client.Client, blockHash *types.Hash) (*header.Header, error) { - var Header header.Header - err := client.CallWithBlockHash(client1, &Header, "chain_getHeader", blockHash) - if err != nil { - return nil, err - } - return &Header, err -} - -func GetHeaderLatest(client1 client.Client) (*header.Header, error) { - return getHeader(client1, nil) -} - -func GetHeader(client1 client.Client, blockHash types.Hash) (*header.Header, error) { - return getHeader(client1, &blockHash) -} diff --git a/avail-go/src/rpc/kate.go b/avail-go/src/rpc/kate.go deleted file mode 100644 index a9523d595..000000000 --- a/avail-go/src/rpc/kate.go +++ /dev/null @@ -1,150 +0,0 @@ -package rpc - -import ( - "encoding/json" - "fmt" - "math/big" - "strings" - - "github.com/centrifuge/go-substrate-rpc-client/v4/types" -) - -const MaxCells = 10000 - -type Cell struct { - Row uint64 `json:"row"` - Col uint64 `json:"col"` -} - -func NewCell(row, col uint64) Cell { - return Cell{Row: row, Col: col} -} - -type GDataProof struct { - RawScalar big.Int `json:"RawScalar"` // For U256 - Proof GProof `json:"Proof"` -} - -type GProof struct { - Data [48]byte `json:"Data"` -} - -func (g *GDataProof) UnmarshalJSON(data []byte) error { - var tupleData [2]json.RawMessage - - if err := json.Unmarshal(data, &tupleData); err != nil { - return err - } - - // Unmarshal RawScalar and remove the '0x' prefix - var rawScalarString string - if err := json.Unmarshal(tupleData[0], &rawScalarString); err != nil { - return err - } - - fmt.Println("RawScalarString:", rawScalarString) - - // Strip '0x' prefix and convert to big.Int - trimmedScalarString := strings.TrimPrefix(rawScalarString, "0x") - rawScalar, ok := new(big.Int).SetString(trimmedScalarString, 16) - if !ok { - fmt.Printf("Failed to convert RawScalar to big.Int, string was: %s\n", trimmedScalarString) - return fmt.Errorf("invalid RawScalar format") - } - g.RawScalar = *rawScalar - - // Unmarshal Proof - var proof [48]byte - if err := json.Unmarshal(tupleData[1], &proof); err != nil { - return err - } - g.Proof = GProof{proof} - - return nil -} - -func formatBigIntWithCommas(b *big.Int) string { - if b == nil { - return "" - } - - numStr := b.String() - - // Starting index for inserting commas - startOffset := 0 - if numStr[0] == '-' { - startOffset = 1 // Keep the negative sign intact - } - - // Slice to hold the parts of the number - var parts []string - - // Iterate over the string in reverse, collecting slices of 3 digits - for i := len(numStr); i > startOffset; i -= 3 { - end := i - start := i - 3 - if start < startOffset { - start = startOffset - } - parts = append([]string{numStr[start:end]}, parts...) - } - - // Join the parts with commas - return strings.Join(parts, ",") -} - -func (g *GDataProof) MarshalJSON() ([]byte, error) { - rawScalarStr := formatBigIntWithCommas(&g.RawScalar) - proofHex := fmt.Sprintf("0x%x", g.Proof.Data) - return json.Marshal([]interface{}{rawScalarStr, proofHex}) -} - -type ProofResponse struct { - DataProof DataProof - Message Message // Interface to capture different message types -} - -type TxDataRoot struct { - DataRoot types.Hash - BlobRoot types.Hash - BridgeRoot types.Hash -} - -// DataProof struct represents the data proof response -type DataProof struct { - Roots TxDataRoot - Proof []types.Hash - NumberOfLeaves uint32 // Change to uint32 to match Rust u32 - LeafIndex uint32 // Change to uint32 to match Rust u32 - Leaf types.Hash -} - -// Message interface represents the enum variants -type Message interface { - isMessage() -} - -type BoundedData struct { - Data []byte -} - -// BoundedDataMaxLen is the maximum length for the bounded data -const BoundedDataMaxLen = 32 // Adjust the maximum length as needed - -// ArbitraryMessage struct represents the ArbitraryMessage variant -type ArbitraryMessage struct { - BoundedData -} - -func (a *ArbitraryMessage) isMessage() {} - -// FungibleToken struct represents the FungibleToken variant -type FungibleToken struct { - AssetID types.Hash - Amount uint128 // Define uint128 type as needed -} - -func (f *FungibleToken) isMessage() {} - -type uint128 uint64 - diff --git a/avail-go/src/rpc/submit.go b/avail-go/src/rpc/submit.go deleted file mode 100644 index e8da669ea..000000000 --- a/avail-go/src/rpc/submit.go +++ /dev/null @@ -1,87 +0,0 @@ -package rpc - -import ( - "avail-go-sdk/src/extrinsic" - "context" - "fmt" - "sync" - - "github.com/centrifuge/go-substrate-rpc-client/v4/client" - "github.com/centrifuge/go-substrate-rpc-client/v4/config" - gethrpc "github.com/centrifuge/go-substrate-rpc-client/v4/gethrpc" - "github.com/centrifuge/go-substrate-rpc-client/v4/types" - "github.com/centrifuge/go-substrate-rpc-client/v4/types/codec" -) - -type ExtrinsicStatusSubscription struct { - sub *gethrpc.ClientSubscription - channel chan types.ExtrinsicStatus - quitOnce sync.Once // ensures quit is closed once -} - -// Chan returns the subscription channel. -// -// The channel is closed when Unsubscribe is called on the subscription. -func (s *ExtrinsicStatusSubscription) Chan() <-chan types.ExtrinsicStatus { - return s.channel -} - -// Err returns the subscription error channel. The intended use of Err is to schedule -// resubscription when the client connection is closed unexpectedly. -// -// The error channel receives a value when the subscription has ended due -// to an error. The received error is nil if Close has been called -// on the underlying client and no other error has occurred. -// -// The error channel is closed when Unsubscribe is called on the subscription. -func (s *ExtrinsicStatusSubscription) Err() <-chan error { - return s.sub.Err() -} - -// Unsubscribe unsubscribes the notification and closes the error channel. -// It can safely be called more than once. -func (s *ExtrinsicStatusSubscription) Unsubscribe() { - s.sub.Unsubscribe() - s.quitOnce.Do(func() { - close(s.channel) - }) -} - -// SubmitAndWatchExtrinsic will submit and subscribe to watch an extrinsic until unsubscribed, returning a subscription -// that will receive server notifications containing the extrinsic status updates. -func SubmitAndWatchExtrinsic(xt extrinsic.Extrinsic, client client.Client) (*ExtrinsicStatusSubscription, error) { //nolint:lll - ctx, cancel := context.WithTimeout(context.Background(), config.Default().SubscribeTimeout) - defer cancel() - - c := make(chan types.ExtrinsicStatus) - - enc, err := codec.EncodeToHex(xt) - if err != nil { - return nil, err - } - - sub, err := client.Subscribe(ctx, "author", "submitAndWatchExtrinsic", "unwatchExtrinsic", "extrinsicUpdate", - c, enc) - if err != nil { - return nil, err - } - - return &ExtrinsicStatusSubscription{sub: sub, channel: c}, nil -} - -func SubmitExtrinsic(xt extrinsic.Extrinsic, client client.Client) (types.Hash, error) { - enc, err := codec.EncodeToHex(xt) - - if err != nil { - return types.Hash{}, err - } - fmt.Println(enc) - - var res string - err = client.Call(&res, "author_submitExtrinsic", enc) - if err != nil { - return types.Hash{}, err - } - - return types.NewHashFromHexString(res) -} diff --git a/avail-go/src/sdk/call/call.go b/avail-go/src/sdk/call/call.go deleted file mode 100644 index 797f2a410..000000000 --- a/avail-go/src/sdk/call/call.go +++ /dev/null @@ -1,54 +0,0 @@ -package call - -import ( - "avail-go-sdk/src/rpc" - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/types" - "encoding/hex" - "fmt" -) - -func Query_proof(api *sdk.SubstrateAPI, testCell []rpc.Cell, blockHash types.Hash) ([]rpc.GDataProof, error) { - var result []rpc.GDataProof - err := api.Client.Call(&result, "kate_queryProof", testCell, blockHash) - if err != nil { - return nil, err - } - return result, nil -} - -func Author_Rotate(api *sdk.SubstrateAPI) ([]byte, error) { - var result string - err := api.Client.Call(&result, "author_rotateKeys", nil) - if err != nil { - return nil, err - } - if len(result) > 2 && result[:2] == "0x" { - result = result[2:] - } - - // Decode the hex string - decodedResult, err := hex.DecodeString(result) - if err != nil { - panic(fmt.Errorf("failed to decode result: %w", err)) - } - return decodedResult, nil -} - -func Query_rows(api *sdk.SubstrateAPI, arr []uint32, h types.Hash) ([][]sdk.BigInt, error) { - var response [][]sdk.BigInt - err := api.Client.Call(&response, "kate_queryRows", arr, h) - if err != nil { - return nil, err - } - return response, nil -} - -func Query_dataproof(api *sdk.SubstrateAPI, transactionIndex types.U32, h types.Hash) (rpc.ProofResponse, error) { - var response rpc.ProofResponse - err := api.Client.Call(&response, "kate_queryDataProof", transactionIndex, h) - if err != nil { - return rpc.ProofResponse{}, err - } - return response, nil -} diff --git a/avail-go/src/sdk/callExtrinsic.go b/avail-go/src/sdk/callExtrinsic.go deleted file mode 100644 index dbb890cf7..000000000 --- a/avail-go/src/sdk/callExtrinsic.go +++ /dev/null @@ -1,160 +0,0 @@ -package sdk - -import ( - "avail-go-sdk/src/extrinsic" - "avail-go-sdk/src/rpc" - "encoding/hex" - "fmt" - "log" - "strings" - "time" - - "github.com/centrifuge/go-substrate-rpc-client/v4/signature" - "github.com/centrifuge/go-substrate-rpc-client/v4/types" - "github.com/ethereum/go-ethereum/common/hexutil" - "golang.org/x/crypto/blake2b" -) - -func NewExtrinsic(api *SubstrateAPI, ext_call string, keyring signature.KeyringPair, AppID int, arg ...interface{}) (types.Hash, error) { - meta, err := api.RPC.State.GetMetadataLatest() - if err != nil { - return types.Hash{}, err - } - call, err := types.NewCall(meta, ext_call, arg...) - if err != nil { - return types.Hash{}, err - } - ext := extrinsic.NewExtrinsic(call) - genesisHash, err := api.RPC.Chain.GetBlockHash(0) - if err != nil { - return types.Hash{}, err - } - rv, err := api.RPC.State.GetRuntimeVersionLatest() - if err != nil { - return types.Hash{}, err - } - key, err := types.CreateStorageKey(meta, "System", "Account", keyring.PublicKey) - if err != nil { - return types.Hash{}, err - } - - var accountInfo types.AccountInfo - ok, err := api.RPC.State.GetStorageLatest(key, &accountInfo) - if err != nil || !ok { - return types.Hash{}, err - } - nonce := uint32(accountInfo.Nonce) - options := extrinsic.SignatureOptions{ - BlockHash: genesisHash, - Era: extrinsic.ExtrinsicEra{IsMortalEra: false}, - GenesisHash: genesisHash, - Nonce: types.NewUCompactFromUInt(uint64(nonce)), - SpecVersion: rv.SpecVersion, - Tip: types.NewUCompactFromUInt(100), - AppID: types.NewUCompactFromUInt(uint64(AppID)), - TransactionVersion: rv.TransactionVersion, - } - err = ext.Sign(keyring, options) - if err != nil { - panic(fmt.Sprintf("cannot sign:%v", err)) - } - hash, err := rpc.SubmitExtrinsic(ext, api.Client) - if err != nil { - panic(fmt.Sprintf("cannot submit extrinsic:%v", err)) - } - - fmt.Printf("Data submitted using APPID: %v \n", AppID) - return hash, nil -} - -func NewExtrinsicWatch(api *SubstrateAPI, ext_call string, keyring signature.KeyringPair, final chan types.Hash, txHash chan types.Hash, AppID int, WaitForInclusion WaitFor, arg ...interface{}) error { - meta, err := api.RPC.State.GetMetadataLatest() - if err != nil { - return err - } - call, err := types.NewCall(meta, ext_call, arg...) - if err != nil { - return err - } - ext := extrinsic.NewExtrinsic(call) - genesisHash, err := api.RPC.Chain.GetBlockHash(0) - if err != nil { - return err - } - rv, err := api.RPC.State.GetRuntimeVersionLatest() - if err != nil { - return err - } - key, err := types.CreateStorageKey(meta, "System", "Account", keyring.PublicKey) - if err != nil { - return err - } - - var accountInfo types.AccountInfo - ok, err := api.RPC.State.GetStorageLatest(key, &accountInfo) - if err != nil || !ok { - return err - } - nonce := uint32(accountInfo.Nonce) - options := extrinsic.SignatureOptions{ - BlockHash: genesisHash, - Era: extrinsic.ExtrinsicEra{IsMortalEra: false}, - GenesisHash: genesisHash, - Nonce: types.NewUCompactFromUInt(uint64(nonce)), - SpecVersion: rv.SpecVersion, - Tip: types.NewUCompactFromUInt(100), - AppID: types.NewUCompactFromUInt(uint64(AppID)), - TransactionVersion: rv.TransactionVersion, - } - err = ext.Sign(keyring, options) - if err != nil { - panic(fmt.Sprintf("cannot sign:%v", err)) - } - - go func() { - enc, _ := EncodeToHex(ext) - - cleanedHexString := strings.TrimPrefix(enc, "0x") - bytes, err := hex.DecodeString(cleanedHexString) - if err != nil { - log.Fatal(err) - } - hash := blake2b.Sum256(bytes) - ext_z := hexutil.Encode(hash[:]) - hash, err = NewHashFromHexString(ext_z) - if err != nil { - log.Fatal(err) - } - txHash <- hash - }() - - sub, err := rpc.SubmitAndWatchExtrinsic(ext, api.Client) - if err != nil { - panic(fmt.Sprintf("cannot submit extrinsic:%v", err)) - } - - fmt.Printf("Transaction being submitted .... ⏳Waiting for block inclusion..") - - defer sub.Unsubscribe() - timeout := time.After(200 * time.Second) - for { - select { - case status := <-sub.Chan(): - switch WaitForInclusion { - case BlockInclusion: - if status.IsInBlock { - final <- status.AsInBlock - return err - } - case BlockFinalization: - if status.IsFinalized { - final <- status.AsFinalized - return err - } - } - case <-timeout: - fmt.Printf("timeout of 200 seconds reached without getting finalized status for extrinsic") - return err - } - } -} diff --git a/avail-go/src/sdk/events.go b/avail-go/src/sdk/events.go deleted file mode 100644 index a95d946e8..000000000 --- a/avail-go/src/sdk/events.go +++ /dev/null @@ -1,525 +0,0 @@ -package sdk - -import ( - "encoding/hex" - "fmt" - - "log" - "math/big" - - "github.com/centrifuge/go-substrate-rpc-client/v4/registry" - "github.com/centrifuge/go-substrate-rpc-client/v4/registry/parser" - retriever "github.com/centrifuge/go-substrate-rpc-client/v4/registry/retriever" - "github.com/centrifuge/go-substrate-rpc-client/v4/registry/state" - "github.com/centrifuge/go-substrate-rpc-client/v4/types" - "github.com/vedhavyas/go-subkey" -) - -func EventParser(api *SubstrateAPI, h types.Hash, eventParse string) { - retriever, err := retriever.NewDefaultEventRetriever(state.NewEventProvider(api.RPC.State), api.RPC.State) - if err != nil { - log.Printf("Couldn't create event retriever") - } - - events, err := retriever.GetEvents(h) - - if err != nil { - log.Printf("Couldn't retrieve events") - } - - switch eventParse { - case "DataSubmitted": - ParseDataSubmitted(events) - case "ApplicationKeyCreated": - parseApplicationKeyCreated(events) - case "ApplicationKeySet": - parseApplicationKeySet(events) - case "BalanceTransfer": - parseBalanceTransfer(events) - case "Bond": - parseBond(events) - } -} -func ParseDataSubmitted(events []*parser.Event) { - for _, event := range events { - if event.Name == "DataAvailability.DataSubmitted" { - from, _ := registry.ProcessDecodedFieldValue[*types.AccountID]( - event.Fields, - func(fieldIndex int, field *registry.DecodedField) bool { - - return field.Name == "sp_core.crypto.AccountId32.who" - }, - func(value any) (*types.AccountID, error) { - fields, ok := value.(registry.DecodedFields) - - if !ok { - return nil, fmt.Errorf("unexpected value: %v", value) - } - - accByteSlice, err := registry.GetDecodedFieldAsSliceOfType[types.U8](fields, func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 0 - }) - - if err != nil { - return nil, err - } - - var accBytes []byte - - for _, accByte := range accByteSlice { - accBytes = append(accBytes, byte(accByte)) - } - - return types.NewAccountID(accBytes) - }, - ) - // a := from.ToHexString() - - // // add, _ := types.NewAddressFromHexAccountID(a) - // fmt.Println(from) - // fmt.Printf("from address read from event: %s \n", a) - has := subkey.SS58Encode(from.ToBytes(), 42) - fmt.Printf("from address read from event: %s \n", has) - dataHash, err := registry.ProcessDecodedFieldValue[*types.Hash]( - event.Fields, - func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 1 - }, - func(value any) (*types.Hash, error) { - fields, ok := value.(registry.DecodedFields) - if !ok { - return nil, fmt.Errorf("unexpected value: %v", value) - } - - hashByteSlice, err := registry.GetDecodedFieldAsSliceOfType[types.U8](fields, func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 0 - }) - - if err != nil { - return nil, err - } - - var hashBytes []byte - for _, hashByte := range hashByteSlice { - hashBytes = append(hashBytes, byte(hashByte)) - } - - hash := types.NewHash(hashBytes) - return &hash, nil - }, - ) - if err != nil { - fmt.Printf("DataHash parsing err: %s\n", err.Error()) - } else if dataHash == nil { - fmt.Println("DataHash is nil") - } else { - fmt.Printf("DataHash read from event: %s \n", dataHash.Hex()) - } - - } - parseTransactionFee(event) - } -} - -func parseTransactionFee(event *parser.Event) { - if event.Name == "TransactionPayment.TransactionFeePaid" { - - amount, err := registry.GetDecodedFieldAsType[types.U128]( - event.Fields, - func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 1 - }, - ) - if err != nil { - fmt.Printf("Amount parsing err: %s\n", err.Error()) - } - fmt.Printf("Actual Fee from TransactionPayment.TransactionFeePaid event: %s \n", convInt(amount.String())) - if err != nil { - fmt.Printf("Balances.Deposit.Who: %s\n", err.Error()) - } - } - -} - -func parseApplicationKeyCreated(events []*parser.Event) { - for _, event := range events { - if event.Name == "DataAvailability.ApplicationKeyCreated" { - owner, _ := registry.ProcessDecodedFieldValue[*types.AccountID]( - event.Fields, - func(fieldIndex int, field *registry.DecodedField) bool { - - return field.Name == "sp_core.crypto.AccountId32.owner" - }, - func(value any) (*types.AccountID, error) { - fields, ok := value.(registry.DecodedFields) - - if !ok { - return nil, fmt.Errorf("unexpected value: %v", value) - } - - accByteSlice, err := registry.GetDecodedFieldAsSliceOfType[types.U8](fields, func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 0 - }) - - if err != nil { - return nil, err - } - - var accBytes []byte - - for _, accByte := range accByteSlice { - accBytes = append(accBytes, byte(accByte)) - } - - return types.NewAccountID(accBytes) - }, - ) - // a := from.ToHexString() - - // // add, _ := types.NewAddressFromHexAccountID(a) - // fmt.Println(from) - // fmt.Printf("from address read from event: %s \n", a) - has := subkey.SS58Encode(owner.ToBytes(), 42) - fmt.Printf("from address read from event: %s \n", has) - - id, err := registry.ProcessDecodedFieldValue[types.UCompact]( - event.Fields, - func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 2 - }, - func(value any) (types.UCompact, error) { - fields, ok := value.(registry.DecodedFields) - if !ok { - return types.NewUCompact(big.NewInt(0)), fmt.Errorf("unexpected value type: %T", value) - } - - // Assuming the UCompact value is the first (and only) field in this struct - ucompact, err := registry.GetDecodedFieldAsType[types.UCompact](fields, func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 0 - }) - - if err != nil { - return types.NewUCompact(big.NewInt(0)), fmt.Errorf("error getting UCompact field: %w", err) - } - - return ucompact, nil - }, - ) - if err != nil { - fmt.Printf("AppId parsing err: %s\n", err.Error()) - } else { - fmt.Println(id.Int64()) - } - - appKey, err := registry.ProcessDecodedFieldValue[types.Bytes]( - event.Fields, - func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 0 // Adjust this index if needed - }, - func(value any) (types.Bytes, error) { - fields, ok := value.(registry.DecodedFields) - if !ok { - return nil, fmt.Errorf("unexpected value type: %T", value) - } - - // The BoundedVec is likely represented as a slice of U8 - byteSlice, err := registry.GetDecodedFieldAsSliceOfType[types.U8](fields, func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 0 - }) - - if err != nil { - return nil, fmt.Errorf("error getting byte slice: %w", err) - } - - // Convert the slice of U8 to types.Bytes - bytes := make(types.Bytes, len(byteSlice)) - for i, b := range byteSlice { - bytes[i] = byte(b) - } - - return bytes, nil - }, - ) - - if err != nil { - fmt.Printf("AppKey parsing err: %s\n", err.Error()) - } else { - // Convert Bytes to string for printing - stringValue := string(appKey) - fmt.Printf("AppKey from event (as string): %s\n", stringValue) - - // If you also want to see the hex representation: - hexString := hex.EncodeToString(appKey) - fmt.Printf("AppKey from event (as hex): 0x%s\n", hexString) - } - - } - parseTransactionFee(event) - } -} - -func parseApplicationKeySet(events []*parser.Event) { - for _, event := range events { - if event.Name == "DataAvailability.ApplicationKeySet" { - owner, _ := registry.ProcessDecodedFieldValue[*types.AccountID]( - event.Fields, - func(fieldIndex int, field *registry.DecodedField) bool { - - return field.Name == "sp_core.crypto.AccountId32.owner" - }, - func(value any) (*types.AccountID, error) { - fields, ok := value.(registry.DecodedFields) - - if !ok { - return nil, fmt.Errorf("unexpected value: %v", value) - } - - accByteSlice, err := registry.GetDecodedFieldAsSliceOfType[types.U8](fields, func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 0 - }) - - if err != nil { - return nil, err - } - - var accBytes []byte - - for _, accByte := range accByteSlice { - accBytes = append(accBytes, byte(accByte)) - } - - return types.NewAccountID(accBytes) - }, - ) - // a := from.ToHexString() - - // // add, _ := types.NewAddressFromHexAccountID(a) - // fmt.Println(from) - // fmt.Printf("from address read from event: %s \n", a) - has := subkey.SS58Encode(owner.ToBytes(), 42) - fmt.Printf("from address read from event: %s \n", has) - - id, err := registry.ProcessDecodedFieldValue[types.UCompact]( - event.Fields, - func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 2 - }, - func(value any) (types.UCompact, error) { - fields, ok := value.(registry.DecodedFields) - if !ok { - return types.NewUCompact(big.NewInt(0)), fmt.Errorf("unexpected value type: %T", value) - } - - // Assuming the UCompact value is the first (and only) field in this struct - ucompact, err := registry.GetDecodedFieldAsType[types.UCompact](fields, func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 0 - }) - - if err != nil { - return types.NewUCompact(big.NewInt(0)), fmt.Errorf("error getting UCompact field: %w", err) - } - - return ucompact, nil - }, - ) - if err != nil { - fmt.Printf("AppId parsing err: %s\n", err.Error()) - } else { - fmt.Println(id.Int64()) - } - - appKey, err := registry.ProcessDecodedFieldValue[types.Bytes]( - event.Fields, - func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 0 // Adjust this index if needed - }, - func(value any) (types.Bytes, error) { - fields, ok := value.(registry.DecodedFields) - if !ok { - return nil, fmt.Errorf("unexpected value type: %T", value) - } - - // The BoundedVec is likely represented as a slice of U8 - byteSlice, err := registry.GetDecodedFieldAsSliceOfType[types.U8](fields, func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 0 - }) - - if err != nil { - return nil, fmt.Errorf("error getting byte slice: %w", err) - } - - // Convert the slice of U8 to types.Bytes - bytes := make(types.Bytes, len(byteSlice)) - for i, b := range byteSlice { - bytes[i] = byte(b) - } - - return bytes, nil - }, - ) - - if err != nil { - fmt.Printf("AppKey parsing err: %s\n", err.Error()) - } else { - // Convert Bytes to string for printing - stringValue := string(appKey) - fmt.Printf("AppKey from event (as string): %s\n", stringValue) - - // If you also want to see the hex representation: - hexString := hex.EncodeToString(appKey) - fmt.Printf("AppKey from event (as hex): 0x%s\n", hexString) - } - - } - parseTransactionFee(event) - } -} - -func parseBalanceTransfer(events []*parser.Event) { - for _, event := range events { - if event.Name == "Balances.Transfer" { - from, err := registry.ProcessDecodedFieldValue[*types.AccountID]( - event.Fields, - func(fieldIndex int, field *registry.DecodedField) bool { - - return field.Name == "sp_core.crypto.AccountId32.from" - }, - func(value any) (*types.AccountID, error) { - fields, ok := value.(registry.DecodedFields) - - if !ok { - return nil, fmt.Errorf("unexpected value: %v", value) - } - - accByteSlice, err := registry.GetDecodedFieldAsSliceOfType[types.U8](fields, func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 0 - }) - - if err != nil { - return nil, err - } - - var accBytes []byte - - for _, accByte := range accByteSlice { - accBytes = append(accBytes, byte(accByte)) - } - - return types.NewAccountID(accBytes) - }, - ) - a := from.ToHexString() - - // // add, _ := types.NewAddressFromHexAccountID(a) - // fmt.Println(from) - fmt.Printf("from address read from event: %s \n", a) - - to, err := registry.ProcessDecodedFieldValue[*types.AccountID]( - event.Fields, - - func(fieldIndex int, field *registry.DecodedField) bool { - - return field.Name == "sp_core.crypto.AccountId32.to" - }, - func(value any) (*types.AccountID, error) { - fields, ok := value.(registry.DecodedFields) - - if !ok { - return nil, fmt.Errorf("unexpected value: %v", value) - } - - accByteSlice, err := registry.GetDecodedFieldAsSliceOfType[types.U8](fields, func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 0 - }) - - if err != nil { - return nil, err - } - - var accBytes []byte - - for _, accByte := range accByteSlice { - accBytes = append(accBytes, byte(accByte)) - } - - return types.NewAccountID(accBytes) - }, - ) - if err != nil { - fmt.Printf("TO parsing err: %s\n", err.Error()) - } - fmt.Printf("To address read from event: %s \n", to.ToHexString()) - amount, err := registry.GetDecodedFieldAsType[types.U128]( - event.Fields, - func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 2 - }, - ) - if err != nil { - fmt.Printf("Amount parsing err: %s\n", err.Error()) - } - fmt.Printf("Amount transferred : %s \n", convInt(amount.String())) - if err != nil { - fmt.Printf("Balances.Deposit.Who: %s\n", err.Error()) - } - } - parseTransactionFee(event) - } -} - -func parseBond(events []*parser.Event) { - for _, event := range events { - if event.Name == "Staking.Bonded" { - from, err := registry.ProcessDecodedFieldValue[*types.AccountID]( - event.Fields, - func(fieldIndex int, field *registry.DecodedField) bool { - - return field.Name == "sp_core.crypto.AccountId32.stash" - }, - func(value any) (*types.AccountID, error) { - fields, ok := value.(registry.DecodedFields) - - if !ok { - return nil, fmt.Errorf("unexpected value: %v", value) - } - - accByteSlice, err := registry.GetDecodedFieldAsSliceOfType[types.U8](fields, func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 0 - }) - - if err != nil { - return nil, err - } - - var accBytes []byte - - for _, accByte := range accByteSlice { - accBytes = append(accBytes, byte(accByte)) - } - - return types.NewAccountID(accBytes) - }, - ) - a := from.ToHexString() - - // // add, _ := types.NewAddressFromHexAccountID(a) - // fmt.Println(from) - fmt.Printf("stash address read from event: %s \n", a) - - amount, err := registry.GetDecodedFieldAsType[types.U128]( - event.Fields, - func(fieldIndex int, field *registry.DecodedField) bool { - return fieldIndex == 1 - }, - ) - if err != nil { - fmt.Printf("Amount parsing err: %s\n", err.Error()) - } - fmt.Printf("Amount staked : %s \n", convInt(amount.String())) - if err != nil { - fmt.Printf("Amount staked: %s\n", err.Error()) - } - } - parseTransactionFee(event) - } -} diff --git a/avail-go/src/sdk/helper.go b/avail-go/src/sdk/helper.go deleted file mode 100644 index e8a550798..000000000 --- a/avail-go/src/sdk/helper.go +++ /dev/null @@ -1,359 +0,0 @@ -package sdk - -import ( - "crypto/rand" - "encoding/hex" - "encoding/json" - "fmt" - "log" - "math/big" - "strings" - - "avail-go-sdk/src/rpc" - - "github.com/centrifuge/go-substrate-rpc-client/v4/scale" - "github.com/centrifuge/go-substrate-rpc-client/v4/signature" - "github.com/centrifuge/go-substrate-rpc-client/v4/types" - "github.com/centrifuge/go-substrate-rpc-client/v4/types/codec" - "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/vedhavyas/go-subkey" - "golang.org/x/crypto/blake2b" -) - -func ConvertMultiAddress(receiver string) (types.MultiAddress, error) { - _, pubkeyBytes, _ := subkey.SS58Decode(receiver) - address := subkey.EncodeHex(pubkeyBytes) - - dest, err := types.NewMultiAddressFromHexAccountID(address) - if err != nil { - _ = fmt.Errorf("cannot create address from given hex:%w", err) - return types.MultiAddress{}, err - } - return dest, nil -} - -type BigInt struct { - *big.Int -} - -func ConvertToBondAmount(input int64) *big.Int { - // Create a new big.Int for the input - inputBig := big.NewInt(input) - - // Create a big.Int for 10^18 - multiplier := new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil) - - // Multiply input by 10^18 - result := new(big.Int).Mul(inputBig, multiplier) - - return result -} - -// UnmarshalJSON defines custom unmarshalling for BigInt. -func (bi *BigInt) UnmarshalJSON(data []byte) error { - // Unmarshal as raw JSON string - var rawString string - if err := json.Unmarshal(data, &rawString); err != nil { - return err - } - - // Remove 0x prefix if present - str := strings.TrimPrefix(rawString, "0x") - - // Initialize bi.Int if it's nil - if bi.Int == nil { - bi.Int = new(big.Int) - } - - // If the string is empty, set bi to zero - if str == "" { - bi.SetInt64(0) - return nil - } - - // Parse the string in base 16 - _, success := bi.SetString(str, 16) - if !success { - return fmt.Errorf("invalid hex string") - } - - return nil -} - -func FormatBN(n BigInt) string { - s := n.String() // Convert number to string - var result strings.Builder - count := 0 - - for i := len(s) - 1; i >= 0; i-- { - if count == 3 { - result.WriteString(",") - count = 0 - } - result.WriteByte(s[i]) - count++ - } - - // Reverse the string to get the correct order - reversed := result.String() - var formatted strings.Builder - for i := len(reversed) - 1; i >= 0; i-- { - formatted.WriteByte(reversed[i]) - } - - return formatted.String() -} -func RandToken(n int) (string, error) { - bytes := make([]byte, n) - if _, err := rand.Read(bytes); err != nil { - return "", err - } - return hex.EncodeToString(bytes), nil -} - -func KeyringFromSeed(seed string) (signature.KeyringPair, error) { - return signature.KeyringPairFromSecret(seed, 42) -} - -type Bytes []byte - -func NewBytes(b []byte) Bytes { - return Bytes(b) -} - -func EncodeToHex(hash interface{}) (string, error) { - return codec.EncodeToHex(hash) -} - -func convInt(val string) string { - bigIntValue := new(big.Int) - bigIntValue.SetString(val, 10) - - divisor := new(big.Int) - divisor.SetString("1000000000000000000", 10) - - bigFloatValue := new(big.Float).SetInt(bigIntValue) - divisorFloat := new(big.Float).SetInt(divisor) - result := new(big.Float).Quo(bigFloatValue, divisorFloat) - - x := (result.Text('f', 18)) - return x -} - -func CreateChannel() chan types.Hash { - c := make(chan types.Hash, 1) - return c -} - -func ExistentialDeposit(api *SubstrateAPI) { - - meta, err := api.RPC.State.GetMetadataLatest() - if err != nil { - panic(fmt.Sprintf("cannot get metadata: %v", err)) - } - var existentialDeposit types.U128 - - for _, mod := range meta.AsMetadataV14.Pallets { - if string(mod.Name) == "Balances" { - for _, constant := range mod.Constants { - if string(constant.Name) == "ExistentialDeposit" { - err = codec.Decode(constant.Value, &existentialDeposit) - if err != nil { - log.Fatalf("Failed to decode ExistentialDeposit: %v", err) - } - fmt.Printf("Existential Deposit: %d\n", existentialDeposit) - return - } - } - } - } - - fmt.Printf("Existential Deposit: %d\n", existentialDeposit) -} - -func NewCall(api *SubstrateAPI, callName string, args ...interface{}) (types.Call, error) { - meta, err := api.RPC.State.GetMetadataLatest() - if err != nil { - return types.Call{}, err - } - return types.NewCall(meta, callName, args...) -} - -func NewHashFromHexString(hexStr string) (types.Hash, error) { - return types.NewHashFromHexString(hexStr) -} - -func NewU256(value *big.Int) types.U256 { - return types.NewU256(*value) -} - -func NewMultiAddressFromHexAccountID(hexStr string) (types.MultiAddress, error) { - return types.NewMultiAddressFromHexAccountID(hexStr) -} - -func NewMultiAddressFromAccountID(accountID []byte) (types.MultiAddress, error) { - return types.NewMultiAddressFromAccountID(accountID) -} - -func NewU8(value uint8) types.U8 { - return types.U8(value) -} - -func NewU32(value uint32) types.U32 { - return types.U32(value) -} - -func NewU64(value uint64) types.U64 { - return types.U64(value) -} - -func NewU128(value *big.Int) types.U128 { - return types.NewU128(*value) -} - -func KeyringPairFromSecret(seed string, keyType uint16) (signature.KeyringPair, error) { - return signature.KeyringPairFromSecret(seed, keyType) -} - -type WaitFor int - -const ( - BlockInclusion WaitFor = iota + 1 - BlockFinalization -) - -func (w WaitFor) String() string { - return [...]string{"BlockInclusion", "BlockFinalization"}[w-1] -} - -// EnumIndex - Creating common behavior - give the type a EnumIndex function -func (w WaitFor) EnumIndex() int { - return int(w) -} - -type Payee uint8 - -const ( - Staked WaitFor = iota - Stash - Controller - Account - None -) - -func (w Payee) String() string { - return [...]string{"Staked", "Stash", "Controller", "Account", "None"}[w] -} - -// EnumIndex - Creating common behavior - give the type a EnumIndex function -func (w Payee) EnumIndex() uint8 { - return uint8(w) -} - -func GetData(hash types.Hash, api *SubstrateAPI, txHash types.Hash) error { - block, err := rpc.GetAvailBlock(hash, api.Client) - if err != nil { - return fmt.Errorf("cannot get block by hash:%w", err) - } - for _, ext := range block.Block.Extrinsics { - - // these values below are specific indexes only for data submission, differs with each extrinsic - if ext.IsSigned() && ext.Method.CallIndex.SectionIndex == 29 && ext.Method.CallIndex.MethodIndex == 1 { - enc, _ := EncodeToHex(ext) - cleanedHexString := strings.TrimPrefix(enc, "0x") - bytes, err := hex.DecodeString(cleanedHexString) - if err != nil { - log.Fatal(err) - } - hash := blake2b.Sum256(bytes) - txHashDecoded := hexutil.Encode(hash[:]) - if txHashDecoded == txHash.Hex() { - arg := ext.Method.Args - str := string(arg) - slice := str[1:] - - fmt.Println("Data retrieved:", slice) - } - } - } - return nil -} - -type DispatchFeeModifier struct { - WeightMaximumFee types.U128 - WeightFeeDivider types.U32 - WeightFeeMultiplier types.U32 -} - -// Encode implements scale.Encodeable -func (d DispatchFeeModifier) Encode(encoder scale.Encoder) error { - // Encode WeightMaximumFee - if err := encoder.PushByte(1); err != nil { // 1 for Some - return err - } - if err := encoder.Encode(d.WeightMaximumFee); err != nil { - return err - } - - // Encode WeightFeeDivider - if err := encoder.PushByte(1); err != nil { // 1 for Some - return err - } - if err := encoder.Encode(d.WeightFeeDivider); err != nil { - return err - } - - // Encode WeightFeeMultiplier - if err := encoder.PushByte(1); err != nil { // 1 for Some - return err - } - if err := encoder.Encode(d.WeightFeeMultiplier); err != nil { - return err - } - - return nil -} - -// Decode implements scale.Decodeable -func (d *DispatchFeeModifier) Decode(decoder scale.Decoder) error { - // Decode WeightMaximumFee - optionByte, err := decoder.ReadOneByte() - if err != nil { - return err - } - if optionByte == 1 { // Some - if err := decoder.Decode(&d.WeightMaximumFee); err != nil { - return err - } - } else if optionByte != 0 { // Not None (0) or Some (1) - return fmt.Errorf("invalid option byte for WeightMaximumFee: %d", optionByte) - } - - // Decode WeightFeeDivider - optionByte, err = decoder.ReadOneByte() - if err != nil { - return err - } - if optionByte == 1 { // Some - if err := decoder.Decode(&d.WeightFeeDivider); err != nil { - return err - } - } else if optionByte != 0 { // Not None (0) or Some (1) - return fmt.Errorf("invalid option byte for WeightFeeDivider: %d", optionByte) - } - - // Decode WeightFeeMultiplier - optionByte, err = decoder.ReadOneByte() - if err != nil { - return err - } - if optionByte == 1 { // Some - if err := decoder.Decode(&d.WeightFeeMultiplier); err != nil { - return err - } - } else if optionByte != 0 { // Not None (0) or Some (1) - return fmt.Errorf("invalid option byte for WeightFeeMultiplier: %d", optionByte) - } - - return nil -} diff --git a/avail-go/src/sdk/sdk.go b/avail-go/src/sdk/sdk.go deleted file mode 100644 index 165273063..000000000 --- a/avail-go/src/sdk/sdk.go +++ /dev/null @@ -1,32 +0,0 @@ -package sdk - -import ( - "github.com/centrifuge/go-substrate-rpc-client/v4/client" - "github.com/centrifuge/go-substrate-rpc-client/v4/rpc" -) - -type SubstrateAPI struct { - RPC *rpc.RPC - Client client.Client -} - -func NewSDK(url string) (*SubstrateAPI, error) { - cl, err := client.Connect(url) - if err != nil { - return nil, err - } - - newRPC, err := rpc.NewRPC(cl) - if err != nil { - return nil, err - } - - return &SubstrateAPI{ - RPC: newRPC, - Client: cl, - }, nil -} - -func (api *SubstrateAPI) Close() { - api.Client.Close() -} diff --git a/avail-go/src/sdk/tx/transactions.go b/avail-go/src/sdk/tx/transactions.go deleted file mode 100644 index ce779a5a2..000000000 --- a/avail-go/src/sdk/tx/transactions.go +++ /dev/null @@ -1,470 +0,0 @@ -package tx - -import ( - "avail-go-sdk/src/sdk" - "avail-go-sdk/src/sdk/types" - "errors" - "fmt" - "math/big" - "strconv" - - "github.com/vedhavyas/go-subkey/v2" -) - -type WaitFor int - -const ( - BlockInclusion WaitFor = iota + 1 - BlockFinalization -) - -func (w WaitFor) String() string { - return [...]string{"BlockInclusion", "BlockFinalization"}[w-1] -} - -// EnumIndex - Creating common behavior - give the type a EnumIndex function -func (w WaitFor) EnumIndex() int { - return int(w) -} - -// SubmitData submits data to the chain -func SubmitData(api *sdk.SubstrateAPI, seed string, AppID int, data string, WaitForInclusion sdk.WaitFor) (types.Hash, types.Hash, error) { - keyringPair, err := sdk.KeyringFromSeed(seed) - if err != nil { - panic(fmt.Sprintf("cannot create KeyPair:%v", err)) - } - BlockHashCh2 := make(chan types.Hash) - txHashCh2 := make(chan types.Hash) - go func() { - err := sdk.NewExtrinsicWatch(api, "DataAvailability.submit_data", keyringPair, BlockHashCh2, txHashCh2, AppID, WaitForInclusion, sdk.NewBytes([]byte(data))) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - close(BlockHashCh2) - close(txHashCh2) - return - } - fmt.Println("Data submitted successfully") - }() - blockHash := <-BlockHashCh2 - txHash := <-txHashCh2 - return blockHash, txHash, nil -} - -func CreateApplicationKey(api *sdk.SubstrateAPI, seed string, data string, WaitForInclusion sdk.WaitFor) (types.Hash, types.Hash, error) { - keyringPair, err := sdk.KeyringFromSeed(seed) - if err != nil { - panic(fmt.Sprintf("cannot create KeyPair:%v", err)) - } - BlockHashCh2 := make(chan types.Hash) - txHashCh2 := make(chan types.Hash) - go func() { - err := sdk.NewExtrinsicWatch(api, "DataAvailability.create_application_key", keyringPair, BlockHashCh2, txHashCh2, 0, WaitForInclusion, sdk.NewBytes([]byte("22222"))) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - close(BlockHashCh2) - close(txHashCh2) - return - } - fmt.Println("Data submitted successfully") - }() - blockHash := <-BlockHashCh2 - txHash := <-txHashCh2 - return blockHash, txHash, nil - -} - -func SetApplicationKey(api *sdk.SubstrateAPI, seed string, WaitForInclusion sdk.WaitFor, oldKey string, newKey string) (types.Hash, types.Hash, error) { - keyringPair, err := sdk.KeyringFromSeed(seed) - if err != nil { - panic(fmt.Sprintf("cannot create KeyPair:%v", err)) - } - BlockHashCh2 := make(chan types.Hash) - txHashCh2 := make(chan types.Hash) - go func() { - call, err := sdk.NewCall(api, "DataAvailability.set_application_key", sdk.NewBytes([]byte(oldKey)), sdk.NewBytes([]byte(newKey))) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - } - err = sdk.NewExtrinsicWatch(api, "Sudo.sudo", keyringPair, BlockHashCh2, txHashCh2, 0, WaitForInclusion, call) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - close(BlockHashCh2) - close(txHashCh2) - return - } - fmt.Println("Transaction submitted successfully") - }() - blockHash := <-BlockHashCh2 - txHash := <-txHashCh2 - return blockHash, txHash, nil - -} - -func SetSubmitDataFeeModifier(api *sdk.SubstrateAPI, seed string, WaitForInclusion sdk.WaitFor, modifier sdk.DispatchFeeModifier) (types.Hash, types.Hash, error) { - keyringPair, err := sdk.KeyringFromSeed(seed) - if err != nil { - panic(fmt.Sprintf("cannot create KeyPair:%v", err)) - } - BlockHashCh2 := make(chan types.Hash) - txHashCh2 := make(chan types.Hash) - - go func() { - call, err := sdk.NewCall(api, "DataAvailability.set_submit_data_fee_modifier", modifier) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - } - err = sdk.NewExtrinsicWatch(api, "Sudo.sudo", keyringPair, BlockHashCh2, txHashCh2, 0, WaitForInclusion, call) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - close(BlockHashCh2) - close(txHashCh2) - return - } - fmt.Println("Transaction submitted successfully") - }() - blockHash := <-BlockHashCh2 - txHash := <-txHashCh2 - return blockHash, txHash, nil - -} - -func SubmitBlockLength(api *sdk.SubstrateAPI, seed string, WaitForInclusion sdk.WaitFor, rows uint32, cols uint32) (types.Hash, types.Hash, error) { - keyringPair, err := sdk.KeyringFromSeed(seed) - if err != nil { - panic(fmt.Sprintf("cannot create KeyPair:%v", err)) - } - BlockHashCh2 := make(chan types.Hash) - txHashCh2 := make(chan types.Hash) - - go func() { - call, err := sdk.NewCall(api, "DataAvailability.submit_block_length_proposal", sdk.NewU32(rows), sdk.NewU32(cols)) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - } - err = sdk.NewExtrinsicWatch(api, "Sudo.sudo", keyringPair, BlockHashCh2, txHashCh2, 0, WaitForInclusion, call) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - close(BlockHashCh2) - close(txHashCh2) - return - } - fmt.Println("Data submitted successfully") - }() - blockHash := <-BlockHashCh2 - txHash := <-txHashCh2 - return blockHash, txHash, nil - -} - -func Bond(api *sdk.SubstrateAPI, seed string, WaitForInclusion sdk.WaitFor, amount int64, Payee sdk.Payee) (types.Hash, types.Hash, error) { - keyringPair, err := sdk.KeyringFromSeed(seed) - if err != nil { - panic(fmt.Sprintf("cannot create KeyPair:%v", err)) - } - bondAmount := sdk.ConvertToBondAmount(amount) - - newBondAmount := new(big.Int) - newBondAmount.Set(bondAmount) - - BlockHashCh2 := make(chan types.Hash) - txHashCh2 := make(chan types.Hash) - bondAmountUCompact := types.NewUCompact(newBondAmount) - go func() { - err = sdk.NewExtrinsicWatch(api, "Staking.bond", keyringPair, BlockHashCh2, txHashCh2, 0, WaitForInclusion, bondAmountUCompact, sdk.NewU8(Payee.EnumIndex())) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - close(BlockHashCh2) - close(txHashCh2) - return - } - fmt.Println("Data submitted successfully") - }() - blockHash := <-BlockHashCh2 - txHash := <-txHashCh2 - return blockHash, txHash, nil -} - -func BondExtra(api *sdk.SubstrateAPI, seed string, WaitForInclusion sdk.WaitFor, amount int64) (types.Hash, types.Hash, error) { - keyringPair, err := sdk.KeyringFromSeed(seed) - if err != nil { - panic(fmt.Sprintf("cannot create KeyPair:%v", err)) - } - BlockHashCh2 := make(chan types.Hash) - txHashCh2 := make(chan types.Hash) - bondAmount := sdk.ConvertToBondAmount(amount) - - newBondAmount := new(big.Int) - newBondAmount.Set(bondAmount) - bondAmountUCompact := types.NewUCompact(newBondAmount) - - go func() { - err = sdk.NewExtrinsicWatch(api, "Staking.bond_extra", keyringPair, BlockHashCh2, txHashCh2, 0, WaitForInclusion, bondAmountUCompact) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - close(BlockHashCh2) - close(txHashCh2) - return - } - fmt.Println("Data submitted successfully") - }() - blockHash := <-BlockHashCh2 - txHash := <-txHashCh2 - return blockHash, txHash, nil -} - -func Chill(api *sdk.SubstrateAPI, seed string, WaitForInclusion sdk.WaitFor) (types.Hash, types.Hash, error) { - keyringPair, err := sdk.KeyringFromSeed(seed) - if err != nil { - panic(fmt.Sprintf("cannot create KeyPair:%v", err)) - } - BlockHashCh2 := make(chan types.Hash) - txHashCh2 := make(chan types.Hash) - - go func() { - err = sdk.NewExtrinsicWatch(api, "Staking.chill", keyringPair, BlockHashCh2, txHashCh2, 0, WaitForInclusion) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - close(BlockHashCh2) - close(txHashCh2) - return - } - fmt.Println("Data submitted successfully") - }() - blockHash := <-BlockHashCh2 - txHash := <-txHashCh2 - return blockHash, txHash, nil -} - -func ChillOther(api *sdk.SubstrateAPI, seed string, WaitForInclusion sdk.WaitFor, stash string) (types.Hash, types.Hash, error) { - keyringPair, err := sdk.KeyringFromSeed(seed) - if err != nil { - panic(fmt.Sprintf("cannot create KeyPair:%v", err)) - } - fmt.Println(keyringPair) - _, pubkeyBytes, _ := subkey.SS58Decode(stash) - hexString := subkey.EncodeHex(pubkeyBytes) - - fmt.Println(hexString) - dest, err := sdk.NewMultiAddressFromHexAccountID(hexString) - if err != nil { - return types.Hash{}, types.Hash{}, err - } - fmt.Println(dest) - BlockHashCh2 := make(chan types.Hash) - txHashCh2 := make(chan types.Hash) - - go func() { - err = sdk.NewExtrinsicWatch(api, "Staking.chill_other", keyringPair, BlockHashCh2, txHashCh2, 0, WaitForInclusion, dest.AsID) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - close(BlockHashCh2) - close(txHashCh2) - return - } - fmt.Println("Data submitted successfully") - }() - blockHash := <-BlockHashCh2 - txHash := <-txHashCh2 - return blockHash, txHash, nil -} - -func Nominate(api *sdk.SubstrateAPI, seed string, WaitForInclusion sdk.WaitFor, stash []string) (types.Hash, types.Hash, error) { - keyringPair, err := sdk.KeyringFromSeed(seed) - if err != nil { - panic(fmt.Sprintf("cannot create KeyPair:%v", err)) - } - var dest []types.MultiAddress - for _, v := range stash { - _, pubkeyBytes, _ := subkey.SS58Decode(v) - hexString := subkey.EncodeHex(pubkeyBytes) - d, err := sdk.NewMultiAddressFromHexAccountID(hexString) - if err != nil { - return types.Hash{}, types.Hash{}, err - } - dest = append(dest, d) - } - - BlockHashCh2 := make(chan types.Hash) - txHashCh2 := make(chan types.Hash) - - go func() { - err = sdk.NewExtrinsicWatch(api, "Staking.nominate", keyringPair, BlockHashCh2, txHashCh2, 0, WaitForInclusion, dest) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - close(BlockHashCh2) - close(txHashCh2) - return - } - fmt.Println("Data submitted successfully") - }() - blockHash := <-BlockHashCh2 - txHash := <-txHashCh2 - return blockHash, txHash, nil -} - -func Unbond(api *sdk.SubstrateAPI, seed string, WaitForInclusion sdk.WaitFor, amount types.UCompact) (types.Hash, types.Hash, error) { - keyringPair, err := sdk.KeyringFromSeed(seed) - if err != nil { - panic(fmt.Sprintf("cannot create KeyPair:%v", err)) - } - BlockHashCh2 := make(chan types.Hash) - txHashCh2 := make(chan types.Hash) - - go func() { - err = sdk.NewExtrinsicWatch(api, "Staking.unbond", keyringPair, BlockHashCh2, txHashCh2, 0, WaitForInclusion, amount) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - close(BlockHashCh2) - close(txHashCh2) - return - } - fmt.Println("Data submitted successfully") - }() - blockHash := <-BlockHashCh2 - txHash := <-txHashCh2 - return blockHash, txHash, nil -} - -func Validate(api *sdk.SubstrateAPI, seed string, WaitForInclusion sdk.WaitFor, commissionNum int) (types.Hash, types.Hash, error) { - keyringPair, err := sdk.KeyringFromSeed(seed) - if err != nil { - panic(fmt.Sprintf("cannot create KeyPair:%v", err)) - } - BlockHashCh2 := make(chan types.Hash) - txHashCh2 := make(chan types.Hash) - commissionStr, err := commissionNumberToPerbill(commissionNum) - if err != nil { - fmt.Errorf("failed to convert commission to Perbill: %v", err) - } - - commission, err := strconv.ParseUint(commissionStr, 10, 64) - if err != nil { - fmt.Errorf("failed to parse commission string: %v", err) - } - - // Define the ValidatorPrefs struct manually - type ValidatorPrefs struct { - Commission types.UCompact - Blocked bool - } - - // Create the validator preferences struct - prefs := ValidatorPrefs{ - Commission: types.NewUCompactFromUInt(commission), - Blocked: false, - } - go func() { - err = sdk.NewExtrinsicWatch(api, "Staking.validate", keyringPair, BlockHashCh2, txHashCh2, 0, WaitForInclusion, prefs) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - close(BlockHashCh2) - close(txHashCh2) - return - } - fmt.Println("Data submitted successfully") - }() - blockHash := <-BlockHashCh2 - txHash := <-txHashCh2 - return blockHash, txHash, nil -} - -func commissionNumberToPerbill(value int) (string, error) { - if value < 0 || value > 100 { - return "", errors.New("Commission is limited to the following range: 0 - 100. It cannot be less than 0 or more than 100.") - } - - commission := strconv.Itoa(value) + "0000000" - // For some reason 0 commission is not defined as "0" but as "1". - if commission == "00000000" { - commission = "1" - } - - return commission, nil -} - -func TransferKeepAlive(api *sdk.SubstrateAPI, seed string, WaitForInclusion sdk.WaitFor, dest string, amount types.UCompact) (types.Hash, types.Hash, error) { - keyringPair, err := sdk.KeyringFromSeed(seed) - if err != nil { - panic(fmt.Sprintf("cannot create KeyPair:%v", err)) - } - _, pubkeyBytes, _ := subkey.SS58Decode(dest) - hexString := subkey.EncodeHex(pubkeyBytes) - destAddr, err := sdk.NewMultiAddressFromHexAccountID(hexString) - if err != nil { - return types.Hash{}, types.Hash{}, err - } - BlockHashCh2 := make(chan types.Hash) - txHashCh2 := make(chan types.Hash) - - go func() { - err = sdk.NewExtrinsicWatch(api, "Balances.transfer_keep_alive", keyringPair, BlockHashCh2, txHashCh2, 0, WaitForInclusion, destAddr, amount) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - close(BlockHashCh2) - close(txHashCh2) - return - } - fmt.Println("Transaction submitted successfully") - }() - blockHash := <-BlockHashCh2 - txHash := <-txHashCh2 - return blockHash, txHash, nil -} - -func TransferAllowDeath(api *sdk.SubstrateAPI, seed string, WaitForInclusion sdk.WaitFor, dest string, amount types.UCompact) (types.Hash, types.Hash, error) { - keyringPair, err := sdk.KeyringFromSeed(seed) - if err != nil { - panic(fmt.Sprintf("cannot create KeyPair:%v", err)) - } - _, pubkeyBytes, _ := subkey.SS58Decode(dest) - hexString := subkey.EncodeHex(pubkeyBytes) - destAddr, err := sdk.NewMultiAddressFromHexAccountID(hexString) - if err != nil { - return types.Hash{}, types.Hash{}, err - } - BlockHashCh2 := make(chan types.Hash) - txHashCh2 := make(chan types.Hash) - - go func() { - err = sdk.NewExtrinsicWatch(api, "Balances.transfer_allow_death", keyringPair, BlockHashCh2, txHashCh2, 0, WaitForInclusion, destAddr, amount) - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - close(BlockHashCh2) - close(txHashCh2) - return - } - fmt.Println("Transaction submitted successfully") - }() - blockHash := <-BlockHashCh2 - txHash := <-txHashCh2 - return blockHash, txHash, nil -} - -func TransferAll(api *sdk.SubstrateAPI, seed string, WaitForInclusion sdk.WaitFor, dest string) (types.Hash, types.Hash, error) { - keyringPair, err := sdk.KeyringFromSeed(seed) - if err != nil { - panic(fmt.Sprintf("cannot create KeyPair:%v", err)) - } - _, pubkeyBytes, _ := subkey.SS58Decode(dest) - hexString := subkey.EncodeHex(pubkeyBytes) - destAddr, err := sdk.NewMultiAddressFromHexAccountID(hexString) - if err != nil { - return types.Hash{}, types.Hash{}, err - } - BlockHashCh2 := make(chan types.Hash) - txHashCh2 := make(chan types.Hash) - - go func() { - err = sdk.NewExtrinsicWatch(api, "Balances.transfer_all", keyringPair, BlockHashCh2, txHashCh2, 0, WaitForInclusion, destAddr, sdk.NewU8(1)) //KeepAlive:yes, change to 0 for no - if err != nil { - fmt.Printf("cannot create extrinsic: %v", err) - close(BlockHashCh2) - close(txHashCh2) - return - } - fmt.Println("Transaction submitted successfully") - }() - blockHash := <-BlockHashCh2 - txHash := <-txHashCh2 - return blockHash, txHash, nil -} diff --git a/avail-go/src/sdk/types/types.go b/avail-go/src/sdk/types/types.go deleted file mode 100644 index d96bfc3d2..000000000 --- a/avail-go/src/sdk/types/types.go +++ /dev/null @@ -1,19 +0,0 @@ -package types - -import ( - "github.com/centrifuge/go-substrate-rpc-client/v4/types" -) - -type MultiAddress = types.MultiAddress -type Call = types.Call -type Hash = types.Hash -type U32 = types.U32 -type U264 = types.U64 -type U256 = types.U256 -type U128 = types.U128 -type ChainProperties struct { - IsEthereum bool - SS58Format types.U32 - TokenDecimals types.U32 - TokenSymbol types.Text -} diff --git a/avail-go/src/sdk/types/ucompact.go b/avail-go/src/sdk/types/ucompact.go deleted file mode 100644 index 2e5e41512..000000000 --- a/avail-go/src/sdk/types/ucompact.go +++ /dev/null @@ -1,54 +0,0 @@ -package types - -import ( - "encoding/json" - "math/big" - - "github.com/centrifuge/go-substrate-rpc-client/v4/scale" -) - -type UCompact big.Int - -func NewUCompact(value *big.Int) UCompact { - return UCompact(*value) -} - -func (u *UCompact) Int64() int64 { - i := big.Int(*u) - return i.Int64() -} - -func NewUCompactFromUInt(value uint64) UCompact { - return NewUCompact(new(big.Int).SetUint64(value)) -} - -func (u *UCompact) Decode(decoder scale.Decoder) error { - ui, err := decoder.DecodeUintCompact() - if err != nil { - return err - } - - *u = UCompact(*ui) - return nil -} - -func (u UCompact) Encode(encoder scale.Encoder) error { - err := encoder.EncodeUintCompact(big.Int(u)) - if err != nil { - return err - } - return nil -} - -func (u UCompact) MarshalJSON() ([]byte, error) { - return json.Marshal(u.Int64()) -} - -func (u *UCompact) UnmarshalJSON(b []byte) error { - var i big.Int - if err := json.Unmarshal(b, &i); err != nil { - return err - } - *u = UCompact(i) - return nil -}