1717
1818import { color } from "@oclif/color" ;
1919import omit from "lodash-es/omit.js" ;
20+ import { stringify } from "yaml" ;
2021
2122import { commandObj } from "../../commandObj.js" ;
2223import type { ResourceType } from "../../configs/project/provider/provider4.js" ;
@@ -31,6 +32,7 @@ import { numToStr } from "../../helpers/typesafeStringify.js";
3132import { splitErrorsAndResults } from "../../helpers/utils.js" ;
3233import { confirm } from "../../prompt.js" ;
3334import { ensureFluenceEnv } from "../../resolveFluenceEnv.js" ;
35+ import type { Required } from "../../typeHelpers.js" ;
3436import { uint8ArrayToPeerIdHexString } from "../conversions.js" ;
3537import {
3638 peerIdHexStringToBase58String ,
@@ -58,7 +60,9 @@ type PeersOnChain = {
5860 hexPeerId : string ;
5961} [ ] ;
6062
61- type Txs = { description ?: string ; tx : ReturnType < typeof populateTx > } [ ] ;
63+ type Tx = { description ?: string ; tx : ReturnType < typeof populateTx > } ;
64+ type Txs = Tx [ ] ;
65+ type TxsWithDescription = Required < Tx > [ ] ;
6266
6367export async function updateOffers ( flags : OffersArgs ) {
6468 const offers = await resolveOffersFromProviderConfig ( flags ) ;
@@ -79,7 +83,25 @@ export async function updateOffers(flags: OffersArgs) {
7983 ] . flat ( ) ;
8084
8185 if ( firstUpdateOffersTx === undefined ) {
82- commandObj . logToStderr ( "No changes found for selected offers" ) ;
86+ const addedCPs = populatedTxs . reduce < Record < string , string [ ] > > (
87+ ( acc , { addedCPsNames, offerName } ) => {
88+ if ( addedCPsNames . length > 0 ) {
89+ acc [ offerName ] = addedCPsNames ;
90+ }
91+
92+ return acc ;
93+ } ,
94+ { } ,
95+ ) ;
96+
97+ if ( Object . values ( addedCPs ) . length === 0 ) {
98+ commandObj . logToStderr ( "No changes found for selected offers" ) ;
99+ } else {
100+ commandObj . logToStderr (
101+ `Added the compute peers to the following offers:\n${ stringify ( addedCPs ) } ` ,
102+ ) ;
103+ }
104+
83105 return ;
84106 }
85107
@@ -229,10 +251,14 @@ function populateUpdateOffersTxs(offersFoundOnChain: OnChainOffer[]) {
229251 peersOnChain ,
230252 ) ) satisfies Txs ;
231253
232- await addMissingComputePeers ( offer , peersOnChain ) ;
254+ const { addedCPsNames } = await addMissingComputePeers (
255+ offer ,
256+ peersOnChain ,
257+ ) ;
233258
234259 const txs = (
235260 await Promise . all ( [
261+ populateDataCenterTx ( offer ) ,
236262 populateChangeResourceSupplyAndDetailsTx ( offer ) ,
237263 populateCUToRemoveTxs ( offer , peersOnChain ) ,
238264 populateCUToAddTxs ( offer , peersOnChain ) ,
@@ -244,7 +270,13 @@ function populateUpdateOffersTxs(offersFoundOnChain: OnChainOffer[]) {
244270 ] )
245271 ) . flat ( ) satisfies Txs ;
246272
247- return { offerName, offerId, removePeersFromOffersTxs, txs } ;
273+ return {
274+ offerName,
275+ offerId,
276+ removePeersFromOffersTxs,
277+ txs,
278+ addedCPsNames,
279+ } ;
248280 } ) ,
249281 ) ;
250282}
@@ -344,6 +376,28 @@ async function populatePaymentTokenTx({
344376 ] ;
345377}
346378
379+ async function populateDataCenterTx ( {
380+ offerIndexerInfo,
381+ offerId,
382+ dataCenter,
383+ } : OnChainOffer ) {
384+ const { contracts } = await getContracts ( ) ;
385+ return offerIndexerInfo . dataCenter ?. id === dataCenter . id
386+ ? [ ]
387+ : [
388+ {
389+ description : `\nchanging data center from ${ color . yellow (
390+ offerIndexerInfo . dataCenter ?. id ,
391+ ) } to ${ color . yellow ( dataCenter . id ) } `,
392+ tx : populateTx (
393+ contracts . diamond . setOfferDatacenter ,
394+ offerId ,
395+ dataCenter . id ,
396+ ) ,
397+ } ,
398+ ] ;
399+ }
400+
347401async function populateCUToRemoveTxs (
348402 { computePeersFromProviderConfig } : OnChainOffer ,
349403 peersOnChain : PeersOnChain ,
@@ -492,7 +546,7 @@ async function createResourceSupplyAndDetailsUpdateTx(
492546 peerId : string ,
493547 { resourceType, onChainResource, configuredResource } : ResourceSupplyUpdate ,
494548) {
495- const txs : { description : string ; tx : ReturnType < typeof populateTx > } [ ] = [ ] ;
549+ const txs : TxsWithDescription = [ ] ;
496550
497551 if ( onChainResource . resourceId !== configuredResource . resourceId ) {
498552 return txs ;
@@ -548,7 +602,7 @@ async function populateChangeResourceSupplyAndDetailsTx({
548602 computePeersFromProviderConfig,
549603 offerIndexerInfo,
550604} : OnChainOffer ) {
551- const txs : { description ?: string ; tx : ReturnType < typeof populateTx > } [ ] = [ ] ;
605+ const txs : Txs = [ ] ;
552606
553607 for ( const peer of offerIndexerInfo . peers ) {
554608 const peerIdBase58 = await peerIdHexStringToBase58String ( peer . id ) ;
@@ -638,7 +692,7 @@ async function createResourceUpdateTx(
638692 peerId : string ,
639693 { resourceType, onChainResource, configuredResource } : ResourceUpdate ,
640694) {
641- const txs : { description : string ; tx : ReturnType < typeof populateTx > } [ ] = [ ] ;
695+ const txs : TxsWithDescription = [ ] ;
642696 const { contracts } = await getContracts ( ) ;
643697
644698 function removeResource ( ) {
0 commit comments