[price_pusher] Refresh sui object versions (#966)
This commit is contained in:
parent
03185cb17c
commit
0e5d7d0470
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@pythnetwork/price-pusher",
|
"name": "@pythnetwork/price-pusher",
|
||||||
"version": "5.4.5",
|
"version": "5.4.6",
|
||||||
"description": "Pyth Price Pusher",
|
"description": "Pyth Price Pusher",
|
||||||
"homepage": "https://pyth.network",
|
"homepage": "https://pyth.network",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
|
|
|
@ -329,7 +329,11 @@ export class SuiPricePusher implements IPricePusher {
|
||||||
`The balance of gas object ${gasObject.objectId} is too low. Removing from pool.`
|
`The balance of gas object ${gasObject.objectId} is too low. Removing from pool.`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
nextGasObject = gasObject;
|
// Refresh the coin object here in case the error is caused by an object version mismatch.
|
||||||
|
nextGasObject = await SuiPricePusher.tryRefreshObjectReference(
|
||||||
|
this.signer.provider,
|
||||||
|
gasObject
|
||||||
|
);
|
||||||
}
|
}
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
||||||
|
@ -373,6 +377,29 @@ export class SuiPricePusher implements IPricePusher {
|
||||||
return gasPool;
|
return gasPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attempt to refresh the version of the provided object reference to point to the current version
|
||||||
|
// of the object. Return the provided object reference if an error occurs or the object could not
|
||||||
|
// be retrieved.
|
||||||
|
private static async tryRefreshObjectReference(
|
||||||
|
provider: JsonRpcProvider,
|
||||||
|
ref: SuiObjectRef
|
||||||
|
): Promise<SuiObjectRef> {
|
||||||
|
try {
|
||||||
|
const objectResponse = await provider.getObject({ id: ref.objectId });
|
||||||
|
if (objectResponse.data !== undefined) {
|
||||||
|
return {
|
||||||
|
digest: objectResponse.data.digest,
|
||||||
|
objectId: objectResponse.data.objectId,
|
||||||
|
version: objectResponse.data.version,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return ref;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return ref;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static async getAllGasCoins(
|
private static async getAllGasCoins(
|
||||||
provider: JsonRpcProvider,
|
provider: JsonRpcProvider,
|
||||||
owner: SuiAddress
|
owner: SuiAddress
|
||||||
|
|
Loading…
Reference in New Issue