forked from rollkit/rollkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modified submit block to submit blocks
- Loading branch information
1 parent
d92ead6
commit 773fb54
Showing
4 changed files
with
65 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,89 @@ | ||
package datasubmit | ||
|
||
import ( | ||
//"errors" | ||
"errors" | ||
|
||
gsrpc "github.com/centrifuge/go-substrate-rpc-client/v4" | ||
"github.com/centrifuge/go-substrate-rpc-client/v4/signature" | ||
"github.com/centrifuge/go-substrate-rpc-client/v4/types" | ||
) | ||
|
||
// submit data submits the extrinsic through substrate api | ||
func SubmitData(apiURL string, seed string, appID int, data []byte) (types.Hash, error) { | ||
func SubmitData(apiURL string, seed string, appID int, data []byte) error { | ||
api, err := gsrpc.NewSubstrateAPI(apiURL) | ||
if err != nil { | ||
return types.Hash{}, err | ||
return err | ||
} | ||
|
||
meta, err := api.RPC.State.GetMetadataLatest() | ||
if err != nil { | ||
return types.Hash{}, err | ||
return err | ||
} | ||
|
||
//if app id is greater than 0 then it must be created before submitting data | ||
//err = errors.New("AppID can be 0") | ||
err = errors.New("AppID cant be 0") | ||
if appID == 0 { | ||
return types.Hash{}, err | ||
return err | ||
} | ||
|
||
c, err := types.NewCall(meta, "DataAvailability.submit_data", data) | ||
if err != nil { | ||
return types.Hash{}, err | ||
return err | ||
} | ||
|
||
//Create the extrinsic | ||
ext := types.NewExtrinsic(c) | ||
|
||
genesisHash, err := api.RPC.Chain.GetBlockHash(0) | ||
if err != nil { | ||
return types.Hash{}, err | ||
return err | ||
} | ||
|
||
rv, err := api.RPC.State.GetRuntimeVersionLatest() | ||
if err != nil { | ||
return types.Hash{}, err | ||
return err | ||
} | ||
|
||
keyringPair, err := signature.KeyringPairFromSecret(seed, 42) | ||
if err != nil { | ||
return types.Hash{}, err | ||
return err | ||
} | ||
|
||
key, err := types.CreateStorageKey(meta, "System", "Account", keyringPair.PublicKey) | ||
if err != nil { | ||
return types.Hash{}, err | ||
return err | ||
} | ||
|
||
var accountInfo types.AccountInfo | ||
ok, err := api.RPC.State.GetStorageLatest(key, &accountInfo) | ||
if err != nil || !ok { | ||
return types.Hash{}, err | ||
return err | ||
} | ||
|
||
nonce := uint32(accountInfo.Nonce) | ||
o := types.SignatureOptions{ | ||
BlockHash: genesisHash, | ||
Era: types.ExtrinsicEra{IsMortalEra: false}, | ||
GenesisHash: genesisHash, | ||
Nonce: types.NewUCompactFromUInt(uint64(nonce)), | ||
SpecVersion: rv.SpecVersion, | ||
Tip: types.NewUCompactFromUInt(0), | ||
AppID: types.NewUCompactFromUInt(uint64(appID)), | ||
//AppID: types.NewU32(uint32(appID)), | ||
//AppID: types.U32(types.NewI16(int16(appID))), | ||
//AppID: types.U32(uint32(appID)), | ||
//AppID: types.U32(types.NewU16(uint16(appID))), | ||
BlockHash: genesisHash, | ||
Era: types.ExtrinsicEra{IsMortalEra: false}, | ||
GenesisHash: genesisHash, | ||
Nonce: types.NewUCompactFromUInt(uint64(nonce)), | ||
SpecVersion: rv.SpecVersion, | ||
Tip: types.NewUCompactFromUInt(0), | ||
AppID: types.NewUCompactFromUInt(uint64(appID)), | ||
TransactionVersion: rv.TransactionVersion, | ||
} | ||
|
||
// Sign the transaction using Alice's default account | ||
err = ext.Sign(keyringPair, o) | ||
if err != nil { | ||
return types.Hash{}, err | ||
return err | ||
} | ||
|
||
// Send the extrinsic | ||
hash, err := api.RPC.Author.SubmitExtrinsic(ext) | ||
_, err = api.RPC.Author.SubmitExtrinsic(ext) | ||
if err != nil { | ||
return types.Hash{}, err | ||
return err | ||
} | ||
|
||
return hash, nil | ||
return nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
module github.com/rollkit/rollkit | ||
|
||
|
||
go 1.20 | ||
|
||
require ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters