Skip to content

Commit

Permalink
assignGroupID handles mixed txn-dict and txn-obj (#236)
Browse files Browse the repository at this point in the history
Review: #236
Resolves: #178
  • Loading branch information
EvanJRichard authored Nov 3, 2020
1 parent bc92606 commit bc0f61d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ function computeGroupID(txns) {
function assignGroupID(txns, from = undefined) {
const gid = computeGroupID(txns);
let result = [];
for (tx of txns) {
if (!from || address.encodeAddress(tx.from.publicKey) == from) {
for (let txn of txns) {
if (!from || address.encodeAddress(txn.from.publicKey) == from) {
let tx = txn;
if (!(tx instanceof txnBuilder.Transaction)) {
tx = new txnBuilder.Transaction(txn);
}
tx.group = gid;
result.push(tx);
}
Expand Down
36 changes: 36 additions & 0 deletions tests/5.Transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,5 +605,41 @@ describe('Sign', function () {
assetIndex, freezeTarget, freezeState, rekeyTo);
assert.deepStrictEqual(expectedTxn, actualTxn);
});
it('should be able to use helper to assign group ID to mixed Transaction and Dict', function() {
let suggestedParams = {
"genesisHash": "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=",
"genesisID": "",
"firstRound": 322575,
"lastRound": 322575 + 1000,
"fee": 1000,
"flatFee": true
};

let helperTx = algosdk.makePaymentTxnWithSuggestedParams("GAQVB24XEPYOPBQNJQAE4K3OLNYTRYD65ZKR3OEW5TDOOGL7MDKABXHHTM",
"GAQVB24XEPYOPBQNJQAE4K3OLNYTRYD65ZKR3OEW5TDOOGL7MDKABXHHTM", 1000, undefined,
new Uint8Array(0), suggestedParams);

let dictTx = {
"from": "GAQVB24XEPYOPBQNJQAE4K3OLNYTRYD65ZKR3OEW5TDOOGL7MDKABXHHTM",
"to": "GAQVB24XEPYOPBQNJQAE4K3OLNYTRYD65ZKR3OEW5TDOOGL7MDKABXHHTM",
"fee": 1000,
"flatFee": true,
"amount": 0,
"firstRound": 322575,
"lastRound": 322575 + 1000,
"genesisID": "",
"genesisHash": "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=",
"type": "pay"
};

// Store both transactions
let txns = [helperTx, dictTx];

// Group both transactions
let txgroup = algosdk.assignGroupID(txns);

assert.deepStrictEqual(txgroup[0].group, txgroup[1].group)

});
});
});

0 comments on commit bc0f61d

Please sign in to comment.