Skip to content

Commit

Permalink
add submitTxV6
Browse files Browse the repository at this point in the history
  • Loading branch information
thuannd-teko committed Apr 17, 2024
1 parent 79e81e0 commit 8dcd910
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 58 deletions.
61 changes: 7 additions & 54 deletions cmd/ogmigo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ package main

import (
"context"
"encoding/json"
_ "encoding/json"
"fmt"
"github.com/thuannguyen2010/ogmigo"
"github.com/thuannguyen2010/ogmigo/ouroboros/chainsync"
"github.com/urfave/cli/v2"
"log"
"os"
Expand All @@ -39,7 +38,7 @@ func main() {
&cli.StringFlag{
Name: "ogmios",
Usage: "ogmios websocket endpoint",
Value: "ws://3.21.245.207:1337", // mainnet2
Value: "ws://172.16.61.4:1337", // mainnet2
EnvVars: []string{"OGMIOS"},
Destination: &opts.Ogmios,
},
Expand Down Expand Up @@ -67,64 +66,18 @@ func main() {

func action(_ *cli.Context) error {
client := ogmigo.New(
ogmigo.WithEndpoint("ws://172.0.0.1:1337"),
ogmigo.WithEndpoint("ws://172.0.0.4:1337"),
ogmigo.WithLogger(ogmigo.DefaultLogger),
)

var (
ctx = context.Background()
points chainsync.Points
ctx = context.Background()
)
points = []chainsync.Point{
chainsync.PointStruct{
BlockNo: 1120428,
Hash: "c39dc7fcbc3c2ec1df8126c6a0ce0558c92e5f8e22b7e738c33428982cabdfbf",
Slot: 25588246,
}.Point(),
}
//useV6 := false
useV6 := true
var callback ogmigo.ChainSyncFunc = func(ctx context.Context, data []byte) error {
var response chainsync.Response
if useV6 {
var resV6 chainsync.ResponseV6
if err := json.Unmarshal(data, &resV6); err != nil {
return err
}
response = resV6.ConvertToV5()
} else {
if err := json.Unmarshal(data, &response); err != nil {
return err
}
}

if response.Result == nil {
return nil
}
if response.Result.RollForward != nil {
ps := response.Result.RollForward.Block.PointStruct()
fmt.Println("blockNo", ps.BlockNo, "hash", ps.Hash, "slot", ps.Slot)
}
if response.Result.RollBackward != nil {
return nil
}

//ps := response.Result.RollForward.Block.PointStruct()
//fmt.Printf("slot=%v hash=%v block=%v\n", ps.Slot, ps.Hash, ps.BlockNo)

return nil
}
closer, err := client.ChainSync(ctx, callback,
ogmigo.WithPoints(points...),
ogmigo.WithReconnect(true),
ogmigo.WithUseV6(useV6),
)

txId, err := client.SubmitTxV6(ctx, "84ab0082825820b1936e102395112c1b362920430cb036e6f071805cf3de9c8712dcfcab5df8ff018258202b9a6935bf26f55bd971655cbb18449cbcd0dd01fa971b4f386bae1e49a5041d060183a300583910d9acf6e651c55e13f335f17c606b8cc0871a96adab67ed2593550595b2c7257ddaa0552c8e6bff73450d38be9057b08a6722b0cfb0d8fb3f01821a0225bc00a1581cb2600bec6c4bfcd5c6f5047490ba1a3b965b8307d06ec0b49f6b8acaa158202dacc5954ddc1b8661ba386ec075a7f8faeaf76f868a2ad8b2d577b7ce75355301028201d8185854d8799f1908fc0c581c1bcf5f5801a073b1ed979202065bd8433c132879fe51ab9b4006ba6658202dacc5954ddc1b8661ba386ec075a7f8faeaf76f868a2ad8b2d577b7ce7535530a011a002b44a00c061901f4ffa300583910231d677bcfc95c4f37066ace2b30ea8c7515533a409916d73b26de45b2c7257ddaa0552c8e6bff73450d38be9057b08a6722b0cfb0d8fb3f01821a062f91d0a1581cbebc61af81a6d0b8d1c153c7dd625318d03acc020ec3822a3bf2a48fa15820087b9b0880ffb63d4c48c5342cfe01c4bf47de5a72d459d89f7006ac0983111d01028201d8185878d8799fa140a1401a0004cebc0c581ce352fcd9cb2ed528c9b3c5babf79e261efad3dcfa9d98db654dc55365820087b9b0880ffb63d4c48c5342cfe01c4bf47de5a72d459d89f7006ac0983111d01061901f458202dacc5954ddc1b8661ba386ec075a7f8faeaf76f868a2ad8b2d577b7ce753553198e03ff8258390055a9a7dfccec3c96e2d2cae042ce356fb29627aae02d1fb7c118b3b81dfc18e7e2cb33daeea28f570ef9bf910cc27b35f2b5af11ca5f2f9e821a238e6dd7ad581c062a373ab3f7a2f8bbd2f00b6ecb041c11185c8a6817ab5cc6db34dca1444953504f1b0000545bcbc214d7581c50e015ec8204db83a4f57aa9ee40ce6ea157e3b7335a149fafe3f370a1401b000000151d6be4c1581c5c0235716a6a0529bec3c5c7f6bae139a06ce36f47c4be03950fde30a65820370148dbe495c40842e80a8c8590d29840046b0920c6a09101fd2bc5564c6e6901582071baf1d917edd8cae29e420d3c4f9e545572edd0c67773b632b8fecd2151ca470158208ec9486320983132a7185f2262e238594c0b22fc1fba527224f0b48247200c8601582098af276f396048cf4c20dfeeacbcd39e1c81754bf049abad5ddd5de32c61bdcd015820c5cd5a74ffd711c171a84d098301c3907724cbe71804762e96ee164885cd1559015820cc50ec5e482957656560718de32a9fa342c7a5cb43f2567554ea4fe1bd73afd501581c6927d5fbd38ef8be037f45d916496399bd7449cb0d459bcfd2f4fa1fa2582014b015dd432586f7ea75d56f85a103251ea8f4363b5a3b2f8fcc06c0be1dfe67015820efd5ec67d691646bf5b68d6b0409ba1cbf2a19c38e03c32ba565a9ba0e16744c01581c6aae8a4a6094e10c470587746d111570b884ed9012a8a11b0efb5086a14d0014df10200002018d67d634e01a3b9aca00581c74a36b62aed95f0d0d98f23ffa1f8e73d3f859520b3aea8a38633b05b81a582009c64f103e785a951dee08776b416686d41c948a60f4f128b80eb91cd803fb610158201a35f56138021acf0046875ec44ee2cebf8e3cce5beabc09f81efeeed15b88800158202a91232d9f47ca90bfa3b55b09d45a279a581cb5ef9cdd40280e0cec491cfdec0158203714cd55a0fead742e4ef224672ef91cf5f530cc58ef69fc2eda9f79e6ec4ea20158204219f1b7e54aad0c4fc8c45ae8c48b54473d413dc87e35fee52083bc536af55e0158204491dd46a47b9f97b5be925033a2774539e52850a011c06e6e3da54cd73fc5fb0158204dda146e9df94af3b2da01e17d235bf738434877bb53d93bf887b38a5181246d0158205d0adf1f40673c75d50aece30ce1e04641d5f04b7da4428784dc15fc4fec126a0158205d6a9d97b4bdf106000fca83c3bdb1ef02b57cf76a460cd536f4dd9c09c89fd90158206645cd80a9d3413fb856098c2a160606728dfe554ee7d4c0b2ce85e94a4509740158206ef56d4871aa3b98f2546620f268198515a68f2d152574ec608e56966c5c468601582077dffd4ae917c077e615edb8d806a8d238ff738b3985a00e881863bb50434ed601582078bc2418e8f3e317db1a13ae7b525835dda83c976b574f09452ae98fcc2c03590158207aea059ec37326443283fbad556068a4a42c4123a23409ecc0d07028321d5c6b0158207c978623a78e66ebb45fa388f6d477a795dae883218fcd34664bd3e8540b0efe015820867c9e91d7df51f386ac92702dccc55b8af541a19db1f8355f69956fdf9549320158208ae79adcb7a869fba97b7bc229f881a73434da0fe24b64661b1224a4059e2a120158209ddaa856ef2a86571bf760e60502393d0c30fd87095e2ec3a9ce56253dbb0f36015820a4e393637725f191aa270e271b698001000b7ad366a434168b51da205b04e32b015820c27429ce7e25e194eb0cd58663cdc2e12b43da8da8a5f2323bd73b6c023d161c015820c70d9fb18f328b5106c1e1d072b8f75a97258d30c7d4242e316d940723c4ff71015820d3234798c03f0ce2414bf8fe8662747b3581402500e72372d2422295990ae1d0015820d996c58b405b1768a7255a48a5e40675f0120f0cafd8bf5cbeab08ca278839f2015820ea71a7a9358a5fbfbcc5008175911db60a50f0fd84b6b64d998ebe66c9c17a92015820f39f9a6f817d9c57b5872c8149b6e8d60ae4909e0652da2ce21024bbec4eae72015820ff52f2944527a97f3307786627925436d7924a49599fc99ce377773a7889b3c801581c8819741bc9cb6299093bea6a6d306fb5faaf3aa4102ae43b8381837db81e582000e0b70534bbe96bb43d33a39b3abac7123aa65b29db65a2300a7c6528b06bc20158200694de9715c9ad4901b2c87fc8cb9255997a80738284eedc1259dd7a24d1c237015820154221dce5ecf093680bbc50603b06a38ccae88bd63607b3ae8950f6957d136e0158201b3f6b3d99ec1e7cfd3930540c6e8f2f9a9dad24586dc458ce3ee4a3b6cbece90158201c94b0f8da37c5bb17770a1b314934f34dbe497b5d7fe26536368d98fe27d5cb0158202b944b920734b86fc4448c0e365711ac16cbcfcf28764f8214c6dc336d8eefda0158202fa778595a2c0ccbeee9096c8a1cef3ca9c1f2da8abf380a9914fcdb1754ad7a0158203a9b4b128f7a817bc2e19682aa2721ae11d5ba5d5adc82b067eecda3a24154ea015820476f78a3ae2d8f9946c3bf35dd5dd26b1ef5fed9cceb8178557bf14998e82031015820523e8b28cae453eae126f92180e9c7d5b928bbdecc66cc5e7a0edbbd3641c11d0158205a35f32f3e362375dc2e9bcab7b68df84f7e9d08a67f6285e9491725d930318401582060ca43fc8c772c59c9d1ed49c4a7c6a8e18204341dba5082d76ae0eaef9b94ba0158206da358b379ac43563a53e0232079d890a219451171ff51153dcebe59079206010158206ff92e87663a8bef001a555e70bcd969dccb98fdc36500747d75d903fd84e26401582076f46bdd7416d75de8164d6b6647a621d29de9b5e885739475b9e4b73fa38dd101582088d45f3ce94fd00273346c29b34371723f48e15b816ee34bc431a9c723c71306015820917170ff565724686b6ec14cbac10b9a2ca46e4ffb73019c6f986b228b6db287015820995d7bf18da32deaecca57bc7ce565d9efc4c6728f1c08939a25c2297271e51f0158209c021898e1baa1ccffc9e4577ba9a3b4111571049113b8c73a5f49b1332a8511015820a1aa26818e251e086b459fdedf3a7405c0e00b934c28a5ca7a93719243bc5165015820a207d9e477bc8abf094c65e8f101fd171c9e30ba0ef98b36e62ea93cbe3ae06c015820a9400d57a77df9194ce86fe05f986b60f89b6bf9b051d1b9cf0a68535a163090015820ad081712b16c5c1293b7c25d4d6c77e0faeeb78762ae94f7ca5f67de544534c1015820b22cceea7ca42b3ca5e93b8e4a3bee517594dafac9cc43c2f1a88b5df51511b7015820b459165bd053e36479dcf831466fd8c90e2dc63e1c9e05676cfdc27a0d5aac31015820bdde05b2fd0fcd82cfaae4d2a02bebfd9a9234dcc02795848271b2e69d1e6379015820be1fdc9832ea75b07fab3428b05a7e77423380d3d740dc5bbbf510aa0e0fff43015820cd9600229697ab7e786686fae4a47658297b2abe91b19b29dc50606c9c6d99e4015820d98c80c066111e545a15c6f1348d01348c65eebe1a8b6d8b69362bd91d379c99015820e9dd34e3475bdef3daff4f68d7cecf13ec3113707d2a6eca435c99053be6ee4601581cb49bdc4e7262f2b00aeede862ea2928e4e9024d627f7d6345d0cb793a2458686868601014f686868681089ad00000000000f42401a77359400581cc3eb4faed4f2937ea35295e63c1c42d4324866ddf4897df153f0141da6582005ee4ae8749e505c65f79895b3ab5942f00fef1ed628ed936e635814a3701536015820304d30cea76b84e92b7466c127d7155fad433c79fb0988f08ba4a24e5d1ca91c015820580c547e2ea6611729ec902af6f8bbb794c09e555447ff8b54a7d866df6b2126015820a0c79fbb90078f1867cda82a1a8a3b96a40b4bb15204b7098af74852f7d5786f015820c1d23f7faf4461bc6522be90446a0d8ca3c6ca94708568bfe0052d9589193707015820d2fc2cadadb83583a592a1146fed219421af319abb6c7c4edb6cb28c62e1147201581cddd4669c9f5122caba6569d48197f75736d218dfbd2a9099a6a328e0b55820119195c29d7bea13ea80bd28f54739ca241620635ef920b8ced33d0e005ef118015820144b1c69fea4458678d6235179228b4fd27b34387abf94333eac12368c9e2d5101582021d54ed40eef2983e501ca19a78f1942f77c06554534db41dc0753a16f1922d8015820328949dc85f54df8837b582f61c57d9766ebbba3927991ee87cae03e96bf577201582038d93717a67b95b0c550dac48c48a6b7a85dbe037212f3eb3fcbada7519d09270158204146d888fccbeaebd80df7a8c27b621548eabdaeb13ac60792e539810a9655d001582046a312b1021b93fa37aef94e68d7e152e8c4353831f5176125b2a1187e031fb301582047f3b2587af27e4569889bd9050833c488a06a6641226ec3e9e581a0734793660158206623be0f718f384261ff6a4001ddc95a7aac46ce203bb9e19d51b47371fbe3af01582068428d1f38832f99c66a8a653a15ffadfb3c1a0b5f410196e0305e3948ef6ce10158206d83e29c6c96c1c469a1756ba146dc5a3cd3c8d6eebc7d437d7c7a04d7eb2b930158207810568af25923800c385f416f399083d17012166b615e02f50e328180bbfcb30158208821949f66479766b1ecbf839bdb1ab946f61e75f82a3ec8de2923536ed0e43301582098a1251afd91727b87dc178e448f5339e35817a3c83105dd21af13343bd498b50158209d7017c0d9899f6ccc01e51f9b18062e4059ec1cdf518ce93913bec1faebae2a015820a0736d5d3e8287efedffb6b2ac77bcf3cf21222c9118f32cf4062f7c45b92bbf015820a0e0d6437952251af25ae6e0b2a2298e130e834971dbe0d338bbb79d95421187015820a2a0971a50d8cafaa57c4aee09996eb09096e2ea8263753c1f4864039867e2a3015820a9dadb050744e186854a733c023ce0a0ea2e470736a8b1debf245e8afd390667015820b4293bb1207e02112ee33f5fc7d539c41892c580fbbd08d16e245bda633317d4015820b4812c513f9ba96963fac44276e0d4452fd6f628720ce75ad7784444bb80951a01581ce352fcd9cb2ed528c9b3c5babf79e261efad3dcfa9d98db654dc5536a15820087b9b0880ffb63d4c48c5342cfe01c4bf47de5a72d459d89f7006ac0983111d01581cedbebc19705989ee75ee3be41504b5f583179502a109ee3c01fd4aeea645000de14001014d0014df10200001018d67da95f81a773594004d0014df10200001018d67f482b01a4d7c6d004d0014df10200001018d68b166281a773594004d0014df10200001018d68c501b01aa0eebb004d0014df10200001018d695e4fc81a1dcd6500581cf5e505a4c2eee373fc31240607d141d6e0028794328caed9ddb9e7a3a15041697264726f7054657374546f6b656e1a00c093d0021a00084a38031a02c85678081a02c8551009a2581cbebc61af81a6d0b8d1c153c7dd625318d03acc020ec3822a3bf2a48fa15820087b9b0880ffb63d4c48c5342cfe01c4bf47de5a72d459d89f7006ac0983111d01581ce352fcd9cb2ed528c9b3c5babf79e261efad3dcfa9d98db654dc5536a15820087b9b0880ffb63d4c48c5342cfe01c4bf47de5a72d459d89f7006ac0983111d010b5820a45d0d357be041e3bd634eadc85bd3f28c4da7dc27b54528e939409bb83838c10d8182582003b06f3e886efaf0a25747fb8a84bcea413450ba67c60b9a26c8ede1366b632001108258390055a9a7dfccec3c96e2d2cae042ce356fb29627aae02d1fb7c118b3b81dfc18e7e2cb33daeea28f570ef9bf910cc27b35f2b5af11ca5f2f9e1a00d88d5c111a000c6f5412848258208f5d0bdc4e367cc581a5976286880667aa596131598185f8c9df394bfa27be76008258203348d7cc3df797478c8ede2db7b2ca1013c4e429b95d35a294f78ab78ab0d13800825820833b35976d9cdf5fb9badc4fa5e50daeadef0b1ad0998f8afaa5c5fc4a5615f70082582052b2970a262a1a75bf5ed891a0af03fd80dbb4047b27ac0e4f5562bd42241c2000a2008182582030a17e1fbdadad78da1c8146d1b5a62ff371c1d73aed792c909ab9dcdcda1c0f58408e94d4aadd8d0fc3c17e3a7e536cc2264238b2b94b68f74ec3751777632e5123392d14405100331ac3f7774a9c017ea240c83a38d8415cda8915a6af8fea83020583840001d87b80821a001067a11a190a9565840101d87b80821a000adc601a1043a5df840100d87b80821a0002295d1a0382536ff5f6")
if err != nil {
return err
panic(err.Error())
}
defer closer.Close()

fmt.Println(txId)
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Kill, os.Interrupt)

Expand Down
11 changes: 7 additions & 4 deletions tx_submission.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/buger/jsonparser"
"sort"
"strings"

"github.com/buger/jsonparser"
)

type Response struct {
Expand Down Expand Up @@ -121,8 +120,12 @@ func (s SubmitTxError) Messages() []json.RawMessage {

// Error implements the error interface
func (s SubmitTxError) Error() string {
keys, _ := s.ErrorCodes()
return fmt.Sprintf("SubmitTx failed: %v", strings.Join(keys, ", "))
var msgs []string
for _, m := range s.messages {
msgs = append(msgs, string(m))
}

return fmt.Sprintf("SubmitTx failed: %v", strings.Join(msgs, ","))
}

func readSubmitTx(data []byte) error {
Expand Down

0 comments on commit 8dcd910

Please sign in to comment.