-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: finish tx-submission client implementation
Fixes #54
- Loading branch information
Showing
7 changed files
with
247 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
/tx-monitor | ||
/block-fetch | ||
/peer-sharing | ||
/tx-submission | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
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 |
---|---|---|
@@ -0,0 +1,149 @@ | ||
// Copyright 2023 Blink Labs, LLC. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
ouroboros "github.com/blinklabs-io/gouroboros" | ||
"github.com/blinklabs-io/gouroboros/cmd/common" | ||
"github.com/blinklabs-io/gouroboros/protocol/txsubmission" | ||
) | ||
|
||
type txSubmissionFlags struct { | ||
*common.GlobalFlags | ||
/* | ||
slot uint64 | ||
hash string | ||
all bool | ||
*/ | ||
} | ||
|
||
func main() { | ||
// Parse commandline | ||
f := txSubmissionFlags{ | ||
GlobalFlags: common.NewGlobalFlags(), | ||
} | ||
/* | ||
f.Flagset.Uint64Var(&f.slot, "slot", 0, "slot for single block to fetch") | ||
f.Flagset.StringVar(&f.hash, "hash", "", "hash for single block to fetch") | ||
f.Flagset.BoolVar(&f.all, "all", false, "show all available detail for block") | ||
*/ | ||
f.Parse() | ||
// Create connection | ||
conn := common.CreateClientConnection(f.GlobalFlags) | ||
errorChan := make(chan error) | ||
go func() { | ||
for { | ||
err := <-errorChan | ||
fmt.Printf("ERROR(async): %s\n", err) | ||
os.Exit(1) | ||
} | ||
}() | ||
o, err := ouroboros.New( | ||
ouroboros.WithConnection(conn), | ||
ouroboros.WithNetworkMagic(uint32(f.NetworkMagic)), | ||
ouroboros.WithErrorChan(errorChan), | ||
ouroboros.WithNodeToNode(f.NtnProto), | ||
ouroboros.WithKeepAlive(true), | ||
ouroboros.WithTxSubmissionConfig( | ||
txsubmission.NewConfig( | ||
txsubmission.WithRequestTxIdsFunc( | ||
// TODO | ||
func(blocking bool, ack uint16, req uint16) ([]txsubmission.TxIdAndSize, error) { | ||
return []txsubmission.TxIdAndSize{}, nil | ||
}, | ||
), | ||
), | ||
), | ||
) | ||
if err != nil { | ||
fmt.Printf("ERROR: %s\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Start the TxSubmission activity loop | ||
o.TxSubmission().Client.Init() | ||
|
||
// Wait forever | ||
select {} | ||
|
||
/* | ||
blockHash, err := hex.DecodeString(f.hash) | ||
if err != nil { | ||
fmt.Printf("ERROR: failed to decode block hash: %s\n", err) | ||
os.Exit(1) | ||
} | ||
block, err := o.BlockFetch().Client.GetBlock(ocommon.NewPoint(f.slot, blockHash)) | ||
if err != nil { | ||
fmt.Printf("ERROR: failed to fetch block: %s\n", err) | ||
os.Exit(1) | ||
} | ||
// Display block info | ||
switch v := block.(type) { | ||
case *ledger.ByronEpochBoundaryBlock: | ||
fmt.Printf("era = Byron (EBB), epoch = %d, id = %s\n", v.Header.ConsensusData.Epoch, v.Hash()) | ||
case *ledger.ByronMainBlock: | ||
fmt.Printf("era = Byron, epoch = %d, slot = %d, id = %s\n", v.Header.ConsensusData.SlotId.Epoch, v.SlotNumber(), v.Hash()) | ||
case ledger.Block: | ||
fmt.Printf("era = %s, slot = %d, block_no = %d, id = %s\n", v.Era().Name, v.SlotNumber(), v.BlockNumber(), v.Hash()) | ||
} | ||
if f.all { | ||
// Display transaction info | ||
fmt.Printf("\nTransactions:\n") | ||
for _, tx := range block.Transactions() { | ||
fmt.Printf(" Hash: %s\n", tx.Hash()) | ||
if tx.Metadata().Value() != nil { | ||
fmt.Printf(" Metadata:\n %#v (%x)\n", tx.Metadata().Value(), tx.Metadata().Cbor()) | ||
} | ||
fmt.Printf(" Inputs:\n") | ||
for _, input := range tx.Inputs() { | ||
fmt.Printf(" Id: %s\n", input.Id()) | ||
fmt.Printf(" Index: %d\n", input.Index()) | ||
fmt.Println("") | ||
} | ||
fmt.Printf(" Outputs:\n") | ||
for _, output := range tx.Outputs() { | ||
fmt.Printf(" Address: %s\n", output.Address()) | ||
fmt.Printf(" Amount: %d\n", output.Amount()) | ||
assets := output.Assets() | ||
if assets != nil { | ||
fmt.Printf(" Assets:\n") | ||
for _, policyId := range assets.Policies() { | ||
fmt.Printf(" Policy Id: %s\n", policyId) | ||
fmt.Printf(" Policy assets:\n") | ||
for _, assetName := range assets.Assets(policyId) { | ||
fmt.Printf(" Asset name: %s\n", assetName) | ||
fmt.Printf(" Amount: %d\n", assets.Asset(policyId, assetName)) | ||
fmt.Println("") | ||
} | ||
} | ||
} | ||
if output.Datum() != nil { | ||
jsonData, err := json.Marshal(output.Datum()) | ||
if err != nil { | ||
fmt.Printf(" Datum (hex): %x\n", output.Datum().Cbor()) | ||
} else { | ||
fmt.Printf(" Datum: %s\n", jsonData) | ||
} | ||
} | ||
fmt.Println("") | ||
} | ||
} | ||
} | ||
*/ | ||
} |
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
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
Oops, something went wrong.