Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
billettc committed Jul 22, 2024
1 parent fc5273b commit 57914bb
Show file tree
Hide file tree
Showing 5 changed files with 79,033 additions and 80,331 deletions.
166 changes: 84 additions & 82 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func main() {
blockHash, err := types.NewHashFromHexString("0x7720f26b49f715dcc116728db3a0cf00a331418867ad45b9b3505593c050f50c")
blockHash, err := types.NewHashFromHexString("0xad1ce65fb2dde8ee826f2b25999f873f92815224300cd3b747031123f4cb6611")
if err != nil {
log.Fatalf("Failed to create block hash: %v", err)
}
Expand Down Expand Up @@ -62,6 +62,11 @@ func main() {
log.Fatalf("Failed to get extrinsics: %v", err)
}

//metadata, err := api.RPC.State.GetMetadata(blockHash)
//if err != nil {
// log.Fatalf("Failed to get metadata: %v", err)
//}
//
for _, extrinsic := range extrinsics {
parts := strings.Split(extrinsic.Name, ".")
pallet := parts[0]
Expand All @@ -71,90 +76,87 @@ func main() {

switch structName {
case "Timestamp_Set_Call":
now := extrinsic.CallFields[0].Value.(types.UCompact)
nowValue := now.Int64()
c := pbgear.Timestamp_Set_Call{
Now: &pbgear.CompactUint64{
Value: uint64(nowValue),
},
}
fmt.Println(c)
call := from_Timestamp_Set_Call(extrinsic.CallFields)
fmt.Println(call)
case "Balances_TransferKeepAlive_Call":
call := from_Balances_Transfer_Keep_Alive_Call(extrinsic.CallFields)
fmt.Println(call)
case "Gear_Run_Call":
maxGas := extrinsic.CallFields[0].Value.(uint8)
c := pbgear.Gear_Run_Call{
MaxGas: *maxGas,
}
from_Gear_Run_Call(extrinsic.CallFields)
}
}
}

func from_Balances_Transfer_Keep_Alive_Call(callFields []*registry.DecodedField) *pbgear.Balances_TransferKeepAlive_Call {
return &pbgear.Balances_TransferKeepAlive_Call{
Dest: from_balance_dest(callFields[0]),
Value: nil,
}
}

//fmt.Println("---------------------------------------------")
//fmt.Println("- Extrinsics")
//fmt.Println("---------------------------------------------")
//fmt.Println("Number of extrinsics: ", len(extrinsics))
//for _, extrinsic := range extrinsics {
// j, err := json.MarshalIndent(extrinsic, "", " ")
// if err != nil {
// log.Fatalf("Failed to marshal extrinsic: %v", err)
// }
// _ = j
// fmt.Println(string(j))
//}
//
//eventRetriever, err := retriever.NewDefaultEventRetriever(state.NewEventProvider(api.RPC.State), api.RPC.State)
//if err != nil {
// log.Fatalf("Error creating event retriever: %v", err)
//}
//
//events, err := eventRetriever.GetEvents(blockHash)
//if err != nil {
// log.Fatalf("Failed to get events: %v", err)
//}
//
//// fmt.Println("---------------------------------------------")
//// fmt.Println("- Events")
//// fmt.Println("---------------------------------------------")
//// fmt.Println("Number of events: ", len(events))
//
//for _, event := range events {
// j, err := json.MarshalIndent(event, "", " ")
// if err != nil {
// log.Fatalf("Failed to marshal event: %v", err)
// }
// _ = j
//
// // fmt.Println(string(j))
// //log.Printf("Event ID: %x \n", event.EventID)
// //log.Printf("Event Name: %s \n", event.Name)
// //log.Printf("Event Fields Count: %d \n", len(event.Fields))
// //for k, v := range event.Fields {
// // log.Printf("Field Name: %s \n", k)
// // log.Printf("Field Type: %v \n", reflect.TypeOf(v))
// // log.Printf("Field Value: %v \n", v)
// //}
//}
//
//metadata, err := api.RPC.State.GetMetadata(blockHash)
//if err != nil {
// log.Fatalf("Failed to get metadata: %v", err)
//}
//
//m, err := json.MarshalIndent(metadata, "", " ")
//if err != nil {
// log.Fatalf("Failed to marshal extrinsic: %v", err)
//}
//_ = m
//
//// fmt.Println(string(m))
//
//// block0, err := types.NewHashFromHexString("0x1555a60f789e322c607f8b8df062cf0441484897b547028c378509d5e56eec48")
//// if err != nil {
//// log.Fatalf("Failed to create block hash: %v", err)
//// }
//// specVerion, err := api.RPC.State.GetRuntimeVersion(block0)
//// if err != nil {
//// log.Fatalf("Failed to get runtime version: %v", err)
//// }
//
// fmt.Println("Spec Version: ", specVerion.SpecVersion)
func from_balance_dest(in *registry.DecodedField) *pbgear.BalancesDest {
out := &pbgear.BalancesDest{}
switch in.Name {
case "sp_runtime.multiaddress.MultiAddress.dest":
out.Value = from_BalancesDest_Balances_Id(in.Value.(registry.DecodedFields)[0])
}

return out
}

func from_BalancesDest_Balances_Id(in *registry.DecodedField) *pbgear.BalancesDest_Balances_Id {
return &pbgear.BalancesDest_Balances_Id{
Balances_Id: &pbgear.Balances_Id{
Value_0: from_sp_runtime_multi_address_multi_address(in.Value.(registry.DecodedFields)[0]),
},
}
}

func from_sp_runtime_multi_address_multi_address(in *registry.DecodedField) *pbgear.SpCoreCrypto_AccountId32 {
return &pbgear.SpCoreCrypto_AccountId32{Value_0: from_array_u8(in)}
}

func from_array_u8(in *registry.DecodedField) []uint32 {
out := make([]uint32, 0)
for _, value := range in.Value.([]interface{}) {
v := value.(types.U8)
out = append(out, uint32(v))
}
return out
}

func from_Timestamp_Set_Call(callFields []*registry.DecodedField) *pbgear.Timestamp_Set_Call {
return &pbgear.Timestamp_Set_Call{
Now: from_Compact_uint64(callFields[0]),
}
}

func from_Compact_uint64(in *registry.DecodedField) *pbgear.CompactUint64 {
v := in.Value.(types.UCompact)
return &pbgear.CompactUint64{
Value: from_uint64(v),
}
}

func from_uint64(in types.UCompact) uint64 {
return uint64(in.Int64())
}

func from_Gear_Run_Call(callFields []*registry.DecodedField) *pbgear.Gear_Run_Call {
return &pbgear.Gear_Run_Call{
MaxGas: from_optional_uint64(callFields[0]),
}
}

func from_optional_uint64(field *registry.DecodedField) *uint64 {
var out *uint64

if v, ok := field.Value.(uint8); ok {
if v != 0 {
panic("expected none")
}
} else {
out = field.Value.(*uint64)
}
return out
}
Loading

0 comments on commit 57914bb

Please sign in to comment.