Skip to content

Commit dea25db

Browse files
croakyiampogo
authored andcommitted
sdk/node: add transaction tags
Afford the interface: ```js await client.transactions.transact(builder => { // ... builder.transactionTags = tags }) const txs = client.transactions .list({ filter: `actions(snapshot.transactionTags.foo=$1)`, filterParams: [tags.foo], }) .all() for await (const tx of txs) { console.log(tx.tags) console.log(tx.actions[0].snapshot.transactionTags) } ``` Closes #3638 Author: Dan Croak <dan@statusok.com> Date: Wed May 9 15:36:37 2018 -0700 upstream:3cd4ab1f3b389171b169f956d845db2ea1895443
1 parent 151bec5 commit dea25db

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

src/api/transactions.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import { validate } from '../validate'
2424
*
2525
* @property {Action[]} actions
2626
* List of specified actions for a transaction.
27+
*
28+
* @property {Object} tags
29+
* User-specified key-value data embedded in the transaction.
2730
*/
2831

2932
/**
@@ -32,6 +35,7 @@ import { validate } from '../validate'
3235
*/
3336
export class TransactionBuilder {
3437
public actions: any[]
38+
public transactionTags: any
3539

3640
/**
3741
* constructor - return a new object used for constructing a transaction.
@@ -43,6 +47,13 @@ export class TransactionBuilder {
4347
* @type Array
4448
*/
4549
this.actions = []
50+
51+
/**
52+
* Key-value tags for the transaction.
53+
* @name TransactionBuilder#transactionTags
54+
* @type Object
55+
*/
56+
this.transactionTags = null
4657
}
4758

4859
/**

test/transactions.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,40 @@ describe('Transaction', () => {
7575
assert.deepEqual(items[0].type, 'issue')
7676
})
7777

78+
it('adds transaction tags', async () => {
79+
const gold = await createFlavor('gold')
80+
const alice = await createAccount('alice')
81+
const tags = { foo: uuid.v4().toString() }
82+
83+
await client.transactions.transact(builder => {
84+
builder.issue({
85+
flavorId: gold.id,
86+
amount: 100,
87+
destinationAccountId: alice.id,
88+
})
89+
builder.transactionTags = tags
90+
})
91+
92+
const txs = await testHelpers.asyncAll(client.transactions
93+
.list({
94+
filter: `actions(snapshot.transactionTags.foo=$1)`,
95+
filterParams: [tags.foo],
96+
})
97+
.all())
98+
99+
expect(txs.length).to.equal(1)
100+
101+
txs.forEach(tx => {
102+
assert.deepEqual(tx.tags, tags)
103+
const action = tx.actions[0]
104+
assert.deepEqual(action.snapshot.transactionTags, tags)
105+
assert.deepEqual(action.type, 'issue')
106+
assert.deepEqual(action.amount, 100)
107+
assert.deepEqual(action.flavorId, gold.id)
108+
assert.deepEqual(action.destinationAccountId, alice.id)
109+
})
110+
})
111+
78112
it('handles large numbers', async () => {
79113
const gold = await createFlavor('gold')
80114
const alice = await createAccount('alice')

0 commit comments

Comments
 (0)