Skip to content

Commit

Permalink
rpcserver+tapdb: use new batch state R/W methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jharveyb committed May 25, 2023
1 parent 5294289 commit 665c000
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 5 additions & 3 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,9 @@ func marshalMintingBatch(batch *tapgarden.MintingBatch) (*mintrpc.MintingBatch,
func marshalBatchState(batch *tapgarden.MintingBatch) (mintrpc.BatchState,
error) {

switch batch.BatchState {
currentBatchState := batch.State()

switch currentBatchState {
case tapgarden.BatchStatePending:
return mintrpc.BatchState_BATCH_STATE_PEDNING, nil

Expand All @@ -1907,8 +1909,8 @@ func marshalBatchState(batch *tapgarden.MintingBatch) (mintrpc.BatchState,
return mintrpc.BatchState_BATCH_STATE_SPROUT_CANCELLED, nil

default:
return 0, fmt.Errorf("unknown batch state: %d",
batch.BatchState)
return 0, fmt.Errorf("unknown batch state: %v",
currentBatchState.String())
}
}

Expand Down
12 changes: 8 additions & 4 deletions tapdb/asset_minting.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,9 +832,6 @@ func marshalMintingBatch(ctx context.Context, q PendingAssetStore,
// For each batch, we'll assemble an intermediate batch struct, then
// fill in all the seedlings with another sub-query.
batch := &tapgarden.MintingBatch{
BatchState: tapgarden.BatchState(
dbBatch.BatchState,
),
BatchKey: keychain.KeyDescriptor{
KeyLocator: keychain.KeyLocator{
Family: keychain.KeyFamily(
Expand All @@ -848,6 +845,13 @@ func marshalMintingBatch(ctx context.Context, q PendingAssetStore,
CreationTime: dbBatch.CreationTimeUnix.UTC(),
}

batchState, err := tapgarden.NewBatchState(uint8(dbBatch.BatchState))
if err != nil {
return nil, err
}

batch.NewState(batchState)

if dbBatch.MintingTxPsbt != nil {
genesisPkt, err := psbt.NewFromRawBytes(
bytes.NewReader(dbBatch.MintingTxPsbt), false,
Expand All @@ -867,7 +871,7 @@ func marshalMintingBatch(ctx context.Context, q PendingAssetStore,
// either fetch the set of seedlings (asset
// descriptions w/ no real assets), or the set of
// sprouts (full defined assets, but not yet mined).
switch batch.BatchState {
switch batchState {
case tapgarden.BatchStatePending,
tapgarden.BatchStateFrozen,
tapgarden.BatchStateSeedlingCancelled:
Expand Down
4 changes: 2 additions & 2 deletions tapdb/asset_minting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ func newAssetStore(t *testing.T) (*AssetMintingStore, *AssetStore,
func assertBatchState(t *testing.T, batch *tapgarden.MintingBatch,
state tapgarden.BatchState) {

require.Equal(t, state, batch.BatchState)
require.Equal(t, state, batch.State())
}

func assertBatchEqual(t *testing.T, a, b *tapgarden.MintingBatch) {
t.Helper()

require.Equal(t, a.CreationTime.Unix(), b.CreationTime.Unix())
require.Equal(t, a.BatchState, b.BatchState)
require.Equal(t, a.State(), b.State())
require.Equal(t, a.BatchKey, b.BatchKey)
require.Equal(t, a.Seedlings, b.Seedlings)
require.Equal(t, a.GenesisPacket, b.GenesisPacket)
Expand Down

0 comments on commit 665c000

Please sign in to comment.