Fix race condition once and for all (#847)

This commit is contained in:
guibescos 2023-05-26 20:26:38 -05:00 committed by GitHub
parent 73c2af21a7
commit ce8e064c98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 32 deletions

View File

@ -324,18 +324,16 @@ const General = ({ proposerServerUrl }: { proposerServerUrl: string }) => {
)
// create add publisher instruction if there are any publishers
if (newChanges.priceAccounts[0].publishers.length > 0) {
newChanges.priceAccounts[0].publishers.forEach(
(publisherKey: string) => {
pythProgramClient.methods
.addPublisher(new PublicKey(publisherKey))
.accounts({
fundingAccount,
priceAccount: priceAccountKey,
})
.instruction()
.then((instruction) => instructions.push(instruction))
}
for (let publisherKey of newChanges.priceAccounts[0].publishers) {
instructions.push(
await pythProgramClient.methods
.addPublisher(new PublicKey(publisherKey))
.accounts({
fundingAccount,
priceAccount: priceAccountKey,
})
.instruction()
)
}
@ -438,28 +436,31 @@ const General = ({ proposerServerUrl }: { proposerServerUrl: string }) => {
)
// add instructions to remove publishers
publisherKeysToRemove.forEach((publisherKey: string) => {
pythProgramClient.methods
.delPublisher(new PublicKey(publisherKey))
.accounts({
fundingAccount,
priceAccount: new PublicKey(prev.priceAccounts[0].address),
})
.instruction()
.then((instruction) => instructions.push(instruction))
})
for (let publisherKey of publisherKeysToRemove) {
instructions.push(
await pythProgramClient.methods
.delPublisher(new PublicKey(publisherKey))
.accounts({
fundingAccount,
priceAccount: new PublicKey(prev.priceAccounts[0].address),
})
.instruction()
)
}
// add instructions to add new publishers
publisherKeysToAdd.forEach((publisherKey: string) => {
pythProgramClient.methods
.addPublisher(new PublicKey(publisherKey))
.accounts({
fundingAccount,
priceAccount: new PublicKey(prev.priceAccounts[0].address),
})
.instruction()
.then((instruction) => instructions.push(instruction))
})
for (let publisherKey of publisherKeysToAdd) {
instructions.push(
await pythProgramClient.methods
.addPublisher(new PublicKey(publisherKey))
.accounts({
fundingAccount,
priceAccount: new PublicKey(prev.priceAccounts[0].address),
})
.instruction()
)
}
}
}