add a function for ReadSwapToVoucher

This commit is contained in:
Alfred Kamanda 2026-02-16 14:14:50 +03:00
parent 09954d967f
commit a78639799d
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703

View File

@ -236,3 +236,27 @@ func ReadSwapFromVoucher(ctx context.Context, store DataStore, sessionId string)
TokenAddress: data[storedb.DATA_ACTIVE_SWAP_FROM_ADDRESS],
}, nil
}
// ReadSwapToVoucher retrieves the swap to voucher being swapped from the pool
func ReadSwapToVoucher(ctx context.Context, store DataStore, sessionId string) (*dataserviceapi.TokenHoldings, error) {
keys := []storedb.DataTyp{
storedb.DATA_ACTIVE_SWAP_TO_SYM,
storedb.DATA_ACTIVE_SWAP_TO_DECIMAL,
storedb.DATA_ACTIVE_SWAP_TO_ADDRESS,
}
data := make(map[storedb.DataTyp]string)
for _, key := range keys {
value, err := store.ReadEntry(ctx, sessionId, key)
if err != nil {
return nil, fmt.Errorf("failed to get data key %x: %v", key, err)
}
data[key] = string(value)
}
return &dataserviceapi.TokenHoldings{
TokenSymbol: data[storedb.DATA_ACTIVE_SWAP_TO_SYM],
TokenDecimals: data[storedb.DATA_ACTIVE_SWAP_TO_DECIMAL],
TokenAddress: data[storedb.DATA_ACTIVE_SWAP_TO_ADDRESS],
}, nil
}