Skip to content

Commit

Permalink
fix(signer): update ANT to have signer
Browse files Browse the repository at this point in the history
  • Loading branch information
Atticus committed Mar 20, 2024
1 parent 18f2b58 commit c7f8eee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
14 changes: 10 additions & 4 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { ArconnectSigner, ArweaveSigner } from 'arbundles';

import {
ANTRecord,
ANTState,
Expand All @@ -32,13 +34,17 @@ export type SortKey = string;
export type WalletAddress = string;

// TODO: append this with other configuration options (e.g. local vs. remote evaluation)
export type ContractConfiguration =
| {
export type ArIOSigner = ArweaveSigner | ArconnectSigner;
export type ContractConfiguration = {
signer?: ArIOSigner; // TODO: optionally allow JWK in place of signer
} & (
| {
contract?: SmartWeaveContract<unknown>;
}
| {
| {
contractTxId: string;
};
}
);

export function isContractConfiguration<T>(
config: ContractConfiguration,
Expand Down
6 changes: 5 additions & 1 deletion src/common/ant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ import { RemoteContract } from './contracts/remote-contract.js';

export class ANT implements ANTContract {
private contract: SmartWeaveContract<ANTState>;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
private signer: ArIOSigner | undefined;

constructor(config: ContractConfiguration) {
constructor({ signer, ...config }: ContractConfiguration) {
this.signer = signer;
if (isContractConfiguration<ANTState>(config)) {
this.contract = config.contract;
} else if (isContractTxIdConfiguration(config)) {
Expand Down
24 changes: 8 additions & 16 deletions src/common/ar-io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { ArconnectSigner, ArweaveSigner } from 'arbundles';

import { ARNS_TESTNET_REGISTRY_TX } from '../constants.js';
import {
ArIOContract,
ArIOState,
Expand All @@ -33,19 +32,6 @@ import {
} from '../types.js';
import { RemoteContract } from './contracts/remote-contract.js';

// TODO: append this with other configuration options (e.g. local vs. remote evaluation)
export type ArIOSigner = ArweaveSigner | ArconnectSigner;
export type ContractConfiguration = {
signer?: ArIOSigner; // TODO: optionally allow JWK in place of signer
} & (
| {
contract?: SmartWeaveContract<unknown>;
}
| {
contractTxId: string;
}
);

function isContractConfiguration<T>(
config: ContractConfiguration,
): config is { contract: SmartWeaveContract<T> } {
Expand All @@ -64,7 +50,13 @@ export class ArIO implements ArIOContract {
// @ts-ignore
private signer: ArIOSigner | undefined;

constructor({ signer, ...config }: ContractConfiguration) {
constructor(
{ signer, ...config }: ContractConfiguration = {
contract: new RemoteContract<ArIOState>({
contractTxId: ARNS_TESTNET_REGISTRY_TX,
}),
},
) {
this.signer = signer;
if (isContractConfiguration<ArIOState>(config)) {
this.contract = config.contract;
Expand Down

0 comments on commit c7f8eee

Please sign in to comment.