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

Update sdk #22

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
30 changes: 17 additions & 13 deletions examples/AnnounceCreateApostille.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
import { lastValueFrom } from 'rxjs';
import { Account, RepositoryFactoryHttp, TransactionService } from 'symbol-sdk';
import { ApostilleTransaction } from '../src/model';
import { HashingType } from '../src/utils/hash';
Expand All @@ -8,7 +9,7 @@ const seed = `hello_${new Date().toLocaleString()}.txt`;

const signerKey = '__INPUT_YOUR_PRIVATE_KEY__';

const apiEndpoint = 'https://sym-test.opening-line.jp:3001';
const apiEndpoint = 'http://sym-test-01.opening-line.jp:3000';
let networkType = 0;
let generationHash = ''
let epochAdjustment = 0;
Expand All @@ -17,14 +18,14 @@ let feeMultiplier = 0;
const repoFactory = new RepositoryFactoryHttp(apiEndpoint);

async function getNetworkProps() {
generationHash = await repoFactory.getGenerationHash().toPromise();
networkType = await repoFactory.getNetworkType().toPromise();
epochAdjustment = await repoFactory.getEpochAdjustment().toPromise();
generationHash = await lastValueFrom(repoFactory.getGenerationHash());
networkType = await lastValueFrom(repoFactory.getNetworkType());
epochAdjustment = await lastValueFrom(repoFactory.getEpochAdjustment());
}

async function getFeeMultiplier() {
const networkRepo = await repoFactory.createNetworkRepository();
const feeMultipliers = await networkRepo.getTransactionFees().toPromise();
const feeMultipliers = await lastValueFrom(networkRepo.getTransactionFees());
feeMultiplier = feeMultipliers.minFeeMultiplier;
}

Expand All @@ -41,20 +42,23 @@ async function announceApostilleTx() {
apiEndpoint,
epochAdjustment
);
const announceInfo = await apostilleTx.singedTransactionAndAnnounceType();
const announceInfo = await apostilleTx.signedTransactionAndAnnounceType();
const transactionRepo = repoFactory.createTransactionRepository();
const receiptRepo = repoFactory.createReceiptRepository();
const transactionService = new TransactionService(transactionRepo, receiptRepo);
const listener = repoFactory.createListener();

listener.open().then(() => {
transactionService.announce(announceInfo.signedTransaction, listener).subscribe((x) => {
console.log(`txHash: ${x.transactionInfo?.hash}`);
console.log(`apostille owner key: ${apostilleTx.apostilleAccount.account?.privateKey}`);
listener.close();
}, (err) => {
console.error(err);
listener.close();
transactionService.announce(announceInfo.signedTransaction, listener).subscribe({
next(x) {
console.log(`txHash: ${x.transactionInfo?.hash}`);
console.log(`apostille owner key: ${apostilleTx.apostilleAccount.account?.privateKey}`);
listener.close();
},
error(err) {
console.error(err);
listener.close();
}
});
});
}
Expand Down
28 changes: 16 additions & 12 deletions examples/AnnounceUpdateApostille.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable no-console */
import { lastValueFrom } from "rxjs";
import { Account, RepositoryFactoryHttp, TransactionService } from "symbol-sdk";
import { ApostilleTransaction } from "../src/model";
import { HashingType } from "../src/utils/hash";

const data = 'Hello World!!';
const signerKey = '__INPUT_YOUR_PRIVATE_KEY__';
const apostilleAccountKey = '__INPUT_YOUR_APOSTILLE_ACCOUNT_PRIVATE_KEY__';
const apiEndpoint = 'https://sym-test.opening-line.jp:3001';
const apiEndpoint = 'http://sym-test-01.opening-line.jp:3000';

let networkType = 0;
let generationHash = ''
Expand All @@ -16,14 +17,14 @@ let feeMultiplier = 0;
const repoFactory = new RepositoryFactoryHttp(apiEndpoint);

async function getNetworkProps() {
generationHash = await repoFactory.getGenerationHash().toPromise();
networkType = await repoFactory.getNetworkType().toPromise();
epochAdjustment = await repoFactory.getEpochAdjustment().toPromise();
generationHash = await lastValueFrom(repoFactory.getGenerationHash());
networkType = await lastValueFrom(repoFactory.getNetworkType());
epochAdjustment = await lastValueFrom(repoFactory.getEpochAdjustment());
}

async function getFeeMultiplier() {
const networkRepo = await repoFactory.createNetworkRepository();
const feeMultipliers = await networkRepo.getTransactionFees().toPromise();
const feeMultipliers = await lastValueFrom(networkRepo.getTransactionFees());
feeMultiplier = feeMultipliers.minFeeMultiplier;
}

Expand All @@ -43,7 +44,7 @@ async function announceUpdateApostilleTx() {
epochAdjustment
);

const announceInfo = await apostilleTx.singedTransactionAndAnnounceType();
const announceInfo = await apostilleTx.signedTransactionAndAnnounceType();
const transactionRepo = repoFactory.createTransactionRepository();
const receiptRepo = repoFactory.createReceiptRepository();
const transactionService = new TransactionService(
Expand All @@ -53,12 +54,15 @@ async function announceUpdateApostilleTx() {
const listener = repoFactory.createListener();

listener.open().then(() => {
transactionService.announce(announceInfo.signedTransaction, listener).subscribe((x) => {
console.log(`txHash: ${x.transactionInfo?.hash}`);
listener.close();
}, (err) => {
console.error(err);
listener.close();
transactionService.announce(announceInfo.signedTransaction, listener).subscribe({
next(x) {
console.log(`txHash: ${x.transactionInfo?.hash}`);
listener.close();
},
error(err) {
console.error(err);
listener.close();
}
})
})
}
Expand Down
28 changes: 16 additions & 12 deletions examples/ApostilleAssignOwners.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
import { lastValueFrom } from 'rxjs';
import { Account, RepositoryFactoryHttp, Address, HashLockTransaction, Deadline, UInt64, TransactionService, Currency } from 'symbol-sdk';
import { IApostilleOptions, ApostilleTransaction } from '../src/model';
import { HashingType } from '../src/utils/hash';
Expand All @@ -8,7 +9,7 @@ const seed = `hello_${new Date().toLocaleString()}.txt`;

const signerKey = '__INPUT_YOUR_PRIVATE_KEY__';

const apiEndpoint = 'https://sym-test.opening-line.jp:3001';
const apiEndpoint = 'http://sym-test-01.opening-line.jp:3000';
let networkType = 0;
let generationHash = ''
let epochAdjustment = 0;
Expand All @@ -17,14 +18,14 @@ let feeMultiplier = 0;
const repoFactory = new RepositoryFactoryHttp(apiEndpoint);

async function getNetworkProps() {
generationHash = await repoFactory.getGenerationHash().toPromise();
networkType = await repoFactory.getNetworkType().toPromise();
epochAdjustment = await repoFactory.getEpochAdjustment().toPromise();
generationHash = await lastValueFrom(repoFactory.getGenerationHash());
networkType = await lastValueFrom(repoFactory.getNetworkType());
epochAdjustment = await lastValueFrom(repoFactory.getEpochAdjustment());
}

async function getFeeMultiplier() {
const networkRepo = await repoFactory.createNetworkRepository();
const feeMultipliers = await networkRepo.getTransactionFees().toPromise();
const feeMultipliers = await lastValueFrom(networkRepo.getTransactionFees());
feeMultiplier = feeMultipliers.minFeeMultiplier;
}

Expand Down Expand Up @@ -56,7 +57,7 @@ async function announceApostilleTx() {
option
);

apostilleTx.singedTransactionAndAnnounceType().then((info) => {
apostilleTx.signedTransactionAndAnnounceType().then((info) => {
const signedTx = info.signedTransaction;
const hashLockTx = HashLockTransaction.create(
Deadline.create(epochAdjustment),
Expand All @@ -78,12 +79,15 @@ async function announceApostilleTx() {
signedHashLockTx,
signedTx,
listener
).subscribe((x) => {
listener.close();
console.log(x);
}, (err) => {
listener.close();
console.error(err);
).subscribe({
next(x) {
listener.close();
console.log(x);
},
error(err) {
listener.close();
console.error(err);
}
});
});
});
Expand Down
38 changes: 21 additions & 17 deletions examples/ApostilleWithMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/* eslint-disable no-console */
import { lastValueFrom } from 'rxjs';
import { Account, RepositoryFactoryHttp, TransactionService } from 'symbol-sdk';
import { IApostilleMetadata, IApostilleOptions, ApostilleTransaction } from '../src/model';
import { HashingType } from '../src/utils/hash';

const data = 'Hello World';
const seed = `hello_${new Date().toLocaleString()}.txt`;

const singerKey = '__INPUT_YOUR_PRIVATE_KEY__';
const signerKey = '__INPUT_YOUR_PRIVATE_KEY__';

const apiEndpoint = 'https://sym-test.opening-line.jp:3001';
const apiEndpoint = 'http://sym-test-01.opening-line.jp:3000';

let networkType = 0;
let generationHash = '';
Expand All @@ -18,14 +19,14 @@ let epochAdjustment = 0;
const repoFactory = new RepositoryFactoryHttp(apiEndpoint);

async function getNetworkProps() {
generationHash = await repoFactory.getGenerationHash().toPromise();
networkType = await repoFactory.getNetworkType().toPromise();
epochAdjustment = await repoFactory.getEpochAdjustment().toPromise();
generationHash = await lastValueFrom(repoFactory.getGenerationHash());
networkType = await lastValueFrom(repoFactory.getNetworkType());
epochAdjustment = await lastValueFrom(repoFactory.getEpochAdjustment());
}

async function getFeeMultiplier() {
const networkRepo = await repoFactory.createNetworkRepository();
const feeMultipliers = await networkRepo.getTransactionFees().toPromise();
const feeMultipliers = await lastValueFrom(networkRepo.getTransactionFees());
feeMultiplier = feeMultipliers.minFeeMultiplier;
}

Expand All @@ -40,12 +41,12 @@ const option: IApostilleOptions = {
}

async function announceApostilleTx() {
const singer = Account.createFromPrivateKey(singerKey, networkType);
const signer = Account.createFromPrivateKey(signerKey, networkType);
const apostilleTransaction = ApostilleTransaction.createFromData(
data,
HashingType.Type.sha256,
seed,
singer,
signer,
networkType,
generationHash,
feeMultiplier,
Expand All @@ -54,22 +55,25 @@ async function announceApostilleTx() {
option
);

apostilleTransaction.singedTransactionAndAnnounceType().then((info) => {
apostilleTransaction.signedTransactionAndAnnounceType().then((info) => {
const signedTx = info.signedTransaction;
const transactionService = new TransactionService(
repoFactory.createTransactionRepository(),
repoFactory.createReceiptRepository(),
);
const listener = repoFactory.createListener();
listener.open().then(() => {
transactionService.announce(signedTx, listener).subscribe((x) => {
console.log('--- Apostille created ---');
console.log(`txHash: ${x.transactionInfo!.hash}`);
console.log(`apostille owner key: ${apostilleTransaction.apostilleAccount.account!.privateKey}`);
listener.close();
}, (err) => {
console.error(err);
listener.close();
transactionService.announce(signedTx, listener).subscribe({
next(x) {
console.log('--- Apostille created ---');
console.log(`txHash: ${x.transactionInfo!.hash}`);
console.log(`apostille owner key: ${apostilleTransaction.apostilleAccount.account!.privateKey}`);
listener.close();
},
error(err) {
console.error(err);
listener.close();
}
});
}).catch((err) => {
console.error(err);
Expand Down
4 changes: 2 additions & 2 deletions examples/AuditApostille.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { AuditService } from '../src/service';

const data = 'Hello World';
const txHash = '4ADCC18B2D72D8D40922D14A03B077C7D8BEC1FEE9934FE69E54DBBC3800E342';
const apiEndpoint = 'https://sym-test.opening-line.jp:3001';
const txHash = '__INPUT_AUDITED_TRANSACTION_HASH__';
const apiEndpoint = 'http://sym-test-01.opening-line.jp:3000';

AuditService.audit(data, txHash, apiEndpoint).then((result) => {
console.log(result);
Expand Down
4 changes: 2 additions & 2 deletions examples/AuditWithPartialTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import { AuditService } from "../src/service";

const data = 'Hello World!';
const txHash = '77CB1A251B028529C5AB07394D4DD5E769382C0E47FA4267B8694649ED75D003';
const txHash = '__INPUT_AUDITED_TRANSACTION_HASH__';

const apiEndpoint = 'https://sym-test.opening-line.jp:3001';
const apiEndpoint = 'http://sym-test-01.opening-line.jp:3000';

AuditService.audit(data, txHash, apiEndpoint).then((result) => {
console.log(result);
Expand Down
Loading