@alephium/web3 0.25.2 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-explorer.d.ts +85 -8
- package/dist/src/api/api-explorer.js +85 -10
- package/dist/src/utils/exchange.d.ts +7 -3
- package/dist/src/utils/exchange.js +49 -33
- package/dist/src/utils/index.d.ts +1 -1
- package/dist/src/utils/index.js +5 -4
- package/package.json +2 -2
- package/src/api/api-explorer.ts +137 -11
- package/src/utils/exchange.ts +49 -29
- package/src/utils/index.ts +4 -3
|
@@ -114,6 +114,14 @@ export interface ExplorerInfo {
|
|
|
114
114
|
/** @format int64 */
|
|
115
115
|
lastFinalizedInputTime: number;
|
|
116
116
|
}
|
|
117
|
+
export interface FungibleTokenMetadata {
|
|
118
|
+
/** @format 32-byte-hash */
|
|
119
|
+
id: string;
|
|
120
|
+
symbol: string;
|
|
121
|
+
name: string;
|
|
122
|
+
/** @format uint256 */
|
|
123
|
+
decimals: string;
|
|
124
|
+
}
|
|
117
125
|
export interface Hashrate {
|
|
118
126
|
/** @format int64 */
|
|
119
127
|
timestamp: number;
|
|
@@ -164,6 +172,20 @@ export interface MempoolTransaction {
|
|
|
164
172
|
/** @format int64 */
|
|
165
173
|
lastSeen: number;
|
|
166
174
|
}
|
|
175
|
+
export interface NFTCollectionMetadata {
|
|
176
|
+
/** @format address */
|
|
177
|
+
address: string;
|
|
178
|
+
collectionUri: string;
|
|
179
|
+
}
|
|
180
|
+
export interface NFTMetadata {
|
|
181
|
+
/** @format 32-byte-hash */
|
|
182
|
+
id: string;
|
|
183
|
+
tokenUri: string;
|
|
184
|
+
/** @format 32-byte-hash */
|
|
185
|
+
collectionId: string;
|
|
186
|
+
/** @format uint256 */
|
|
187
|
+
nftIndex: string;
|
|
188
|
+
}
|
|
167
189
|
export interface NotFound {
|
|
168
190
|
detail: string;
|
|
169
191
|
resource: string;
|
|
@@ -243,6 +265,17 @@ export interface Token {
|
|
|
243
265
|
/** @format uint256 */
|
|
244
266
|
amount: string;
|
|
245
267
|
}
|
|
268
|
+
export interface TokenInfo {
|
|
269
|
+
/** @format 32-byte-hash */
|
|
270
|
+
token: string;
|
|
271
|
+
/** Raw interface id, e.g. 0001 */
|
|
272
|
+
stdInterfaceId?: TokenStdInterfaceId | string;
|
|
273
|
+
}
|
|
274
|
+
export declare enum TokenStdInterfaceId {
|
|
275
|
+
Fungible = "fungible",
|
|
276
|
+
NonFungible = "non-fungible",
|
|
277
|
+
NonStandard = "non-standard"
|
|
278
|
+
}
|
|
246
279
|
export interface TokenSupply {
|
|
247
280
|
/** @format int64 */
|
|
248
281
|
timestamp: number;
|
|
@@ -306,6 +339,12 @@ export interface ValU256 {
|
|
|
306
339
|
value: string;
|
|
307
340
|
type: string;
|
|
308
341
|
}
|
|
342
|
+
export declare enum MaxSizeTokens {
|
|
343
|
+
Value80 = 80
|
|
344
|
+
}
|
|
345
|
+
export declare enum MaxSizeAddresses {
|
|
346
|
+
Value80 = 80
|
|
347
|
+
}
|
|
309
348
|
import 'cross-fetch/polyfill';
|
|
310
349
|
export type QueryParamsType = Record<string | number, any>;
|
|
311
350
|
export type ResponseFormat = keyof Omit<Body, 'body' | 'bodyUsed'>;
|
|
@@ -536,6 +575,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
536
575
|
* @tags Addresses
|
|
537
576
|
* @name GetAddressesAddressTokens
|
|
538
577
|
* @request GET:/addresses/{address}/tokens
|
|
578
|
+
* @deprecated
|
|
539
579
|
*/
|
|
540
580
|
getAddressesAddressTokens: (address: string, query?: {
|
|
541
581
|
/**
|
|
@@ -751,7 +791,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
751
791
|
};
|
|
752
792
|
tokens: {
|
|
753
793
|
/**
|
|
754
|
-
* @description List
|
|
794
|
+
* @description List token information
|
|
755
795
|
*
|
|
756
796
|
* @tags Tokens
|
|
757
797
|
* @name GetTokens
|
|
@@ -768,7 +808,20 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
768
808
|
* @format int32
|
|
769
809
|
*/
|
|
770
810
|
limit?: number;
|
|
771
|
-
|
|
811
|
+
/**
|
|
812
|
+
* fungible, non-fungible, non-standard or any interface id in hex-string format, e.g: 0001
|
|
813
|
+
* @format string
|
|
814
|
+
*/
|
|
815
|
+
'interface-id'?: TokenStdInterfaceId | string;
|
|
816
|
+
}, params?: RequestParams) => Promise<TokenInfo[]>;
|
|
817
|
+
/**
|
|
818
|
+
* @description list given tokens information
|
|
819
|
+
*
|
|
820
|
+
* @tags Tokens
|
|
821
|
+
* @name PostTokens
|
|
822
|
+
* @request POST:/tokens
|
|
823
|
+
*/
|
|
824
|
+
postTokens: (data?: string[], params?: RequestParams) => Promise<TokenInfo[]>;
|
|
772
825
|
/**
|
|
773
826
|
* @description List token transactions
|
|
774
827
|
*
|
|
@@ -788,6 +841,30 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
788
841
|
*/
|
|
789
842
|
limit?: number;
|
|
790
843
|
}, params?: RequestParams) => Promise<Transaction[]>;
|
|
844
|
+
/**
|
|
845
|
+
* @description Return metadata for the given fungible tokens, if metadata doesn't exist or token isn't a fungible, it won't be in the output list
|
|
846
|
+
*
|
|
847
|
+
* @tags Tokens
|
|
848
|
+
* @name PostTokensFungibleMetadata
|
|
849
|
+
* @request POST:/tokens/fungible-metadata
|
|
850
|
+
*/
|
|
851
|
+
postTokensFungibleMetadata: (data?: string[], params?: RequestParams) => Promise<FungibleTokenMetadata[]>;
|
|
852
|
+
/**
|
|
853
|
+
* @description Return metadata for the given nft tokens, if metadata doesn't exist or token isn't a nft, it won't be in the output list
|
|
854
|
+
*
|
|
855
|
+
* @tags Tokens
|
|
856
|
+
* @name PostTokensNftMetadata
|
|
857
|
+
* @request POST:/tokens/nft-metadata
|
|
858
|
+
*/
|
|
859
|
+
postTokensNftMetadata: (data?: string[], params?: RequestParams) => Promise<NFTMetadata[]>;
|
|
860
|
+
/**
|
|
861
|
+
* @description Return metadata for the given nft collection addresses, if metadata doesn't exist or address isn't a nft collection, it won't be in the output list
|
|
862
|
+
*
|
|
863
|
+
* @tags Tokens
|
|
864
|
+
* @name PostTokensNftCollectionMetadata
|
|
865
|
+
* @request POST:/tokens/nft-collection-metadata
|
|
866
|
+
*/
|
|
867
|
+
postTokensNftCollectionMetadata: (data?: string[], params?: RequestParams) => Promise<NFTCollectionMetadata[]>;
|
|
791
868
|
};
|
|
792
869
|
charts: {
|
|
793
870
|
/**
|
|
@@ -907,18 +984,18 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
907
984
|
* @description Get contract parent address if exist
|
|
908
985
|
*
|
|
909
986
|
* @tags Contracts
|
|
910
|
-
* @name
|
|
911
|
-
* @request GET:/contracts/{
|
|
987
|
+
* @name GetContractsContractAddressParent
|
|
988
|
+
* @request GET:/contracts/{contract_address}/parent
|
|
912
989
|
*/
|
|
913
|
-
|
|
990
|
+
getContractsContractAddressParent: (contractAddress: string, params?: RequestParams) => Promise<ContractParent>;
|
|
914
991
|
/**
|
|
915
992
|
* @description Get sub contract addresses
|
|
916
993
|
*
|
|
917
994
|
* @tags Contracts
|
|
918
|
-
* @name
|
|
919
|
-
* @request GET:/contracts/{
|
|
995
|
+
* @name GetContractsContractAddressSubContracts
|
|
996
|
+
* @request GET:/contracts/{contract_address}/sub-contracts
|
|
920
997
|
*/
|
|
921
|
-
|
|
998
|
+
getContractsContractAddressSubContracts: (contractAddress: string, query?: {
|
|
922
999
|
/**
|
|
923
1000
|
* Page number
|
|
924
1001
|
* @format int32
|
|
@@ -10,12 +10,26 @@
|
|
|
10
10
|
* ---------------------------------------------------------------
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.Api = exports.HttpClient = exports.ContentType = exports.IntervalType = void 0;
|
|
13
|
+
exports.Api = exports.HttpClient = exports.ContentType = exports.MaxSizeAddresses = exports.MaxSizeTokens = exports.TokenStdInterfaceId = exports.IntervalType = void 0;
|
|
14
14
|
var IntervalType;
|
|
15
15
|
(function (IntervalType) {
|
|
16
16
|
IntervalType["Daily"] = "daily";
|
|
17
17
|
IntervalType["Hourly"] = "hourly";
|
|
18
18
|
})(IntervalType = exports.IntervalType || (exports.IntervalType = {}));
|
|
19
|
+
var TokenStdInterfaceId;
|
|
20
|
+
(function (TokenStdInterfaceId) {
|
|
21
|
+
TokenStdInterfaceId["Fungible"] = "fungible";
|
|
22
|
+
TokenStdInterfaceId["NonFungible"] = "non-fungible";
|
|
23
|
+
TokenStdInterfaceId["NonStandard"] = "non-standard";
|
|
24
|
+
})(TokenStdInterfaceId = exports.TokenStdInterfaceId || (exports.TokenStdInterfaceId = {}));
|
|
25
|
+
var MaxSizeTokens;
|
|
26
|
+
(function (MaxSizeTokens) {
|
|
27
|
+
MaxSizeTokens[MaxSizeTokens["Value80"] = 80] = "Value80";
|
|
28
|
+
})(MaxSizeTokens = exports.MaxSizeTokens || (exports.MaxSizeTokens = {}));
|
|
29
|
+
var MaxSizeAddresses;
|
|
30
|
+
(function (MaxSizeAddresses) {
|
|
31
|
+
MaxSizeAddresses[MaxSizeAddresses["Value80"] = 80] = "Value80";
|
|
32
|
+
})(MaxSizeAddresses = exports.MaxSizeAddresses || (exports.MaxSizeAddresses = {}));
|
|
19
33
|
require("cross-fetch/polyfill");
|
|
20
34
|
const utils_1 = require("./utils");
|
|
21
35
|
var ContentType;
|
|
@@ -322,6 +336,7 @@ class Api extends HttpClient {
|
|
|
322
336
|
* @tags Addresses
|
|
323
337
|
* @name GetAddressesAddressTokens
|
|
324
338
|
* @request GET:/addresses/{address}/tokens
|
|
339
|
+
* @deprecated
|
|
325
340
|
*/
|
|
326
341
|
getAddressesAddressTokens: (address, query, params = {}) => this.request({
|
|
327
342
|
path: `/addresses/${address}/tokens`,
|
|
@@ -553,7 +568,7 @@ class Api extends HttpClient {
|
|
|
553
568
|
};
|
|
554
569
|
this.tokens = {
|
|
555
570
|
/**
|
|
556
|
-
* @description List
|
|
571
|
+
* @description List token information
|
|
557
572
|
*
|
|
558
573
|
* @tags Tokens
|
|
559
574
|
* @name GetTokens
|
|
@@ -566,6 +581,21 @@ class Api extends HttpClient {
|
|
|
566
581
|
format: 'json',
|
|
567
582
|
...params
|
|
568
583
|
}).then(utils_1.convertHttpResponse),
|
|
584
|
+
/**
|
|
585
|
+
* @description list given tokens information
|
|
586
|
+
*
|
|
587
|
+
* @tags Tokens
|
|
588
|
+
* @name PostTokens
|
|
589
|
+
* @request POST:/tokens
|
|
590
|
+
*/
|
|
591
|
+
postTokens: (data, params = {}) => this.request({
|
|
592
|
+
path: `/tokens`,
|
|
593
|
+
method: 'POST',
|
|
594
|
+
body: data,
|
|
595
|
+
type: ContentType.Json,
|
|
596
|
+
format: 'json',
|
|
597
|
+
...params
|
|
598
|
+
}).then(utils_1.convertHttpResponse),
|
|
569
599
|
/**
|
|
570
600
|
* @description List token transactions
|
|
571
601
|
*
|
|
@@ -579,6 +609,51 @@ class Api extends HttpClient {
|
|
|
579
609
|
query: query,
|
|
580
610
|
format: 'json',
|
|
581
611
|
...params
|
|
612
|
+
}).then(utils_1.convertHttpResponse),
|
|
613
|
+
/**
|
|
614
|
+
* @description Return metadata for the given fungible tokens, if metadata doesn't exist or token isn't a fungible, it won't be in the output list
|
|
615
|
+
*
|
|
616
|
+
* @tags Tokens
|
|
617
|
+
* @name PostTokensFungibleMetadata
|
|
618
|
+
* @request POST:/tokens/fungible-metadata
|
|
619
|
+
*/
|
|
620
|
+
postTokensFungibleMetadata: (data, params = {}) => this.request({
|
|
621
|
+
path: `/tokens/fungible-metadata`,
|
|
622
|
+
method: 'POST',
|
|
623
|
+
body: data,
|
|
624
|
+
type: ContentType.Json,
|
|
625
|
+
format: 'json',
|
|
626
|
+
...params
|
|
627
|
+
}).then(utils_1.convertHttpResponse),
|
|
628
|
+
/**
|
|
629
|
+
* @description Return metadata for the given nft tokens, if metadata doesn't exist or token isn't a nft, it won't be in the output list
|
|
630
|
+
*
|
|
631
|
+
* @tags Tokens
|
|
632
|
+
* @name PostTokensNftMetadata
|
|
633
|
+
* @request POST:/tokens/nft-metadata
|
|
634
|
+
*/
|
|
635
|
+
postTokensNftMetadata: (data, params = {}) => this.request({
|
|
636
|
+
path: `/tokens/nft-metadata`,
|
|
637
|
+
method: 'POST',
|
|
638
|
+
body: data,
|
|
639
|
+
type: ContentType.Json,
|
|
640
|
+
format: 'json',
|
|
641
|
+
...params
|
|
642
|
+
}).then(utils_1.convertHttpResponse),
|
|
643
|
+
/**
|
|
644
|
+
* @description Return metadata for the given nft collection addresses, if metadata doesn't exist or address isn't a nft collection, it won't be in the output list
|
|
645
|
+
*
|
|
646
|
+
* @tags Tokens
|
|
647
|
+
* @name PostTokensNftCollectionMetadata
|
|
648
|
+
* @request POST:/tokens/nft-collection-metadata
|
|
649
|
+
*/
|
|
650
|
+
postTokensNftCollectionMetadata: (data, params = {}) => this.request({
|
|
651
|
+
path: `/tokens/nft-collection-metadata`,
|
|
652
|
+
method: 'POST',
|
|
653
|
+
body: data,
|
|
654
|
+
type: ContentType.Json,
|
|
655
|
+
format: 'json',
|
|
656
|
+
...params
|
|
582
657
|
}).then(utils_1.convertHttpResponse)
|
|
583
658
|
};
|
|
584
659
|
this.charts = {
|
|
@@ -676,11 +751,11 @@ class Api extends HttpClient {
|
|
|
676
751
|
* @description Get contract parent address if exist
|
|
677
752
|
*
|
|
678
753
|
* @tags Contracts
|
|
679
|
-
* @name
|
|
680
|
-
* @request GET:/contracts/{
|
|
754
|
+
* @name GetContractsContractAddressParent
|
|
755
|
+
* @request GET:/contracts/{contract_address}/parent
|
|
681
756
|
*/
|
|
682
|
-
|
|
683
|
-
path: `/contracts/${
|
|
757
|
+
getContractsContractAddressParent: (contractAddress, params = {}) => this.request({
|
|
758
|
+
path: `/contracts/${contractAddress}/parent`,
|
|
684
759
|
method: 'GET',
|
|
685
760
|
format: 'json',
|
|
686
761
|
...params
|
|
@@ -689,11 +764,11 @@ class Api extends HttpClient {
|
|
|
689
764
|
* @description Get sub contract addresses
|
|
690
765
|
*
|
|
691
766
|
* @tags Contracts
|
|
692
|
-
* @name
|
|
693
|
-
* @request GET:/contracts/{
|
|
767
|
+
* @name GetContractsContractAddressSubContracts
|
|
768
|
+
* @request GET:/contracts/{contract_address}/sub-contracts
|
|
694
769
|
*/
|
|
695
|
-
|
|
696
|
-
path: `/contracts/${
|
|
770
|
+
getContractsContractAddressSubContracts: (contractAddress, query, params = {}) => this.request({
|
|
771
|
+
path: `/contracts/${contractAddress}/sub-contracts`,
|
|
697
772
|
method: 'GET',
|
|
698
773
|
query: query,
|
|
699
774
|
format: 'json',
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { Transaction } from '../api/api-alephium';
|
|
2
2
|
import { Address } from '../signer';
|
|
3
3
|
export declare function validateExchangeAddress(address: string): void;
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
4
|
+
export declare function isSimpleALPHTransferTx(tx: Transaction): boolean;
|
|
5
|
+
export declare function isSimpleTransferTokenTx(tx: Transaction): boolean;
|
|
6
|
+
export declare function getALPHDepositInfo(tx: Transaction): {
|
|
7
|
+
targetAddress: Address;
|
|
8
|
+
depositAmount: bigint;
|
|
9
|
+
};
|
|
10
|
+
export declare function getSenderAddress(tx: Transaction): Address;
|
|
7
11
|
export declare function getAddressFromUnlockScript(unlockScript: string): Address;
|
|
@@ -17,7 +17,7 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
17
17
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.getAddressFromUnlockScript = exports.
|
|
20
|
+
exports.getAddressFromUnlockScript = exports.getSenderAddress = exports.getALPHDepositInfo = exports.isSimpleTransferTokenTx = exports.isSimpleALPHTransferTx = exports.validateExchangeAddress = void 0;
|
|
21
21
|
const __1 = require("..");
|
|
22
22
|
function validateExchangeAddress(address) {
|
|
23
23
|
let decoded;
|
|
@@ -38,19 +38,38 @@ function validateExchangeAddress(address) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
exports.validateExchangeAddress = validateExchangeAddress;
|
|
41
|
-
function
|
|
42
|
-
return
|
|
41
|
+
function isSimpleALPHTransferTx(tx) {
|
|
42
|
+
return isSimpleTransferTx(tx) && checkALPHOutput(tx);
|
|
43
43
|
}
|
|
44
|
-
exports.
|
|
45
|
-
function
|
|
46
|
-
|
|
44
|
+
exports.isSimpleALPHTransferTx = isSimpleALPHTransferTx;
|
|
45
|
+
function isSimpleTransferTokenTx(tx) {
|
|
46
|
+
const isTransferTx = isSimpleTransferTx(tx);
|
|
47
|
+
if (isTransferTx) {
|
|
48
|
+
const senderAddress = getSenderAddress(tx);
|
|
49
|
+
const targetAddress = tx.unsigned.fixedOutputs.find((o) => o.address !== senderAddress).address;
|
|
50
|
+
return checkTokenOutput(tx, targetAddress);
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
exports.isSimpleTransferTokenTx = isSimpleTransferTokenTx;
|
|
55
|
+
// we assume that the tx is a simple transfer tx, i.e. isSimpleTransferALPHTx(tx) == true
|
|
56
|
+
function getALPHDepositInfo(tx) {
|
|
57
|
+
const senderAddress = getSenderAddress(tx);
|
|
58
|
+
const targetAddress = tx.unsigned.fixedOutputs.find((o) => o.address !== senderAddress).address;
|
|
59
|
+
let depositAmount = 0n;
|
|
60
|
+
tx.unsigned.fixedOutputs.forEach((o) => {
|
|
61
|
+
if (o.address === targetAddress) {
|
|
62
|
+
depositAmount += BigInt(o.attoAlphAmount);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return { targetAddress, depositAmount };
|
|
47
66
|
}
|
|
48
|
-
exports.
|
|
49
|
-
// we assume that the tx is
|
|
50
|
-
function
|
|
67
|
+
exports.getALPHDepositInfo = getALPHDepositInfo;
|
|
68
|
+
// we assume that the tx is a simple transfer tx, i.e. isSimpleTransferALPHTx(tx) == true
|
|
69
|
+
function getSenderAddress(tx) {
|
|
51
70
|
return getAddressFromUnlockScript(tx.unsigned.inputs[0].unlockScript);
|
|
52
71
|
}
|
|
53
|
-
exports.
|
|
72
|
+
exports.getSenderAddress = getSenderAddress;
|
|
54
73
|
var UnlockScriptType;
|
|
55
74
|
(function (UnlockScriptType) {
|
|
56
75
|
UnlockScriptType[UnlockScriptType["P2PKH"] = 0] = "P2PKH";
|
|
@@ -81,50 +100,47 @@ function getAddressFromUnlockScript(unlockScript) {
|
|
|
81
100
|
}
|
|
82
101
|
}
|
|
83
102
|
exports.getAddressFromUnlockScript = getAddressFromUnlockScript;
|
|
84
|
-
function
|
|
103
|
+
function getSenderAddressAnyTx(tx) {
|
|
85
104
|
try {
|
|
86
105
|
const inputAddresses = tx.unsigned.inputs.map((i) => getAddressFromUnlockScript(i.unlockScript));
|
|
87
106
|
// we have checked that the inputs is not empty
|
|
88
|
-
const
|
|
89
|
-
return inputAddresses.slice(1).every((addr) => addr ===
|
|
107
|
+
const sender = inputAddresses[0];
|
|
108
|
+
return inputAddresses.slice(1).every((addr) => addr === sender) ? sender : undefined;
|
|
90
109
|
}
|
|
91
110
|
catch (_) {
|
|
92
111
|
return undefined;
|
|
93
112
|
}
|
|
94
113
|
}
|
|
95
|
-
function checkOutputAddress(tx, from, to) {
|
|
96
|
-
let fromCount = 0;
|
|
97
|
-
let toCount = 0;
|
|
98
|
-
tx.unsigned.fixedOutputs.forEach((o) => {
|
|
99
|
-
if (o.address === from) {
|
|
100
|
-
fromCount += 1;
|
|
101
|
-
}
|
|
102
|
-
else if (o.address === to) {
|
|
103
|
-
toCount += 1;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
const outputCount = tx.unsigned.fixedOutputs.length;
|
|
107
|
-
return toCount === 1 && fromCount === outputCount - 1;
|
|
108
|
-
}
|
|
109
114
|
function checkALPHOutput(tx) {
|
|
110
115
|
const outputs = tx.unsigned.fixedOutputs;
|
|
111
116
|
return outputs.every((o) => o.tokens.length === 0);
|
|
112
117
|
}
|
|
113
118
|
function checkTokenOutput(tx, to) {
|
|
114
119
|
// we have checked the output address
|
|
115
|
-
const
|
|
116
|
-
|
|
120
|
+
const outputs = tx.unsigned.fixedOutputs.filter((o) => o.address === to);
|
|
121
|
+
if (outputs[0].tokens.length === 0) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
const tokenId = outputs[0].tokens[0].id;
|
|
125
|
+
return outputs.every((o) => BigInt(o.attoAlphAmount) === __1.DUST_AMOUNT && o.tokens.length === 1 && o.tokens[0].id === tokenId);
|
|
117
126
|
}
|
|
118
|
-
function
|
|
127
|
+
function isSimpleTransferTx(tx) {
|
|
119
128
|
if (tx.contractInputs.length !== 0 ||
|
|
120
129
|
tx.generatedOutputs.length !== 0 ||
|
|
121
130
|
tx.unsigned.inputs.length === 0 ||
|
|
122
131
|
tx.unsigned.scriptOpt !== undefined) {
|
|
123
132
|
return false;
|
|
124
133
|
}
|
|
125
|
-
const
|
|
126
|
-
if (
|
|
134
|
+
const sender = getSenderAddressAnyTx(tx);
|
|
135
|
+
if (sender === undefined) {
|
|
127
136
|
return false;
|
|
128
137
|
}
|
|
129
|
-
|
|
138
|
+
const outputAddresses = [];
|
|
139
|
+
tx.unsigned.fixedOutputs.forEach((o) => {
|
|
140
|
+
if (!outputAddresses.includes(o.address)) {
|
|
141
|
+
outputAddresses.push(o.address);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return ((outputAddresses.length === 1 && outputAddresses[0] !== sender) ||
|
|
145
|
+
(outputAddresses.length === 2 && outputAddresses.includes(sender)));
|
|
130
146
|
}
|
|
@@ -6,4 +6,4 @@ export * from './utils';
|
|
|
6
6
|
export * from './subscription';
|
|
7
7
|
export * from './sign';
|
|
8
8
|
export * from './number';
|
|
9
|
-
export { validateExchangeAddress,
|
|
9
|
+
export { validateExchangeAddress, isSimpleALPHTransferTx, isSimpleTransferTokenTx, getSenderAddress, getALPHDepositInfo } from './exchange';
|
package/dist/src/utils/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
31
31
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
32
32
|
};
|
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.
|
|
34
|
+
exports.getALPHDepositInfo = exports.getSenderAddress = exports.isSimpleTransferTokenTx = exports.isSimpleALPHTransferTx = exports.validateExchangeAddress = void 0;
|
|
35
35
|
__exportStar(require("./webcrypto"), exports);
|
|
36
36
|
__exportStar(require("./address"), exports);
|
|
37
37
|
__exportStar(require("./bs58"), exports);
|
|
@@ -42,6 +42,7 @@ __exportStar(require("./sign"), exports);
|
|
|
42
42
|
__exportStar(require("./number"), exports);
|
|
43
43
|
var exchange_1 = require("./exchange");
|
|
44
44
|
Object.defineProperty(exports, "validateExchangeAddress", { enumerable: true, get: function () { return exchange_1.validateExchangeAddress; } });
|
|
45
|
-
Object.defineProperty(exports, "
|
|
46
|
-
Object.defineProperty(exports, "
|
|
47
|
-
Object.defineProperty(exports, "
|
|
45
|
+
Object.defineProperty(exports, "isSimpleALPHTransferTx", { enumerable: true, get: function () { return exchange_1.isSimpleALPHTransferTx; } });
|
|
46
|
+
Object.defineProperty(exports, "isSimpleTransferTokenTx", { enumerable: true, get: function () { return exchange_1.isSimpleTransferTokenTx; } });
|
|
47
|
+
Object.defineProperty(exports, "getSenderAddress", { enumerable: true, get: function () { return exchange_1.getSenderAddress; } });
|
|
48
|
+
Object.defineProperty(exports, "getALPHDepositInfo", { enumerable: true, get: function () { return exchange_1.getALPHDepositInfo; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "A JS/TS library to interact with the Alephium platform",
|
|
5
5
|
"license": "GPL",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"author": "Alephium dev <dev@alephium.org>",
|
|
29
29
|
"config": {
|
|
30
30
|
"alephium_version": "2.5.5",
|
|
31
|
-
"explorer_backend_version": "1.
|
|
31
|
+
"explorer_backend_version": "1.16.0"
|
|
32
32
|
},
|
|
33
33
|
"type": "commonjs",
|
|
34
34
|
"dependencies": {
|