Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clayton/bfg no pop #362

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
88 changes: 0 additions & 88 deletions api/bfgapi/bfgapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,11 @@ const (

CmdPingRequest = "bfgapi-ping-request"
CmdPingResponse = "bfgapi-ping-response"
CmdPopTxForL2BlockRequest = "bfgapi-pop-txs-for-l2-block-request"
CmdPopTxForL2BlockResponse = "bfgapi-pop-txs-for-l2-block-response"
CmdNewL2KeystonesRequest = "bfgapi-new-l2-keystones-request"
CmdNewL2KeystonesResponse = "bfgapi-new-l2-keystones-response"
CmdBTCFinalityByRecentKeystonesRequest = "bfgapi-btc-finality-by-recent-keystones-request"
CmdBTCFinalityByRecentKeystonesResponse = "bfgapi-btc-finality-by-recent-keystones-response"
CmdBTCFinalityByKeystonesRequest = "bfgapi-btc-finality-by-keystones-request"
CmdBTCFinalityByKeystonesResponse = "bfgapi-btc-finality-by-keystones-response"
CmdBTCFinalityNotification = "bfgapi-btc-finality-notification"
CmdBTCNewBlockNotification = "bfgapi-btc-new-block-notification"
CmdL2KeystonesNotification = "bfgapi-l2-keystones-notification"
CmdL2KeystonesRequest = "bfgapi-l2-keystones-request"
CmdL2KeystonesResponse = "bfgapi-l2-keystones-response"
CmdBitcoinBalanceRequest = "bfgapi-bitcoin-balance-request"
CmdBitcoinBalanceResponse = "bfgapi-bitcoin-balance-response"
CmdBitcoinBroadcastRequest = "bfgapi-bitcoin-broadcast-request"
CmdBitcoinBroadcastResponse = "bfgapi-bitcoin-broadcast-response"
CmdBitcoinInfoRequest = "bfgapi-bitcoin-info-request"
CmdBitcoinInfoResponse = "bfgapi-bitcoin-info-response"
CmdBitcoinUTXOsRequest = "bfgapi-bitcoin-utxos-request"
CmdBitcoinUTXOsResponse = "bfgapi-bitcoin-utxos-response"
)

var (
Expand All @@ -66,44 +50,6 @@ type (
PingResponse protocol.PingResponse
)

type NewL2KeystonesRequest struct {
L2Keystones []hemi.L2Keystone `json:"l2_keystones"`
}

type NewL2KeystonesResponse struct {
Error *protocol.Error `json:"error,omitempty"`
}

type L2KeystonesRequest struct {
NumL2Keystones uint64 `json:"num_l2_keystones"`
}

type L2KeystonesResponse struct {
L2Keystones []hemi.L2Keystone `json:"l2_keystones"`
Error *protocol.Error `json:"error,omitempty"`
}

type BitcoinBalanceRequest struct {
ScriptHash api.ByteSlice `json:"script_hash"`
}

type BitcoinBalanceResponse struct {
Confirmed uint64 `json:"confirmed"`
Unconfirmed int64 `json:"unconfirmed"`
Error *protocol.Error `json:"error,omitempty"`
}

type BitcoinBroadcastRequest struct {
Transaction api.ByteSlice `json:"transaction"` // XXX this needs to be plural
}

type BitcoinBroadcastResponse struct {
TXID api.ByteSlice `json:"txid"`
Error *protocol.Error `json:"error,omitempty"`
}

type BitcoinInfoRequest struct{}

type BitcoinInfoResponse struct {
Height uint64 `json:"height"`
Error *protocol.Error `json:"error,omitempty"`
Expand All @@ -115,25 +61,11 @@ type BitcoinUTXO struct {
Value int64 `json:"value"`
}

type BitcoinUTXOsRequest struct {
ScriptHash api.ByteSlice `json:"script_hash"`
}

type BitcoinUTXOsResponse struct {
UTXOs []*BitcoinUTXO `json:"utxos"`
Error *protocol.Error `json:"error,omitempty"`
}

type PopTxsForL2BlockRequest struct {
L2Block api.ByteSlice `json:"l2_block"`
Page uint32 `json:"page,omitempty"`
}

type PopTxsForL2BlockResponse struct {
PopTxs []PopTx `json:"pop_txs"`
Error *protocol.Error `json:"error,omitempty"`
}

type BTCFinalityByRecentKeystonesRequest struct {
NumRecentKeystones uint32 `json:"num_recent_keystones"`
}
Expand All @@ -156,10 +88,6 @@ type BTCFinalityByKeystonesResponse struct {

type BTCFinalityNotification struct{}

type BTCNewBlockNotification struct{}

type L2KeystonesNotification struct{}

type PopTx struct {
BtcTxId api.ByteSlice `json:"btc_tx_id"`
BtcRawTx api.ByteSlice `json:"btc_raw_tx"`
Expand All @@ -174,27 +102,11 @@ type PopTx struct {
var commands = map[protocol.Command]reflect.Type{
CmdPingRequest: reflect.TypeOf(PingRequest{}),
CmdPingResponse: reflect.TypeOf(PingResponse{}),
CmdPopTxForL2BlockRequest: reflect.TypeOf(PopTxsForL2BlockRequest{}),
CmdPopTxForL2BlockResponse: reflect.TypeOf(PopTxsForL2BlockResponse{}),
CmdNewL2KeystonesRequest: reflect.TypeOf(NewL2KeystonesRequest{}),
CmdNewL2KeystonesResponse: reflect.TypeOf(NewL2KeystonesResponse{}),
CmdBTCFinalityByRecentKeystonesRequest: reflect.TypeOf(BTCFinalityByRecentKeystonesRequest{}),
CmdBTCFinalityByRecentKeystonesResponse: reflect.TypeOf(BTCFinalityByRecentKeystonesResponse{}),
CmdBTCFinalityByKeystonesRequest: reflect.TypeOf(BTCFinalityByKeystonesRequest{}),
CmdBTCFinalityByKeystonesResponse: reflect.TypeOf(BTCFinalityByKeystonesResponse{}),
CmdBTCFinalityNotification: reflect.TypeOf(BTCFinalityNotification{}),
CmdBTCNewBlockNotification: reflect.TypeOf(BTCNewBlockNotification{}),
CmdL2KeystonesNotification: reflect.TypeOf(L2KeystonesNotification{}),
CmdL2KeystonesRequest: reflect.TypeOf(L2KeystonesRequest{}),
CmdL2KeystonesResponse: reflect.TypeOf(L2KeystonesResponse{}),
CmdBitcoinBalanceRequest: reflect.TypeOf(BitcoinBalanceRequest{}),
CmdBitcoinBalanceResponse: reflect.TypeOf(BitcoinBalanceResponse{}),
CmdBitcoinBroadcastRequest: reflect.TypeOf(BitcoinBroadcastRequest{}),
CmdBitcoinBroadcastResponse: reflect.TypeOf(BitcoinBroadcastResponse{}),
CmdBitcoinInfoRequest: reflect.TypeOf(BitcoinInfoRequest{}),
CmdBitcoinInfoResponse: reflect.TypeOf(BitcoinInfoResponse{}),
CmdBitcoinUTXOsRequest: reflect.TypeOf(BitcoinUTXOsRequest{}),
CmdBitcoinUTXOsResponse: reflect.TypeOf(BitcoinUTXOsResponse{}),
}

type bfgAPI struct{}
Expand Down
48 changes: 1 addition & 47 deletions api/bssapi/bssapi.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Hemi Labs, Inc.
// Copyright (c) 2024-2025 Hemi Labs, Inc.
// Use of this source code is governed by the MIT License,
// which can be found in the LICENSE file.

Expand All @@ -8,12 +8,8 @@ import (
"context"
"fmt"
"maps"
"math/big"
"reflect"

"github.com/ethereum/go-ethereum/common"

"github.com/hemilabs/heminetwork/api"
"github.com/hemilabs/heminetwork/api/protocol"
"github.com/hemilabs/heminetwork/hemi"
)
Expand All @@ -30,38 +26,6 @@ var (
DefaultURL = "ws://" + DefaultListen + RouteWebsocket
)

type PopPayout struct {
MinerAddress common.Address `json:"miner_address"`
Amount *big.Int `json:"amount"`
}

type PopPayoutsRequest struct {
L2BlockForPayout api.ByteSlice `json:"l2_block_for_payout"`
Page uint32 `json:"page,omitempty"`

// these are unused at this point, they will be used in the future to determine the
// total payout to miners
PopDifficultyNumerator uint64 `json:"popDifficultyNumerator,omitempty"`
PopDifficultyDenominator uint64 `json:"popDifficultyDenominator,omitempty"`
}

type PopPayoutsResponse struct {
PopPayouts []PopPayout `json:"pop_payouts"`

// unused for now
PopScore uint64 `json:"pop_score,omitempty"`

Error *protocol.Error `json:"error,omitempty"`
}

type L2KeystoneRequest struct {
L2Keystone hemi.L2Keystone
}

type L2KeystoneResponse struct {
Error *protocol.Error `json:"error,omitempty"`
}

type OptimismKeystone hemi.L2Keystone // dop only

// Websocket stuff follows.
Expand Down Expand Up @@ -101,32 +65,22 @@ const (
CmdPingResponse = "bssapi-ping-response"

// Custom RPC commands
CmdPopPayoutRequest protocol.Command = "bssapi-pop-payout-request"
CmdPopPayoutResponse protocol.Command = "bssapi-pop-payout-response"
CmdL2KeystoneRequest protocol.Command = "bssapi-l2-keystone-request"
CmdL2KeystoneResponse protocol.Command = "bssapi-l2-keystone-response"
CmdBTCFinalityByRecentKeystonesRequest protocol.Command = "bssapi-btc-finality-by-recent-keystones-request"
CmdBTCFinalityByRecentKeystonesResponse protocol.Command = "bssapi-btc-finality-by-recent-keystones-response"
CmdBTCFinalityByKeystonesRequest protocol.Command = "bssapi-btc-finality-by-keystones-request"
CmdBTCFinalityByKeystonesResponse protocol.Command = "bssapi-btc-finality-by-keystones-response"
CmdBTCFinalityNotification protocol.Command = "bssapi-btc-finality-notification"
CmdBTCNewBlockNotification protocol.Command = "bssapi-btc-new-block-notification"
)

// commands contains the command key and type. This is used during RPC calls.
var commands = map[protocol.Command]reflect.Type{
CmdPingRequest: reflect.TypeOf(PingRequest{}),
CmdPingResponse: reflect.TypeOf(PingResponse{}),
CmdPopPayoutRequest: reflect.TypeOf(PopPayoutsRequest{}),
CmdPopPayoutResponse: reflect.TypeOf(PopPayoutsResponse{}),
CmdL2KeystoneRequest: reflect.TypeOf(L2KeystoneRequest{}),
CmdL2KeystoneResponse: reflect.TypeOf(L2KeystoneResponse{}),
CmdBTCFinalityByRecentKeystonesRequest: reflect.TypeOf(BTCFinalityByRecentKeystonesRequest{}),
CmdBTCFinalityByRecentKeystonesResponse: reflect.TypeOf(BTCFinalityByRecentKeystonesResponse{}),
CmdBTCFinalityByKeystonesRequest: reflect.TypeOf(BTCFinalityByKeystonesRequest{}),
CmdBTCFinalityByKeystonesResponse: reflect.TypeOf(BTCFinalityByKeystonesResponse{}),
CmdBTCFinalityNotification: reflect.TypeOf(BTCFinalityNotification{}),
CmdBTCNewBlockNotification: reflect.TypeOf(BTCNewBlockNotification{}),
}

// apiCmd is an empty structure used to satisfy the protocol.API interface.
Expand Down
Loading
Loading