Skip to content

Commit

Permalink
fix(sudtcollector): make pwcollecotr extends from sudtcollector
Browse files Browse the repository at this point in the history
  • Loading branch information
johnz1019 committed Nov 13, 2020
1 parent 83fc880 commit 065bc5d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lay2/pw-core",
"version": "0.3.20-beta.3",
"version": "0.3.20-beta.4",
"description": "the javascript sdk of pw-sdk",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/collectors/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './collector';
export * from './sudt-collector';
export * from './pw-collector';
12 changes: 8 additions & 4 deletions src/collectors/pw-collector.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import axios from 'axios';
import { Collector, CollectorOptions } from './collector';
import { CollectorOptions } from './collector';
import { SUDTCollector } from './sudt-collector';
import { Cell, Address, Amount, AmountUnit, OutPoint } from '..';
import { SUDT } from '../models/sudt';

export class PwCollector extends Collector {
export class PwCollector extends SUDTCollector {
constructor(public apiBase: string) {
super();
this.apiBase = apiBase;
Expand Down Expand Up @@ -52,16 +53,19 @@ export class PwCollector extends Collector {
async collectSUDT(
sudt: SUDT,
address: Address,
neededAmount?: Amount
options: CollectorOptions
): Promise<Cell[]> {
if (!options || !options.neededAmount) {
throw new Error("'neededAmount' in options must be provided");
}
const cells: Cell[] = [];
const lockHash = address.toLockScript().toHash();
const typeHash = sudt.toTypeScript().toHash();

const res = await axios.get(
`${
this.apiBase
}/cell/unSpent?lockHash=${lockHash}&capacity=0x0&typeHash=${typeHash}&sudtAmount=${neededAmount.toHexString()}`
}/cell/unSpent?lockHash=${lockHash}&capacity=0x0&typeHash=${typeHash}&sudtAmount=${options.neededAmount.toHexString()}`
);

for (let { capacity, outPoint, type, data } of res.data.data) {
Expand Down

0 comments on commit 065bc5d

Please sign in to comment.