feat: create new directory
This commit is contained in:
@@ -112,7 +112,7 @@ describe('Testing the Profit Sharing Token', () => {
|
||||
|
||||
const newSource = fs.readFileSync(path.join(__dirname, '../data/token-evolve.js'), 'utf8');
|
||||
|
||||
const newSrcTxId = await pst.saveSource({ src: newSource });
|
||||
const newSrcTxId = await pst.save({ src: newSource });
|
||||
await mineBlock(arweave);
|
||||
|
||||
await pst.evolve(newSrcTxId);
|
||||
|
||||
@@ -131,7 +131,7 @@ describe('Testing the Profit Sharing Token', () => {
|
||||
|
||||
const newSource = fs.readFileSync(path.join(__dirname, '../data/token-evolve.js'), 'utf8');
|
||||
|
||||
const newSrcTxId = await pst.saveSource({ src: newSource });
|
||||
const newSrcTxId = await pst.save({ src: newSource });
|
||||
await mineBlock(arweave);
|
||||
|
||||
await pst.evolve(newSrcTxId);
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
GQLNodeInterface,
|
||||
InteractionResult,
|
||||
Tags,
|
||||
SaveSource
|
||||
Source
|
||||
} from '@smartweave';
|
||||
import { NetworkInfoInterface } from 'arweave/node/network';
|
||||
import Transaction from 'arweave/node/lib/transaction';
|
||||
@@ -37,7 +37,7 @@ export interface EvolveState {
|
||||
* A base interface to be implemented by SmartWeave Contracts clients
|
||||
* - contains "low-level" methods that allow to interact with any contract
|
||||
*/
|
||||
export interface Contract<State = unknown> extends SaveSource {
|
||||
export interface Contract<State = unknown> extends Source {
|
||||
/**
|
||||
* Returns the Arweave transaction id of this contract.
|
||||
*/
|
||||
@@ -239,9 +239,9 @@ export interface Contract<State = unknown> extends SaveSource {
|
||||
* Evolve is a feature that allows to change contract's source
|
||||
* code, without having to deploy a new contract.
|
||||
* This method effectively evolves the contract to the source.
|
||||
* This requires the {@link saveSource} to be called first
|
||||
* This requires the {@link save} to be called first
|
||||
* and its transaction to be confirmed by the network.
|
||||
* @param newSrcTxId - result of the {@link saveSource} method call.
|
||||
* @param newSrcTxId - result of the {@link save} method call.
|
||||
*/
|
||||
evolve(newSrcTxId: string): Promise<string | null>;
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ import {
|
||||
SmartWeaveTags,
|
||||
SourceType,
|
||||
Tags,
|
||||
SaveSourceImpl,
|
||||
SaveSourceData
|
||||
SourceImpl,
|
||||
SourceData
|
||||
} from '@smartweave';
|
||||
import { TransactionStatusResponse } from 'arweave/node/transactions';
|
||||
import { NetworkInfoInterface } from 'arweave/node/network';
|
||||
@@ -771,14 +771,14 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
||||
return await this.writeInteraction<any>({ function: 'evolve', value: newSrcTxId });
|
||||
}
|
||||
|
||||
async saveSource(saveSourceData: SaveSourceData): Promise<any> {
|
||||
async save(sourceData: SourceData): Promise<any> {
|
||||
if (!this.signer) {
|
||||
throw new Error("Wallet not connected. Use 'connect' method first.");
|
||||
}
|
||||
const { arweave } = this.smartweave;
|
||||
const source = new SaveSourceImpl(arweave);
|
||||
const source = new SourceImpl(arweave);
|
||||
|
||||
const srcTx = await source.saveSource(saveSourceData, this.signer);
|
||||
const srcTx = await source.save(sourceData, this.signer);
|
||||
|
||||
return srcTx.id;
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import { ArWallet } from '@smartweave/core';
|
||||
import { SigningFunction } from './Contract';
|
||||
import { SaveSourceData } from './SaveSourceImpl';
|
||||
|
||||
export interface SaveSource {
|
||||
/**
|
||||
* allows to post contract source on Arweave
|
||||
* @param newContractSource - new contract source...
|
||||
*/
|
||||
saveSource(
|
||||
contractSource: SaveSourceData,
|
||||
signer?: ArWallet | SigningFunction,
|
||||
useBundler?: boolean
|
||||
): Promise<string | null>;
|
||||
}
|
||||
15
src/contract/deploy/Source.ts
Normal file
15
src/contract/deploy/Source.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { SigningFunction } from 'contract/Contract';
|
||||
import { ArWallet } from './CreateContract';
|
||||
import { SourceData } from './impl/SourceImpl';
|
||||
|
||||
export interface Source {
|
||||
/**
|
||||
* allows to post contract source on Arweave
|
||||
* @param contractSource - contract source...
|
||||
*/
|
||||
save(
|
||||
contractSource: SourceData,
|
||||
signer?: ArWallet | SigningFunction,
|
||||
useBundler?: boolean
|
||||
): Promise<string | null>;
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
/* eslint-disable */
|
||||
import { ContractData, ContractType, CreateContract, FromSrcTxContractData, SmartWeaveTags } from '@smartweave/core';
|
||||
import { SmartWeaveTags } from '@smartweave/core';
|
||||
import Arweave from 'arweave';
|
||||
import { LoggerFactory } from '@smartweave/logging';
|
||||
import Transaction from 'arweave/node/lib/transaction';
|
||||
import { SaveSourceImpl } from '@smartweave/contract';
|
||||
import { ContractData, CreateContract, FromSrcTxContractData, SourceImpl } from '@smartweave/contract';
|
||||
|
||||
export class DefaultCreateContract implements CreateContract {
|
||||
private readonly logger = LoggerFactory.INST.create('DefaultCreateContract');
|
||||
@@ -15,9 +15,9 @@ export class DefaultCreateContract implements CreateContract {
|
||||
async deploy(contractData: ContractData, useBundler = false): Promise<string> {
|
||||
const { wallet, initState, tags, transfer } = contractData;
|
||||
|
||||
const source = new SaveSourceImpl(this.arweave);
|
||||
const source = new SourceImpl(this.arweave);
|
||||
|
||||
const srcTx = await source.saveSource(contractData, wallet, useBundler);
|
||||
const srcTx = await source.save(contractData, wallet, useBundler);
|
||||
this.logger.debug('Creating new contract');
|
||||
|
||||
return await this.deployFromSourceTx(
|
||||
@@ -1,11 +1,12 @@
|
||||
import { ArWallet, ContractData, ContractType, SmartWeaveTags } from '@smartweave/core';
|
||||
import { SmartWeaveTags } from '@smartweave/core';
|
||||
import { LoggerFactory } from '@smartweave/logging';
|
||||
import { SaveSource, SigningFunction } from '@smartweave';
|
||||
import { Source, SigningFunction } from '@smartweave';
|
||||
import metering from 'redstone-wasm-metering';
|
||||
import Arweave from 'arweave';
|
||||
import { Go } from '../core/modules/impl/wasm/go-wasm-imports';
|
||||
import { Go } from '../../../core/modules/impl/wasm/go-wasm-imports';
|
||||
import fs, { PathOrFileDescriptor } from 'fs';
|
||||
import { matchMutClosureDtor } from '../core/modules/impl/wasm/wasm-bindgen-tools';
|
||||
import { matchMutClosureDtor } from '../../../core/modules/impl/wasm/wasm-bindgen-tools';
|
||||
import { ArWallet, ContractType } from '../CreateContract';
|
||||
|
||||
const wasmTypeMapping: Map<number, string> = new Map([
|
||||
[1, 'assemblyscript'],
|
||||
@@ -15,18 +16,18 @@ const wasmTypeMapping: Map<number, string> = new Map([
|
||||
[5, 'c']*/
|
||||
]);
|
||||
|
||||
export interface SaveSourceData {
|
||||
export interface SourceData {
|
||||
src: string | Buffer;
|
||||
wasmSrcCodeDir?: string;
|
||||
wasmGlueCode?: string;
|
||||
}
|
||||
|
||||
export class SaveSourceImpl implements SaveSource {
|
||||
private readonly logger = LoggerFactory.INST.create('SaveSource');
|
||||
export class SourceImpl implements Source {
|
||||
private readonly logger = LoggerFactory.INST.create('Source');
|
||||
constructor(private readonly arweave: Arweave) {}
|
||||
|
||||
async saveSource(contractData: SaveSourceData, signer: ArWallet | SigningFunction, useBundler = false): Promise<any> {
|
||||
this.logger.debug('Creating new contract');
|
||||
async save(contractData: SourceData, signer: ArWallet | SigningFunction, useBundler = false): Promise<any> {
|
||||
this.logger.debug('Creating new contract source');
|
||||
|
||||
const { src, wasmSrcCodeDir, wasmGlueCode } = contractData;
|
||||
|
||||
@@ -3,5 +3,7 @@ export * from './HandlerBasedContract';
|
||||
export * from './PstContract';
|
||||
export * from './PstContractImpl';
|
||||
export * from './InnerWritesEvaluator';
|
||||
export * from './SaveSource';
|
||||
export * from './SaveSourceImpl';
|
||||
export * from './deploy/Source';
|
||||
export * from './deploy/impl/SourceImpl';
|
||||
export * from './deploy/impl/DefaultCreateContract';
|
||||
export * from './deploy/CreateContract';
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
/**
|
||||
* This type contains all data and meta-data of the given contact.
|
||||
*/
|
||||
import { ContractType } from './modules/CreateContract';
|
||||
import Transaction from 'arweave/node/lib/transaction';
|
||||
import { ContractType } from '@smartweave/contract';
|
||||
|
||||
export class ContractMetadata {
|
||||
dtor: number;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import {
|
||||
CreateContract,
|
||||
DefaultCreateContract,
|
||||
DefinitionLoader,
|
||||
ExecutorFactory,
|
||||
HandlerApi,
|
||||
@@ -10,7 +8,7 @@ import {
|
||||
StateEvaluator
|
||||
} from '@smartweave/core';
|
||||
import Arweave from 'arweave';
|
||||
import { Contract, HandlerBasedContract, PstContract, PstContractImpl } from '@smartweave/contract';
|
||||
import { Contract, CreateContract, DefaultCreateContract, HandlerBasedContract, PstContract, PstContractImpl } from '@smartweave/contract';
|
||||
import { GQLNodeInterface } from '@smartweave/legacy';
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,6 @@ export * from './modules/ExecutorFactory';
|
||||
export * from './modules/InteractionsLoader';
|
||||
export * from './modules/InteractionsSorter';
|
||||
export * from './modules/StateEvaluator';
|
||||
export * from './modules/CreateContract';
|
||||
|
||||
export * from './modules/impl/BlockHeightInteractionsSorter';
|
||||
export * from './modules/impl/ContractDefinitionLoader';
|
||||
@@ -14,7 +13,6 @@ export * from './modules/impl/DefaultStateEvaluator';
|
||||
export * from './modules/impl/CacheableStateEvaluator';
|
||||
export * from './modules/impl/HandlerExecutorFactory';
|
||||
export * from './modules/impl/LexicographicalInteractionsSorter';
|
||||
export * from './modules/impl/DefaultCreateContract';
|
||||
export * from './modules/impl/TagsParser';
|
||||
export * from './modules/impl/normalize-source';
|
||||
export * from './modules/impl/StateCache';
|
||||
|
||||
Reference in New Issue
Block a user