Skip to content

Commit

Permalink
fix: kaspa his (#4509)
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteZhang1024 authored Apr 26, 2024
1 parent 565240a commit 1275f15
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
88 changes: 88 additions & 0 deletions packages/engine/src/vaults/impl/kaspa/sdk/transactionUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,94 @@ const cases = [
fee: new BigNumber('0.00003154'),
},
},
{
testId: 'test-other-to-multi-self-and-other',
data: {
mass: '3154',
mineAddress:
'kaspa:qz3xsrquk2t7prvkam54mgh3ru6uxs0scgdq98lql0hf2xh08zp8shclpaz4e',
inputs: [
generateInput(
'kaspa:qpa0mtj40e5uqpq06sf44hluvru5smajraxt4c3nl4km86zt537929zjp27tu',
10000n,
),
generateInput(
'kaspa:qpa0mtj40e5uqpq06sf44hluvru5smajraxt4c3nl4km86zt537929zjp27tu',
10000n,
),
],
outputs: [
generateOutput(
'kaspa:qz3xsrquk2t7prvkam54mgh3ru6uxs0scgdq98lql0hf2xh08zp8shclpaz4e',
5000n,
),
generateOutput(
'kaspa:qpw28f6nq2zwt30ywf2yahtqqtp6l6uv37zd8fegltf9tfy8yaflk4fvlp8mp',
5000n,
),
generateOutput(
'kaspa:qpw28f6nq2zwt30ywf2yahtqqtp6l6uv37zd8fegltf9tfy8yaflk4fvlp8mp',
6846n,
),
],
},
result: {
fromAddress:
'kaspa:qpa0mtj40e5uqpq06sf44hluvru5smajraxt4c3nl4km86zt537929zjp27tu',
toAddress: [
{
address:
'kaspa:qz3xsrquk2t7prvkam54mgh3ru6uxs0scgdq98lql0hf2xh08zp8shclpaz4e',
amount: 5000n,
},
],
fee: new BigNumber('0.00003154'),
},
},
{
testId: 'test-other-to-multi-self-and-other-with-change',
data: {
mass: '3154',
mineAddress:
'kaspa:qz3xsrquk2t7prvkam54mgh3ru6uxs0scgdq98lql0hf2xh08zp8shclpaz4e',
inputs: [
generateInput(
'kaspa:qpa0mtj40e5uqpq06sf44hluvru5smajraxt4c3nl4km86zt537929zjp27tu',
10000n,
),
generateInput(
'kaspa:qpa0mtj40e5uqpq06sf44hluvru5smajraxt4c3nl4km86zt537929zjp27tu',
10000n,
),
],
outputs: [
generateOutput(
'kaspa:qpa0mtj40e5uqpq06sf44hluvru5smajraxt4c3nl4km86zt537929zjp27tu',
6846n,
),
generateOutput(
'kaspa:qz3xsrquk2t7prvkam54mgh3ru6uxs0scgdq98lql0hf2xh08zp8shclpaz4e',
5000n,
),
generateOutput(
'kaspa:qpw28f6nq2zwt30ywf2yahtqqtp6l6uv37zd8fegltf9tfy8yaflk4fvlp8mp',
5000n,
),
],
},
result: {
fromAddress:
'kaspa:qpa0mtj40e5uqpq06sf44hluvru5smajraxt4c3nl4km86zt537929zjp27tu',
toAddress: [
{
address:
'kaspa:qz3xsrquk2t7prvkam54mgh3ru6uxs0scgdq98lql0hf2xh08zp8shclpaz4e',
amount: 5000n,
},
],
fee: new BigNumber('0.00003154'),
},
},
];

describe('test kaspa tx decode', () => {
Expand Down
7 changes: 5 additions & 2 deletions packages/engine/src/vaults/impl/kaspa/sdk/transactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ function determineToAddresses(
);

outputs?.forEach((output) => {
// 如果输出地址不在输入地址中,它就不是找零,应该被包括
if (!inputAddresses.has(output.script_public_key_address)) {
if (hasSenderIncludeMine) {
if (!inputAddresses.has(output.script_public_key_address)) {
toAddresses.add(output.script_public_key_address);
}
} else if (output.script_public_key_address === mineAddress) {
toAddresses.add(output.script_public_key_address);
}
});
Expand Down

0 comments on commit 1275f15

Please sign in to comment.