From 665c0008004af2333e79d3a7c11a68ebd0e4e949 Mon Sep 17 00:00:00 2001 From: Jonathan Harvey-Buschel Date: Thu, 25 May 2023 09:59:59 -0400 Subject: [PATCH] rpcserver+tapdb: use new batch state R/W methods --- rpcserver.go | 8 +++++--- tapdb/asset_minting.go | 12 ++++++++---- tapdb/asset_minting_test.go | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 5d1605f44..ec144eeba 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -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 @@ -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()) } } diff --git a/tapdb/asset_minting.go b/tapdb/asset_minting.go index cf96c6eea..eceb274bc 100644 --- a/tapdb/asset_minting.go +++ b/tapdb/asset_minting.go @@ -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( @@ -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, @@ -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: diff --git a/tapdb/asset_minting_test.go b/tapdb/asset_minting_test.go index 7069e442f..4651fb05d 100644 --- a/tapdb/asset_minting_test.go +++ b/tapdb/asset_minting_test.go @@ -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)