Skip to content

Commit

Permalink
[SKIP CI] Merge pull request #507 from subquery/feat/add-extend-onchain
Browse files Browse the repository at this point in the history
feat: add sign param
  • Loading branch information
cool-firer authored Oct 24, 2024
2 parents 372a3ff + 447be22 commit 7ff8204
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 12 deletions.
4 changes: 2 additions & 2 deletions apps/indexer-coordinator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@subql/indexer-coordinator",
"version": "2.5.0",
"version": "2.6.0",
"description": "",
"author": "SubQuery",
"license": "Apache-2.0",
Expand Down Expand Up @@ -45,7 +45,7 @@
"@nestjs/schedule": "^2.2.2",
"@nestjs/serve-static": "^2.2.2",
"@nestjs/typeorm": "8.1.4",
"@subql/contract-sdk": "1.3.0",
"@subql/contract-sdk": "1.3.1-0",
"@subql/network-clients": "1.1.0",
"@subql/network-config": "1.1.1",
"@subql/network-query": "1.1.1",
Expand Down
6 changes: 4 additions & 2 deletions apps/indexer-coordinator/src/payg/payg.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ export class PaygResolver {
channelExtend(
@Args('id') id: string,
@Args('expiration') expiration: number,
@Args('price', { nullable: true }) price?: string
@Args('price', { nullable: true }) price?: string,
@Args('indexerSign', { nullable: true }) indexerSign?: string,
@Args('consumerSign', { nullable: true }) consumerSign?: string
) {
return this.paygService.extend(id, expiration, price);
return this.paygService.extend(id, expiration, price, indexerSign, consumerSign);
}

@Mutation(() => ChannelType)
Expand Down
64 changes: 62 additions & 2 deletions apps/indexer-coordinator/src/payg/payg.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,30 @@ export class PaygService implements OnModuleInit {
}
}

async extend(id: string, expiration: number, price?: string): Promise<Channel> {
async extend(
id: string,
expiration: number,
price?: string,
indexerSign?: string,
consumerSign?: string
): Promise<Channel> {
const channel = await this.channel(id);
if (!channel) {
throw new Error(`channel not exist: ${id}`);
}

if (channel.status !== ChannelStatus.OPEN) {
throw new Error(`channel not open: ${id}`);
}

if (!indexerSign || !consumerSign) {
logger.debug(`extend channel requires indexerSign and consumerSign: ${id}`);
// throw new Error(`require indexerSign and consumerSign: ${id}`);
}

let modified = false;

const preExpirationAt = channel.expiredAt;
if (channel.expiredAt < expiration) {
channel.expiredAt = expiration;
modified = true;
Expand All @@ -408,12 +424,56 @@ export class PaygService implements OnModuleInit {
modified = true;
}

let signed = false;
if (indexerSign && consumerSign) {
// channel.lastConsumerSign = consumerSign;
// channel.lastIndexerSign = indexerSign;
modified = true;
signed = true;
}

if (!modified) {
return channel;
}

logger.debug(`Extend state channel ${id}`);
const expr = expiration - preExpirationAt;

logger.debug(
`Extend state channel ${id}. ${JSON.stringify(
channel
)} preExpirationAt:${preExpirationAt} expr:${expr}`
);

if (signed) {
await this.contract.sendTransaction({
action: `state channel extend ${id}`,
type: TxType.check,
txFun: (overrides) =>
this.contract
.getSdk()
.stateChannel.extend(
id,
preExpirationAt,
expr,
indexerSign,
consumerSign,
channel.price,
overrides
),
gasFun: (overrides) =>
this.contract
.getSdk()
.stateChannel.estimateGas.extend(
id,
preExpirationAt,
expr,
indexerSign,
consumerSign,
channel.price,
overrides
),
});
}
return this.saveAndPublish(channel, PaygEvent.State);
}

Expand Down
8 changes: 4 additions & 4 deletions apps/indexer-coordinator/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1673,10 +1673,10 @@
resolved "https://registry.yarnpkg.com/@sqltools/formatter/-/formatter-1.2.5.tgz#3abc203c79b8c3e90fd6c156a0c62d5403520e12"
integrity sha512-Uy0+khmZqUrUGm5dmMqVlnvufZRSK0FbYzVgp0UMstm+F5+W2/jnEEQyc9vo1ZR/E5ZI/B1WjjoTqBqwJL6Krw==

"@subql/[email protected]":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@subql/contract-sdk/-/contract-sdk-1.3.0.tgz#e6474369a2156fd3dfd50a84535d9a2894480198"
integrity sha512-vxd8xwtxDtNjv9WXYKx3pD12tdRDJJZ7Cm5yTtyH4piGcvLtJXehENxSBvCKvGtgpvzba8DiwDmbjIMYdomNzA==
"@subql/[email protected].1-0":
version "1.3.1-0"
resolved "https://registry.yarnpkg.com/@subql/contract-sdk/-/contract-sdk-1.3.1-0.tgz#a4608fadaf1c7882d66f5764d1710c7e81026ec9"
integrity sha512-sdBA0eALPV3MuAamYTlD80TW/x+NTmDmS+nFocaMEivrmXimh8JsasnOmjs3p1DXqcqNlDCr2d++9ctSOr75dQ==

"@subql/[email protected]":
version "1.1.0"
Expand Down
4 changes: 2 additions & 2 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
retries: 5

coordinator:
image: subquerynetwork/indexer-coordinator:v2.5.0
image: subquerynetwork/indexer-coordinator:v2.6.0
container_name: indexer_coordinator
restart: always
ports:
Expand Down Expand Up @@ -76,7 +76,7 @@ services:
test: ['CMD', 'redis-cli', '--raw', 'incr', 'ping']

proxy:
image: subquerynetwork/indexer-proxy:v2.6.2
image: subquerynetwork/indexer-proxy:v2.7.0
container_name: indexer_proxy
restart: always
ports:
Expand Down

0 comments on commit 7ff8204

Please sign in to comment.