Skip to content

Commit

Permalink
Merge pull request #21 from dragonchain/master
Browse files Browse the repository at this point in the history
Release 4.3.0
  • Loading branch information
cheeseandcereal committed Feb 5, 2020
2 parents a732ac8 + 60f2cdb commit 7e82e49
Show file tree
Hide file tree
Showing 16 changed files with 922 additions and 655 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS

This file was deleted.

10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 4.3.0

- **Feature**
- Add option for deleting smart contract by transaction type
- Add support for publishing signed interchain transactions
- Export `DragonchainClient` type for external use
- **Development:**
- Update development dependencies
- Remove codeowners

## 4.2.1

- **Feature:**
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2019 Dragonchain, Inc. or its affiliates. All Rights Reserved.
Copyright 2020 Dragonchain, Inc. or its affiliates. All Rights Reserved.

Apache License
Version 2.0, January 2004
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dragonchain-sdk",
"version": "4.2.1",
"version": "4.3.0",
"description": "Dragonchain SDK for Node.JS and the Browser",
"license": "Apache-2.0",
"homepage": "https://github.com/dragonchain/dragonchain-sdk-javascript#readme",
Expand Down Expand Up @@ -80,25 +80,25 @@
"tslib": "^1.10.0"
},
"devDependencies": {
"@types/chai": "^4.2.6",
"@types/chai": "^4.2.8",
"@types/ini": "^1.3.30",
"@types/mocha": "^5.2.7",
"@types/node": "^12.12.14",
"@types/mocha": "^7.0.1",
"@types/node": "^13.7.0",
"@types/node-fetch": "^2.5.4",
"@types/sinon": "^7.5.1",
"@types/sinon-chai": "^3.2.3",
"@typescript-eslint/eslint-plugin": "^2.10.0",
"@typescript-eslint/parser": "^2.10.0",
"@typescript-eslint/eslint-plugin": "^2.19.0",
"@typescript-eslint/parser": "^2.19.0",
"chai": "^4.2.0",
"eslint": "^6.7.2",
"eslint-config-prettier": "^6.7.0",
"mocha": "^6.2.2",
"nyc": "^14.1.1",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"mocha": "^7.0.1",
"nyc": "^15.0.0",
"prettier": "^1.19.1",
"sinon": "^7.5.0",
"sinon-chai": "^3.3.0",
"ts-node": "^8.5.4",
"typedoc": "^0.15.3",
"typescript": "^3.7.3"
"sinon": "^8.1.1",
"sinon-chai": "^3.4.0",
"ts-node": "^8.6.2",
"typedoc": "^0.16.9",
"typescript": "^3.7.5"
}
}
2 changes: 1 addition & 1 deletion src/errors/FailureByDesign.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019 Dragonchain, Inc. or its affiliates. All Rights Reserved.
* Copyright 2020 Dragonchain, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019 Dragonchain, Inc. or its affiliates. All Rights Reserved.
* Copyright 2020 Dragonchain, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { createClient } from './services/dragonchain-client/DragonchainClient';
import { createClient, DragonchainClient as Client } from './services/dragonchain-client/DragonchainClient';

/**
* @hidden
Expand All @@ -38,3 +38,4 @@ const setLogger = (newLogger: any = { log: nullLog, info: nullLog, warn: nullLog
setLogger(); // actually initialize the singleton on initial import

export { createClient, setLogger, logger };
export type DragonchainClient = typeof Client;
16 changes: 15 additions & 1 deletion src/interfaces/DragonchainClientInterfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019 Dragonchain, Inc. or its affiliates. All Rights Reserved.
* Copyright 2020 Dragonchain, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -316,6 +316,20 @@ export interface InterchainNetworkList {
interchains: BitcoinInterchainNetwork[] | EthereumInterchainNetwork[] | BinanceInterchainNetwork[];
}

/**
* Transaction hash (or equivalent) of a published interchain transaction
* @example
* ```json
*
* {
* "transaction": "0x37d1b1032288f7b434973c7840123bbf1acdb5ef5e40dda94257208ccf6c0c9f"
* }
* ```
*/
export interface PublishedInterchainTransaction {
transaction: string;
}

/**
* @example
* ```json
Expand Down
2 changes: 1 addition & 1 deletion src/services/config-service/ConfigCient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019 Dragonchain, Inc. or its affiliates. All Rights Reserved.
* Copyright 2020 Dragonchain, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/services/config-service/ConfigClient.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019 Dragonchain, Inc. or its affiliates. All Rights Reserved.
* Copyright 2020 Dragonchain, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/services/config-service/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019 Dragonchain, Inc. or its affiliates. All Rights Reserved.
* Copyright 2020 Dragonchain, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/services/credential-service/CredentialService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019 Dragonchain, Inc. or its affiliates. All Rights Reserved.
* Copyright 2020 Dragonchain, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/services/credential-service/CredentialService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019 Dragonchain, Inc. or its affiliates. All Rights Reserved.
* Copyright 2020 Dragonchain, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/services/credential-service/DragonchainCredentials.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019 Dragonchain, Inc. or its affiliates. All Rights Reserved.
* Copyright 2020 Dragonchain, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
24 changes: 22 additions & 2 deletions src/services/dragonchain-client/DragonchainClient.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019 Dragonchain, Inc. or its affiliates. All Rights Reserved.
* Copyright 2020 Dragonchain, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -247,11 +247,17 @@ describe('DragonchainClient', () => {
};

describe('.deleteSmartContract', () => {
it('calls #fetch() with correct params', async () => {
it('calls #fetch() with correct params (smart contract ID)', async () => {
const param = 'banana';
await client.deleteSmartContract({ smartContractId: param });
assert.calledWith(fetch, 'fakeUrl/v1/contract/banana', expectedFetchOptions);
});

it('calls #fetch() with correct params (transaction type)', async () => {
const param = 'banana';
await client.deleteSmartContract({ transactionType: param });
assert.calledWith(fetch, 'fakeUrl/v1/contract/txn_type/banana', expectedFetchOptions);
});
});

describe('.deleteApiKey', () => {
Expand Down Expand Up @@ -501,6 +507,20 @@ describe('DragonchainClient', () => {
assert.calledWith(fetch, 'fakeUrl/v1/interchains/default', obj);
});
});

describe('.publishInterchainTransaction', () => {
it('calls #fetch() with correct params', async () => {
const fakeBody: any = {
version: '1',
blockchain: 'bitcoin',
name: 'banana',
signed_txn: 'banana'
};
await client.publishInterchainTransaction({ name: 'banana', blockchain: 'bitcoin', signedTransaction: 'banana' });
const obj = { ...expectedFetchOptions, body: JSON.stringify(fakeBody) };
assert.calledWith(fetch, 'fakeUrl/v1/interchains/transaction/publish', obj);
});
});
});

describe('PUT', () => {
Expand Down
44 changes: 40 additions & 4 deletions src/services/dragonchain-client/DragonchainClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019 Dragonchain, Inc. or its affiliates. All Rights Reserved.
* Copyright 2020 Dragonchain, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,6 +51,7 @@ import {
BinanceInterchainNetwork,
SupportedInterchains,
InterchainNetworkList,
PublishedInterchainTransaction,
CustomTextFieldOptions,
CustomNumberFieldOptions,
CustomTagFieldOptions,
Expand Down Expand Up @@ -655,10 +656,16 @@ export class DragonchainClient {
/**
* The id of the smart contract to delete. Should be a guid
*/
smartContractId: string;
smartContractId?: string;
/**
* Transaction type of the smart contract, mutually exclusive with smartContractId
*/
transactionType?: string;
}) => {
if (!options.smartContractId) throw new FailureByDesign('PARAM_ERROR', 'Parameter `smartContractId` is required');
return (await this.delete(`/v1/contract/${options.smartContractId}`)) as Response<SimpleResponse>;
if (options.smartContractId && options.transactionType) throw new FailureByDesign('PARAM_ERROR', 'Only one of `smartContractId` or `transactionType` can be specified');
if (options.smartContractId) return (await this.delete(`/v1/contract/${options.smartContractId}`)) as Response<SimpleResponse>;
if (options.transactionType) return (await this.delete(`/v1/contract/txn_type/${options.transactionType}`)) as Response<SimpleResponse>;
throw new FailureByDesign('PARAM_ERROR', 'At least one of `smartContractId` or `transactionType` must be supplied');
};

/**
Expand Down Expand Up @@ -1289,6 +1296,35 @@ export class DragonchainClient {
return (await this.get('/v1/interchains/default')) as Response<EthereumInterchainNetwork | BitcoinInterchainNetwork>;
};

/**
* Publish an interchain transaction that's already been signed
*/
public publishInterchainTransaction = async (options: {
/**
* The blockchain type to set (i.e. 'bitcoin', 'ethereum')
*/
blockchain: SupportedInterchains;
/**
* The name of that blockchain's network to use (set when creating the network)
*/
name: string;
/**
* Signed transaction string (return from sign<network>Transaction function)
*/
signedTransaction: string;
}) => {
if (!options.blockchain) throw new FailureByDesign('PARAM_ERROR', 'Parameter `blockchain` is required');
if (!options.name) throw new FailureByDesign('PARAM_ERROR', 'Parameter `name` is required');
if (!options.signedTransaction) throw new FailureByDesign('PARAM_ERROR', 'Parameter `signedTransaction` is required');
const body: any = {
version: '1',
blockchain: options.blockchain,
name: options.name,
signed_txn: options.signedTransaction
};
return (await this.post('/v1/interchains/transaction/publish', body)) as Response<PublishedInterchainTransaction>;
};

/**
* !This method is deprecated and should not be used!
* Backwards compatibility will exist for legacy chains, but will not work on new chains. listInterchainNetworks should be used instead
Expand Down

0 comments on commit 7e82e49

Please sign in to comment.