Skip to content

Commit

Permalink
Fix circular TokenRPC dependency, Remove ExtIds from tx constructor(f…
Browse files Browse the repository at this point in the history
…rom object)
  • Loading branch information
Devon Katz committed Oct 20, 2018
1 parent eff9b02 commit 5a362a9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 51 deletions.
2 changes: 1 addition & 1 deletion 0/Issuance.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Issuance {
return this._tokenId;
}

getRootChainId() {
getIssuerIdentityRootChainId() {
return this._rootChainId;
}

Expand Down
30 changes: 0 additions & 30 deletions 0/TokenRPC.js

This file was deleted.

15 changes: 1 addition & 14 deletions 0/Transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class TransactionBuilder {
this._tokenId = tokenId;
return this;
}

blockheight(blockheight) {
if (isNaN(blockheight) || !Number.isInteger(blockheight)) throw new Error("Blockheight must be a positive nonzero integer");
this._blockheight = blockheight;
Expand Down Expand Up @@ -120,19 +120,6 @@ class Transaction {
this.blockheight = builder.blockheight;
this.timestamp = builder.timestamp;
this.salt = builder.salt;
this.extIds = builder.extIds;

let extIdsCopy = Array.from(this.extIds);

//if there's a coinbase sig on the end, pop it off (FATIP-101)
if (extIdsCopy.length % 2 !== 0) extIdsCopy.pop();

while (extIdsCopy.length > 0) {
this.rcds.push(extIdsCopy[0]);
extIdsCopy.pop();
this.signatures.push(extIdsCopy[0]);
extIdsCopy.pop();
}

this.content = JSON.stringify({
inputs: this.inputs,
Expand Down
34 changes: 29 additions & 5 deletions rpc/RPC.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ const axios = require('axios');
const fctIdentityUtil = require('factom-identity-lib/src/validation');
const fctAddressUtil = require('factom/src/addresses');

const FAT0TokenRPC = require('../0/TokenRPC');

class RPCBuilder {
constructor(builder) {

Expand Down Expand Up @@ -111,6 +109,33 @@ class BaseTokenRPC {
}
}

//Token Specific Token RPCs (Optional, wraps response in class from corresponding token type)
let FAT0Transaction = require('../0/Transaction').Transaction;
let FAT0Issuance = require('../0/Issuance').Issuance;

class FAT0TokenRPC extends BaseTokenRPC {
constructor(rpc, rootChainId, tokenId) {
super(rpc, rootChainId, tokenId);
}

async getIssuance() {
let issuance = await super.getIssuance();
return new FAT0Issuance(issuance);
}

async getTransaction(txId) {
let transaction = await super.getTransaction(txId);
return new FAT0Transaction(transaction);
}

async getTransactions(txId, fa, start, limit) {
let transactions = await super.getTransactions(txId, fa, start, limit);
return transactions.map(tx => new FAT0Transaction(tx));
}
}



function generateTokenRPCParams(tokenRPC, params) {
return Object.assign({
'token-id': tokenRPC._tokenId,
Expand Down Expand Up @@ -139,6 +164,5 @@ async function call(rpc, method, params) {

module.exports = {
RPCBuilder,
RPC,
TokenRPC: BaseTokenRPC
};
BaseTokenRPC
};
2 changes: 1 addition & 1 deletion test/0/0.unit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('Unit Spec', function () {
.coinbase(tx)
.build();

assert(issuance.getRootChainId() === '888888d027c59579fc47a6fc6c4a5c0409c7c39bc38a86cb5fc0069978493762', "Unexpected root chain ID");
assert(issuance.getIssuerIdentityRootChainId() === '888888d027c59579fc47a6fc6c4a5c0409c7c39bc38a86cb5fc0069978493762', "Unexpected root chain ID");
assert(issuance.getType() === 'FAT-0', "Unexpected token type");
assert(issuance.getName() === 'Test Token', "Unexpected token Name");
assert(issuance.getSymbol() === 'TTK', "Unexpected token Symbol");
Expand Down

0 comments on commit 5a362a9

Please sign in to comment.