Skip to content

Commit

Permalink
fix: remove post-conditions from stx transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Jun 23, 2023
1 parent 17b2029 commit 679a93a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
18 changes: 2 additions & 16 deletions packages/transactions/src/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,6 @@ export interface TokenTransferOptions {
anchorMode: AnchorModeName | AnchorMode;
/** an arbitrary string to include in the transaction, must be less than 34 bytes */
memo?: string;
/** the post condition mode, specifying whether or not post-conditions must fully cover all
* transfered assets */
postConditionMode?: PostConditionMode;
/** a list of post conditions to add to the transaction */
postConditions?: PostCondition[];
/** set to true if another account is sponsoring the transaction (covering the transaction fee) */
sponsored?: boolean;
}
Expand Down Expand Up @@ -576,7 +571,6 @@ export async function makeUnsignedSTXTokenTransfer(
fee: BigInt(0),
nonce: BigInt(0),
network: new StacksMainnet(),
postConditionMode: PostConditionMode.Deny,
memo: '',
sponsored: false,
};
Expand Down Expand Up @@ -615,20 +609,12 @@ export async function makeUnsignedSTXTokenTransfer(

const network = StacksNetwork.fromNameOrNetwork(options.network);

const postConditions: PostCondition[] = [];
if (options.postConditions && options.postConditions.length > 0) {
options.postConditions.forEach(postCondition => {
postConditions.push(postCondition);
});
}
const lpPostConditions = createLPList(postConditions);

const transaction = new StacksTransaction(
network.version,
authorization,
payload,
lpPostConditions,
options.postConditionMode,
undefined, // no post conditions on STX transfers (see SIP-005)
undefined, // no post conditions on STX transfers (see SIP-005)
options.anchorMode,
network.chainId
);
Expand Down
17 changes: 7 additions & 10 deletions packages/transactions/tests/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ test('Throws making STX token transder with invalid network name', async () => {
).rejects.toThrow(Error);
});

test('Make STX token transfer with post conditions', async () => {
test("STX token transfers don't take post conditions", async () => {
const recipientAddress = 'SP3FGQ8Z7JY9BWYZ5WM53E0M9NK7WHJF0691NZ159';
const amount = 12345;
const fee = 0;
Expand All @@ -350,18 +350,15 @@ test('Make STX token transfer with post conditions', async () => {
memo,
postConditions,
anchorMode: AnchorMode.Any,
});
} as SignedTokenTransferOptions);

const serialized = bytesToHex(transaction.serialize());
const serialized = transaction.serialize();

const tx =
'0000000001040015c31b8c1c11c515e244b75806bac48d1399c77500000000000000000000000000000000' +
'0001601ceb46ef6988c8b226c80fef4051de6acf344dc67a9421d3e734a72ae310104b061e69cee5d9ee7a' +
'6e1cef17f23b07d7fe4db5fcdb83de0d5f08043a06a36a030200000001000216df0ba3e79792be7be5e50a' +
'370289accfc8c9e03203000000000000d431000516df0ba3e79792be7be5e50a370289accfc8c9e0320000' +
'00000000303974657374206d656d6f00000000000000000000000000000000000000000000000000';
const bytesReader = new BytesReader(serialized);
const deserializedTx = deserializeTransaction(bytesReader);

expect(serialized).toBe(tx);
expect(deserializedTx.postConditions.values).toHaveLength(0);
expect(deserializedTx.postConditionMode).toBe(PostConditionMode.Deny);
});

test('Make Multi-Sig STX token transfer', async () => {
Expand Down

1 comment on commit 679a93a

@vercel
Copy link

@vercel vercel bot commented on 679a93a Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.