77 "os"
88 "os/exec"
99 "path/filepath"
10+ "strconv"
1011 "strings"
1112
1213 cosmossdktypes "github.com/cosmos/cosmos-sdk/types"
@@ -17,6 +18,7 @@ import (
1718 datalayer "github.com/dymensionxyz/roller/data_layer"
1819 "github.com/dymensionxyz/roller/utils/bash"
1920 bashutils "github.com/dymensionxyz/roller/utils/bash"
21+ "github.com/dymensionxyz/roller/utils/config"
2022 "github.com/dymensionxyz/roller/utils/filesystem"
2123 "github.com/dymensionxyz/roller/utils/keys"
2224 "github.com/dymensionxyz/roller/utils/roller"
@@ -374,6 +376,99 @@ func GetRollappParams(hd consts.HubData) (*RaParams, error) {
374376 return & resp , nil
375377}
376378
379+ func GetDrsVersionFromChain (rollappID string , hd consts.HubData ) (string , error ) {
380+ rpc , err := fetchRollappRpcFromChain (rollappID , hd )
381+ if err != nil {
382+ return "" , err
383+ }
384+
385+ params , err := getRollappParamsFromNode (rpc , rollappID )
386+ if err != nil {
387+ return "" , err
388+ }
389+ if params == nil {
390+ return "" , errors .New ("rollapp params response is nil" )
391+ }
392+ return strconv .Itoa (params .DrsVersion ), nil
393+ }
394+
395+ type RollappDaemonParams struct {
396+ Da string `json:"da"`
397+ DrsVersion int `json:"drs_version"`
398+ MinGasPrices cosmossdktypes.DecCoins `json:"min_gas_prices"`
399+ }
400+
401+ func getRollappParamsFromNode (rpcEndpoint , chainID string ) (* RollappDaemonParams , error ) {
402+ rpc := strings .TrimSpace (rpcEndpoint )
403+ if rpc == "" {
404+ rpc = consts .DefaultRollappRPC
405+ }
406+ args := []string {"q" , "rollappparams" , "params" , "--node" , rpc , "-o" , "json" }
407+ if chainID != "" {
408+ args = append (args , "--chain-id" , chainID )
409+ }
410+
411+ cmd := exec .Command (consts .Executables .RollappEVM , args ... )
412+ out , err := bash .ExecCommandWithStdout (cmd )
413+ if err != nil {
414+ return nil , err
415+ }
416+ var resp RollappDaemonParams
417+ if err := json .Unmarshal (out .Bytes (), & resp ); err != nil {
418+ return nil , err
419+ }
420+ return & resp , nil
421+ }
422+
423+ func fetchRollappRpcFromChain (raID string , hd consts.HubData ) (string , error ) {
424+ proposer , err := GetCurrentProposer (raID , hd )
425+ if err != nil {
426+ return "" , err
427+ }
428+ if proposer == "" {
429+ return "" , errors .New ("no proposer found for rollapp" )
430+ }
431+
432+ cmd := exec .Command (
433+ consts .Executables .Dymension ,
434+ "q" , "sequencer" , "show-sequencer" ,
435+ proposer , "-o" , "json" , "--node" , hd .RpcUrl , "--chain-id" , hd .ID ,
436+ )
437+
438+ out , err := bash .ExecCommandWithStdout (cmd )
439+ if err != nil {
440+ return "" , err
441+ }
442+
443+ var resp struct {
444+ Sequencer struct {
445+ Metadata struct {
446+ Rpcs []string `json:"rpcs"`
447+ } `json:"metadata"`
448+ } `json:"sequencer"`
449+ }
450+
451+ if err := json .Unmarshal (out .Bytes (), & resp ); err != nil {
452+ return "" , err
453+ }
454+
455+ if len (resp .Sequencer .Metadata .Rpcs ) == 0 {
456+ return "" , errors .New ("no rpc endpoints found in sequencer metadata" )
457+ }
458+
459+ rpc := strings .TrimSpace (resp .Sequencer .Metadata .Rpcs [0 ])
460+ if rpc == "" {
461+ return "" , errors .New ("empty rpc endpoint in sequencer metadata" )
462+ }
463+
464+ if ! strings .HasPrefix (rpc , "http://" ) && ! strings .HasPrefix (rpc , "https://" ) {
465+ rpc = "https://" + rpc
466+ }
467+ rpc = config .AddHttpsPortIfNeeded (rpc )
468+
469+ return rpc , nil
470+ }
471+
377472func getGenesisFilePath (root string ) string {
378473 return filepath .Join (
379474 RollappConfigDir (root ),
0 commit comments