Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add set flags for classic asset #165

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stellar-plus",
"version": "0.11.0",
"version": "0.12.0",
"description": "beta version of stellar-plus, an all-in-one sdk for the Stellar blockchain",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down
46 changes: 45 additions & 1 deletion src/stellar-plus/asset/classic/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { Horizon as HorizonNamespace, Operation, Asset as StellarAsset } from '@stellar/stellar-sdk'
import {
AuthClawbackEnabledFlag,
AuthFlag,
AuthImmutableFlag,
AuthRequiredFlag,
AuthRevocableFlag,
Horizon as HorizonNamespace,
Operation,
Asset as StellarAsset,
} from '@stellar/stellar-sdk'

import { AccountHandler } from 'stellar-plus/account/account-handler/types'
import {
ClassicAssetHandlerConstructorArgs,
ControlFlags,
ClassicAssetHandler as IClassicAssetHandler,
} from 'stellar-plus/asset/classic/types'
import { AssetTypes } from 'stellar-plus/asset/types'
Expand Down Expand Up @@ -242,6 +252,40 @@ export class ClassicAssetHandler implements IClassicAssetHandler {
return result.response
}

public async setFlags(
args: {
controlFlags: ControlFlags
} & TransactionInvocation
): Promise<HorizonNamespace.HorizonApi.SubmitTransactionResponse> {
this.requireIssuerAccount() // Enforces the issuer account to be set.

const { controlFlags } = args

const txInvocation = args as TransactionInvocation
const updatedTxInvocation = {
...txInvocation,
signers: [...txInvocation.signers, this.issuerAccount!], // Adds the issuer account as a signer. Issue account initialization is already verified by requireIssuerAccount().
}

let flags = 0
if (controlFlags.authorizationRequired) flags |= AuthRequiredFlag
if (controlFlags.authorizationRevocable) flags |= AuthRevocableFlag
if (controlFlags.authorizationImmutable) flags |= AuthImmutableFlag
if (controlFlags.clawbackEnabled) flags |= AuthClawbackEnabledFlag

const setFlags = Operation.setOptions({
setFlags: flags as AuthFlag,
source: this.asset.getIssuer(),
})

const result = (await this.classicTransactionPipeline.execute({
txInvocation: updatedTxInvocation,
operations: [setFlags],
})) as ClassicTransactionPipelineOutputSimple

return result.response
}

public async clawback(): Promise<void> {
throw new Error('Method not implemented.')
}
Expand Down
11 changes: 11 additions & 0 deletions src/stellar-plus/asset/classic/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export type ClassicTokenInterfaceManagement = {
amount: number
} & TransactionInvocation
) => Promise<Horizon.HorizonApi.SubmitTransactionResponse>

setFlags: (
args: { controlFlags: ControlFlags } & TransactionInvocation
) => Promise<Horizon.HorizonApi.SubmitTransactionResponse>
}

export type ClassicTokenInterfaceUser = {
Expand All @@ -49,3 +53,10 @@ export type ClassicUtils = {
args: { to: string; amount: number } & TransactionInvocation
) => Promise<Horizon.HorizonApi.SubmitTransactionResponse>
}

export type ControlFlags = {
authorizationRequired?: boolean
authorizationRevocable?: boolean
clawbackEnabled?: boolean
authorizationImmutable?: boolean
}
Loading