|
1 |
| -import { BaseTx, DbTxStatus, DbTxTypeId } from './datastore/common'; |
2 |
| -import { getTxTypeString, getTxStatusString } from './api/controllers/db-controller'; |
3 | 1 | import {
|
4 |
| - assertNotNullish as unwrapOptional, |
5 |
| - bufferToHexPrefixString, |
6 |
| - hexToBuffer, |
7 |
| -} from './helpers'; |
8 |
| -import { RosettaOperation, RosettaOptions } from '@blockstack/stacks-blockchain-api-types'; |
| 2 | + RosettaAccountIdentifier, |
| 3 | + RosettaOperation, |
| 4 | + RosettaOptions, |
| 5 | +} from '@blockstack/stacks-blockchain-api-types'; |
| 6 | +import { |
| 7 | + addressToString, |
| 8 | + AuthType, |
| 9 | + ContractCallPayload, |
| 10 | + PayloadType, |
| 11 | + TokenTransferPayload, |
| 12 | +} from '@blockstack/stacks-transactions'; |
| 13 | +import { |
| 14 | + emptyMessageSignature, |
| 15 | + isSingleSig, |
| 16 | +} from '@blockstack/stacks-transactions/lib/authorization'; |
| 17 | +import { BufferReader } from '@blockstack/stacks-transactions/lib/bufferReader'; |
9 | 18 | import {
|
10 |
| - StacksTransaction, |
11 | 19 | deserializeTransaction,
|
| 20 | + StacksTransaction, |
12 | 21 | } from '@blockstack/stacks-transactions/lib/transaction';
|
13 |
| -import { BufferReader } from '@blockstack/stacks-transactions/lib/bufferReader'; |
| 22 | +import { txidFromData } from '@blockstack/stacks-transactions/lib/utils'; |
14 | 23 | import * as btc from 'bitcoinjs-lib';
|
15 | 24 | import * as c32check from 'c32check';
|
16 |
| -import { RosettaNetworks, RosettaConstants } from './api/rosetta-constants'; |
17 |
| -import { readTransaction, TransactionPayloadTypeID } from './p2p/tx'; |
18 |
| -import { txidFromData } from '@blockstack/stacks-transactions/lib/utils'; |
| 25 | +import { getTxStatusString, getTxTypeString } from './api/controllers/db-controller'; |
| 26 | +import { RosettaConstants, RosettaNetworks } from './api/rosetta-constants'; |
| 27 | +import { BaseTx, DbTxStatus, DbTxTypeId } from './datastore/common'; |
19 | 28 | import { getTxSenderAddress, getTxSponsorAddress } from './event-stream/reader';
|
20 | 29 | import {
|
21 |
| - isSingleSig, |
22 |
| - emptyMessageSignature, |
23 |
| -} from '@blockstack/stacks-transactions/lib/authorization'; |
24 |
| -import { addressToString } from '@blockstack/stacks-transactions/lib/types'; |
| 30 | + assertNotNullish as unwrapOptional, |
| 31 | + bufferToHexPrefixString, |
| 32 | + hexToBuffer, |
| 33 | +} from './helpers'; |
| 34 | +import { readTransaction, TransactionPayloadTypeID } from './p2p/tx'; |
25 | 35 |
|
26 | 36 | enum CoinAction {
|
27 | 37 | CoinSpent = 'coin_spent',
|
@@ -348,3 +358,51 @@ export function rawTxToBaseTx(raw_tx: string): BaseTx {
|
348 | 358 |
|
349 | 359 | return dbtx;
|
350 | 360 | }
|
| 361 | + |
| 362 | +export function getSingers(transaction: StacksTransaction): RosettaAccountIdentifier[] | undefined { |
| 363 | + let address; |
| 364 | + if (transaction.payload.payloadType == PayloadType.TokenTransfer) { |
| 365 | + address = transaction.payload.recipient.address; |
| 366 | + } else if (transaction.payload.payloadType == PayloadType.ContractCall) { |
| 367 | + address = transaction.payload.contractAddress; |
| 368 | + } else { |
| 369 | + return; |
| 370 | + } |
| 371 | + const { type, version } = address; |
| 372 | + |
| 373 | + const account_identifier_signers: RosettaAccountIdentifier[] = []; |
| 374 | + if (transaction.auth.authType == AuthType.Standard) { |
| 375 | + if (transaction.auth.spendingCondition) { |
| 376 | + const singer = { |
| 377 | + address: addressToString({ |
| 378 | + version: version, |
| 379 | + hash160: transaction.auth.spendingCondition.signer, |
| 380 | + type: type, |
| 381 | + }), |
| 382 | + }; |
| 383 | + account_identifier_signers.push(singer); |
| 384 | + } |
| 385 | + } else if (transaction.auth.authType == AuthType.Sponsored) { |
| 386 | + if (transaction.auth.spendingCondition) { |
| 387 | + const singer = { |
| 388 | + address: addressToString({ |
| 389 | + version: version, |
| 390 | + hash160: transaction.auth.spendingCondition.signer, |
| 391 | + type: type, |
| 392 | + }), |
| 393 | + }; |
| 394 | + account_identifier_signers.push(singer); |
| 395 | + } |
| 396 | + if (transaction.auth.sponsorSpendingCondition) { |
| 397 | + const sponsored = { |
| 398 | + address: addressToString({ |
| 399 | + version: version, |
| 400 | + hash160: transaction.auth.sponsorSpendingCondition.signer, |
| 401 | + type: type, |
| 402 | + }), |
| 403 | + }; |
| 404 | + account_identifier_signers.push(sponsored); |
| 405 | + } |
| 406 | + } |
| 407 | + return account_identifier_signers; |
| 408 | +} |
0 commit comments