Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CAP0015 (FeeBump). #321

Merged
merged 31 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5921842
Fix hash generation with v1 or v0 transactions.
abuiles Apr 9, 2020
71f2ef7
Fix transaction envelope for TransactionV1Envelope.
abuiles Apr 10, 2020
fa2eea1
Add hidden flag to allow building v1 tx with tx builder.
abuiles Apr 10, 2020
8b6421c
Add Transaction.buildFeeBumpTransaction
abuiles Apr 10, 2020
ec9e04c
Change v1 feature flag name.
abuiles Apr 10, 2020
f987eb4
Add docs for new methods.
abuiles Apr 10, 2020
6e74d35
Fix ts types.
abuiles Apr 10, 2020
038bc18
Start fee and source from tx.
abuiles Apr 13, 2020
0d5eb38
Add innerFee and innerSignatures.
abuiles Apr 13, 2020
f9ffbd7
Fix test and make all related args a string.
abuiles Apr 13, 2020
cff1ae5
Add tests against expected xdr.
abuiles Apr 13, 2020
b5f69ec
Move buildFeeBumpTransaction to TransactionBuilder class.
abuiles Apr 13, 2020
8d3cac5
Fix ts tests.
abuiles Apr 13, 2020
4d306e4
Calculate fee from baseFee.
abuiles Apr 13, 2020
bdd2bbd
Move helper back to transaction.
abuiles Apr 13, 2020
1569dbb
Validate minFee.
abuiles Apr 13, 2020
d101496
Show received envelope type.
abuiles Apr 13, 2020
3e06b1e
Fix dependency cycle.
abuiles Apr 13, 2020
75013bb
Move buildFeeBumpTransaction to transaction builder.
abuiles Apr 14, 2020
1ca9afc
Add second condition for minimum base base.
abuiles Apr 14, 2020
0883dad
Fix types.
abuiles Apr 14, 2020
e61506d
Add comment.
abuiles Apr 14, 2020
e95b89d
Simplify minBase fee check.
abuiles Apr 14, 2020
3da9538
Receive a Transaction instead of a xdr.TransactionV1Envelope.
abuiles Apr 14, 2020
272b24d
Fix type for buildFeeBumpTransaction.
abuiles Apr 14, 2020
97ae0da
Fix typo for _envelopeType.
abuiles Apr 14, 2020
3b6eac9
Remove unused import
abuiles Apr 14, 2020
0dc1e00
Use builder to generate innerTx.
abuiles Apr 14, 2020
002f70d
Fix test.
abuiles Apr 14, 2020
c239c54
Add test for invalid envelopeType.
abuiles Apr 14, 2020
e0d734f
Validate transaction envelope to be of type v1.
abuiles Apr 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix test and make all related args a string.
  • Loading branch information
abuiles committed Apr 13, 2020
commit f9ffbd76aaa9ddaf4b8fad99f9dc394088e0791b
9 changes: 6 additions & 3 deletions src/transaction_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Memo } from './memo';
* @constant
* @see [Fees](https://www.stellar.org/developers/guides/concepts/fees.html)
*/
export const BASE_FEE = 100; // Stroops
export const BASE_FEE = '100'; // Stroops

/**
* @constant
Expand Down Expand Up @@ -70,7 +70,7 @@ export const TimeoutInfinite = 0;
* @constructor
* @param {Account} sourceAccount - The source account for this transaction.
* @param {object} opts Options object
* @param {number} opts.fee - The max fee willing to pay per operation in this transaction (**in stroops**). Required.
* @param {string} opts.fee - The max fee willing to pay per operation in this transaction (**in stroops**). Required.
* @param {object} [opts.timebounds] - The timebounds for the validity of this transaction.
* @param {number|string|Date} [opts.timebounds.minTime] - 64 bit unix timestamp or Date object
* @param {number|string|Date} [opts.timebounds.maxTime] - 64 bit unix timestamp or Date object
Expand Down Expand Up @@ -188,8 +188,11 @@ export class TransactionBuilder {
*/
build() {
const sequenceNumber = new BigNumber(this.source.sequenceNumber()).add(1);
const fee = new BigNumber(this.baseFee)
.mul(this.operations.length)
.toNumber();
const attrs = {
fee: this.baseFee * this.operations.length,
fee,
seqNum: xdr.SequenceNumber.fromString(sequenceNumber.toString()),
memo: this.memo ? this.memo.toXDRObject() : null
};
Expand Down
34 changes: 21 additions & 13 deletions test/unit/transaction_builder_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('TransactionBuilder', function() {
});

it('should have 100 stroops fee', function(done) {
expect(transaction.fee).to.be.equal(100);
expect(transaction.fee).to.be.equal('100');
done();
});
});
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('TransactionBuilder', function() {
});

it('should have 200 stroops fee', function(done) {
expect(transaction.fee).to.be.equal(200);
expect(transaction.fee).to.be.equal('200');
done();
});
});
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('TransactionBuilder', function() {
});

it('should have 2000 stroops fee', function(done) {
expect(transaction.fee).to.be.equal(2000);
expect(transaction.fee).to.be.equal('2000');
done();
});
});
Expand Down Expand Up @@ -260,8 +260,8 @@ describe('TransactionBuilder', function() {
done();
});
});
describe('timebounds', function(){
it('requires maxTime', function(){
describe('timebounds', function() {
it('requires maxTime', function() {
let source = new StellarBase.Account(
'GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ',
'0'
Expand All @@ -273,9 +273,11 @@ describe('TransactionBuilder', function() {
},
fee: 100
}).build();
}).to.throw('TimeBounds has to be set or you must call setTimeout(TimeoutInfinite).');
}).to.throw(
'TimeBounds has to be set or you must call setTimeout(TimeoutInfinite).'
);
});
it('requires minTime', function(){
it('requires minTime', function() {
let source = new StellarBase.Account(
'GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ',
'0'
Expand All @@ -287,9 +289,11 @@ describe('TransactionBuilder', function() {
},
fee: 100
}).build();
}).to.throw('TimeBounds has to be set or you must call setTimeout(TimeoutInfinite).');
}).to.throw(
'TimeBounds has to be set or you must call setTimeout(TimeoutInfinite).'
);
});
it('works with timebounds defined', function(){
it('works with timebounds defined', function() {
let source = new StellarBase.Account(
'GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ',
'0'
Expand All @@ -304,7 +308,7 @@ describe('TransactionBuilder', function() {
}).build();
}).to.not.throw();
});
it('fails with empty timebounds', function(){
it('fails with empty timebounds', function() {
let source = new StellarBase.Account(
'GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ',
'0'
Expand All @@ -314,7 +318,9 @@ describe('TransactionBuilder', function() {
timebounds: {},
fee: 100
}).build();
}).to.throw('TimeBounds has to be set or you must call setTimeout(TimeoutInfinite).');
}).to.throw(
'TimeBounds has to be set or you must call setTimeout(TimeoutInfinite).'
);
});
});
describe('setTimeout', function() {
Expand Down Expand Up @@ -440,15 +446,17 @@ describe('TransactionBuilder', function() {
timeoutTimestamp.toString()
);
});
it('works with TimeoutInfinite', function(){
it('works with TimeoutInfinite', function() {
let source = new StellarBase.Account(
'GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ',
'0'
);
expect(() => {
new StellarBase.TransactionBuilder(source, {
fee: 100
}).setTimeout(0).build();
})
.setTimeout(0)
.build();
}).to.not.throw();
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/unit/transaction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Transaction', function() {
var operation = transaction.operations[0];

expect(transaction.source).to.be.equal(source.accountId());
expect(transaction.fee).to.be.equal(100);
expect(transaction.fee).to.be.equal('100');
expect(transaction.memo.type).to.be.equal(StellarBase.MemoText);
expect(transaction.memo.value.toString('ascii')).to.be.equal(
'Happy birthday!'
Expand Down Expand Up @@ -440,7 +440,7 @@ describe('Transaction', function() {
);
var operation = transaction.operations[0];

expect(transaction.fee).to.be.equal(0);
expect(transaction.fee).to.be.equal('0');

done();
});
Expand Down
4 changes: 2 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ export class Transaction<
};
}

export const BASE_FEE = 100;
export const BASE_FEE = "100";
export const TimeoutInfinite = 0;

export class TransactionBuilder {
Expand All @@ -553,7 +553,7 @@ export class TransactionBuilder {

export namespace TransactionBuilder {
interface TransactionBuilderOptions {
fee: number;
fee: string;
timebounds?: {
minTime?: number | string;
maxTime?: number | string;
Expand Down