Skip to content

Commit ad6cff5

Browse files
authored
Merge pull request #792 from PayButton/refactor/rename-nonce-paymentId
refactor: rename nonce -> paymentId
2 parents 9742fb2 + 110603f commit ad6cff5

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

services/chronikService.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,25 @@ export function getNullDataScriptData (outputScript: string): OpReturnData | nul
7474
paymentId: ''
7575
}
7676

77-
const noncePushDataIndex = dataStartIndex + dataPushData * 2
78-
const nonceStartIndex = noncePushDataIndex + 2
79-
const hasNonce = outputScript.length >= nonceStartIndex
80-
if (!hasNonce) {
77+
const paymentIdPushDataIndex = dataStartIndex + dataPushData * 2
78+
const paymentIdStartIndex = paymentIdPushDataIndex + 2
79+
const hasPaymentId = outputScript.length >= paymentIdStartIndex
80+
if (!hasPaymentId) {
8181
return ret
8282
}
8383

84-
const noncePushDataHex = outputScript.slice(noncePushDataIndex, nonceStartIndex)
85-
const noncePushData = parseInt(noncePushDataHex, 16)
86-
let nonceString = ''
87-
if (outputScript.length < nonceStartIndex + noncePushData * 2) {
84+
const paymentIdPushDataHex = outputScript.slice(paymentIdPushDataIndex, paymentIdStartIndex)
85+
const paymentIdPushData = parseInt(paymentIdPushDataHex, 16)
86+
let paymentIdString = ''
87+
if (outputScript.length < paymentIdStartIndex + paymentIdPushData * 2) {
8888
return ret
8989
}
90-
for (let i = 0; i < noncePushData; i++) {
91-
const hexByte = outputScript.slice(nonceStartIndex + (i * 2), nonceStartIndex + (i * 2) + 2)
92-
// we don't decode the hex for the nonce, since those are just random bytes.
93-
nonceString += hexByte
90+
for (let i = 0; i < paymentIdPushData; i++) {
91+
const hexByte = outputScript.slice(paymentIdStartIndex + (i * 2), paymentIdStartIndex + (i * 2) + 2)
92+
// we don't decode the hex for the paymentId, since those are just random bytes.
93+
paymentIdString += hexByte
9494
}
95-
ret.paymentId = nonceString
95+
ret.paymentId = paymentIdString
9696

9797
return ret
9898
}

tests/unittests/chronikService.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('getNullDataScriptData tests', () => {
3232
const data = getNullDataScriptData(script)
3333
expect(data).toStrictEqual(EMPTY_OP_RETURN)
3434
})
35-
it('Empty if data explicitly empty and nonce too', async () => {
35+
it('Empty if data explicitly empty and paymentId too', async () => {
3636
const script = '6a' + '04' + '50415900' + '00' + '00' + '00'
3737
const data = getNullDataScriptData(script)
3838
expect(data).toStrictEqual(EMPTY_OP_RETURN)
@@ -102,23 +102,23 @@ describe('getNullDataScriptData tests', () => {
102102
data: '😂👍©ĸðМжЪы% ŋæPßđĸł„»“æ}¹↓£³→²'
103103
})
104104
})
105-
it('String data with nonce', async () => {
105+
it('String data with paymentId', async () => {
106106
const script = '6a' + '04' + '50415900' + '00' + '08' + '5051525354555657' + '03' + '010203'
107107
const data = getNullDataScriptData(script)
108108
expect(data).toStrictEqual({
109109
paymentId: '010203',
110110
data: 'PQRSTUVW'
111111
})
112112
})
113-
it('String data with explicitly empty nonce', async () => {
113+
it('String data with explicitly empty paymentId', async () => {
114114
const script = '6a' + '04' + '50415900' + '00' + '08' + '5051525354555657' + '00'
115115
const data = getNullDataScriptData(script)
116116
expect(data).toStrictEqual({
117117
paymentId: '',
118118
data: 'PQRSTUVW'
119119
})
120120
})
121-
it('Ignore incomplete nonce', async () => {
121+
it('Ignore incomplete paymentId', async () => {
122122
const script = '6a' + '04' + '50415900' + '00' + '08' + '5051525354555657' + '03' + 'aabb'
123123
const data = getNullDataScriptData(script)
124124
expect(data).toStrictEqual({

0 commit comments

Comments
 (0)