Skip to content

Commit 5e9c2fe

Browse files
weilbithberndbohmeier
authored andcommitted
Rename message to transfer ID
The message ID is actually identifying a transfer. This gets especially clear when considering that it gets generated by the prepare payment function. Thereby also the extra data field has been renamed from `mgId` to `trId`. Related to: #375
1 parent e768443 commit 5e9c2fe

File tree

9 files changed

+77
-77
lines changed

9 files changed

+77
-77
lines changed

CHANGELOG.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
1717
where the fee payer is the loaded user
1818
- Add `extraData` to `TransferDetails`, it contains the raw `extraData` that was present in the transfer
1919
for which details are returned
20-
- Add `paymentRequestId` and `messageId` to `TransferDetails` corresponding to the decoded `extraData`
21-
- Add option to `Payment.preparePayment` function `options.addMessageId: boolean = true` that signals whether
22-
a messageId should be generated and added to the payment's extraData.
23-
- Add `messageId` to the returned values of `Payment.preparePayment`
20+
- Add `paymentRequestId` and `transferId` to `TransferDetails` corresponding to the decoded `extraData`
21+
- Add option to `Payment.preparePayment` function `options.addTransferId: boolean = true` that signals whether
22+
a `transferId` should be generated and added to the payment's extraData.
23+
- Add `transferId` to the returned values of `Payment.preparePayment`
2424
- Add function `Payment.confirmPayment` to confirm any `PaymentTxObject` returned by `prepare`
2525
and potentially send a payment message along with the payment
26-
- Add function `Messaging.paymentMessage` to send a payment message for a messageId to a counterparty address
26+
- Add function `Messaging.paymentMessage` to send a payment message for a `transferId` to a counterparty address
2727

2828
### Deprecated
2929

src/Messaging.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ export class Messaging {
110110
/**
111111
* Sends a payment message to given `counterParty` and returns created message.
112112
* @param counterPartyAddress Address of counter party.
113-
* @param messageId Message id of the payment
113+
* @param transferId Transfer ID of the payment
114114
* @param subject Subject that will be sent to the counterparty
115115
*/
116116
public async paymentMessage(
117117
counterPartyAddress: string,
118-
messageId: string,
118+
transferId: string,
119119
subject: string
120120
): Promise<PaymentMessage> {
121121
const type = 'PaymentMessage'
122122
const message = {
123123
type,
124-
messageId,
124+
transferId,
125125
subject
126126
}
127127
await this.sendMessage(counterPartyAddress, type, message)

src/Payment.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,34 +101,34 @@ export class Payment {
101101
* @param options.feePayer Either `sender` or `receiver`. Specifies who pays network fees.
102102
* @param options.extraData Extra data that will appear in the Transfer event when successful.
103103
* @param options.paymentRequestId Payment request identifier that gets encoded to the extra data.
104-
* @param options.addMessageId Whether a message id should be added to the payment, default to true.
104+
* @param options.addTransferId Whether a transfer id should be added to the payment, default to true.
105105
*/
106106
public async prepare(
107107
networkAddress: string,
108108
receiverAddress: string,
109109
value: number | string,
110-
options: PaymentOptions = { addMessageId: true }
110+
options: PaymentOptions = { addTransferId: true }
111111
): Promise<PaymentTxObject> {
112112
const {
113113
gasPrice,
114114
gasLimit,
115115
networkDecimals,
116116
extraData,
117117
paymentRequestId,
118-
addMessageId
118+
addTransferId
119119
} = options
120120
const decimals = await this.currencyNetwork.getDecimals(networkAddress, {
121121
networkDecimals
122122
})
123-
let messageId: string
124-
if (addMessageId) {
123+
let transferId: string
124+
if (addTransferId) {
125125
// 19 decimals fit in 64 bits
126-
messageId = utils.convertToHexString(utils.generateRandomNumber(19))
126+
transferId = utils.convertToHexString(utils.generateRandomNumber(19))
127127
}
128128
const encodedExtraData: string = encode({
129129
extraData,
130130
paymentRequestId,
131-
messageId
131+
transferId
132132
})
133133

134134
const { path, maxFees, feePayer } = await this.getTransferPathInfo(
@@ -174,7 +174,7 @@ export class Payment {
174174
path,
175175
receiverAddress,
176176
rawTx,
177-
messageId: messageId || null
177+
transferId: transferId || null
178178
}
179179
} else {
180180
throw new Error('Could not find a path with enough capacity.')
@@ -293,28 +293,28 @@ export class Payment {
293293

294294
/**
295295
* Signs the rawTx provided as returned by `prepare`
296-
* and sends the signed transaction as well as the message with messageId
296+
* and sends the signed transaction as well as the message with transferId
297297
* Can be directly given a `PaymentTxObject` object as returned by `prepare`
298298
* @param rawTx Raw transaction object.
299299
* @param receiverAddress Address of the receiver of the message for the payment.
300-
* @param messageId The messageId returned when preparing a payment with message.
300+
* @param transferId The transfer id returned when preparing a payment with message.
301301
* @param message The message to be sent.
302302
*/
303303
public async confirmPayment(
304304
{
305305
rawTx,
306306
receiverAddress,
307-
messageId
308-
}: { rawTx: RawTxObject; receiverAddress: string; messageId?: string },
307+
transferId
308+
}: { rawTx: RawTxObject; receiverAddress: string; transferId?: string },
309309
message?: string
310310
) {
311311
if (message) {
312-
if (!messageId) {
312+
if (!transferId) {
313313
throw new Error(
314-
'Cannot use `message` if payment was prepared without `messageId`.'
314+
'Cannot use `message` if payment was prepared without `transferId`.'
315315
)
316316
}
317-
await this.messaging.paymentMessage(receiverAddress, messageId, message)
317+
await this.messaging.paymentMessage(receiverAddress, transferId, message)
318318
}
319319
return this.transaction.confirm(rawTx)
320320
}
@@ -513,21 +513,21 @@ export class Payment {
513513
function encode({
514514
extraData,
515515
paymentRequestId,
516-
messageId
516+
transferId
517517
}: {
518518
extraData: string
519519
paymentRequestId: string
520-
messageId?: string
520+
transferId?: string
521521
}) {
522-
if (extraData && (paymentRequestId || messageId)) {
522+
if (extraData && (paymentRequestId || transferId)) {
523523
throw Error(
524-
'Can not encode extraData and paymentRequestId or messageId at the same time currently'
524+
'Can not encode extraData and paymentRequestId or transferId at the same time currently'
525525
)
526526
}
527527
if (extraData) {
528528
return extraData
529-
} else if (paymentRequestId || messageId) {
530-
return encodeExtraData({ paymentRequestId, messageId })
529+
} else if (paymentRequestId || transferId) {
530+
return encodeExtraData({ paymentRequestId, transferId })
531531
} else {
532532
return '0x'
533533
}

src/extraData.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ export const MSG_PACK_ID = '0x544c4d50' // hex encoded "TLMP" (Trustlines Messag
44

55
export interface ExtraData {
66
paymentRequestId?: string
7-
messageId?: string
7+
transferId?: string
88
}
99

1010
interface ExtraDataEncoding {
1111
prId?: ArrayBufferView
12-
mgId?: ArrayBufferView
12+
trId?: ArrayBufferView
1313
}
1414

1515
export function encode(extraData: ExtraData): string {
16-
const { paymentRequestId, messageId } = extraData
17-
if (!paymentRequestId && !messageId) {
16+
const { paymentRequestId, transferId } = extraData
17+
if (!paymentRequestId && !transferId) {
1818
return '0x'
1919
} else {
2020
const data: ExtraDataEncoding = {}
2121
if (paymentRequestId) {
2222
data.prId = hexToArray(paymentRequestId)
2323
}
24-
if (messageId) {
25-
data.mgId = hexToArray(messageId)
24+
if (transferId) {
25+
data.trId = hexToArray(transferId)
2626
}
2727
const enc = msgPack.encode(data)
2828
return MSG_PACK_ID + remove0xPrefix(arrayToHex(enc))
@@ -52,7 +52,7 @@ export function decode(encodedExtraData: string): ExtraData {
5252

5353
return {
5454
paymentRequestId: arrayToHex(extraData.prId),
55-
messageId: arrayToHex(extraData.mgId)
55+
transferId: arrayToHex(extraData.trId)
5656
}
5757
}
5858

@@ -85,8 +85,8 @@ export function processExtraData(object) {
8585
object.paymentRequestId = decodedExtraData
8686
? decodedExtraData.paymentRequestId || null
8787
: null
88-
object.messageId = decodedExtraData
89-
? decodedExtraData.messageId || null
88+
object.transferId = decodedExtraData
89+
? decodedExtraData.transferId || null
9090
: null
9191
}
9292
return object

src/typings.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export interface PaymentOptions extends TLOptions {
7979
feePayer?: FeePayer
8080
extraData?: string
8181
paymentRequestId?: string
82-
addMessageId?: boolean
82+
addTransferId?: boolean
8383
}
8484

8585
export interface TrustlineUpdateOptions extends TLOptions {
@@ -137,7 +137,7 @@ export interface NetworkTransferEvent extends NetworkEvent {
137137
amount: Amount
138138
extraData: string
139139
paymentRequestId: string
140-
messageId: string
140+
transferId: string
141141
}
142142

143143
export interface NetworkTrustlineUpdateEventRaw extends NetworkEvent {
@@ -226,7 +226,7 @@ export interface PaymentRequestDeclineMessage {
226226

227227
export interface PaymentMessage {
228228
type: string
229-
messageId: string
229+
transferId: string
230230
subject: string
231231
}
232232

@@ -436,7 +436,7 @@ export interface PaymentTxObject extends TxObject {
436436
receiverAddress: string
437437
feePayer: FeePayer
438438
maxFees: Amount
439-
messageId?: string
439+
transferId?: string
440440
}
441441

442442
export enum FeePayer {
@@ -697,7 +697,7 @@ export interface TransferDetails {
697697
feesPaid: Amount[]
698698
extraData: string
699699
paymentRequestId: string
700-
messageId: string
700+
transferId: string
701701
}
702702

703703
export interface TransferIdentifier {

tests/e2e/Event.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('e2e', () => {
7373
1.5,
7474
{
7575
extraData,
76-
addMessageId: false
76+
addTransferId: false
7777
}
7878
)
7979
await tl1.payment.confirm(rawTx)
@@ -98,7 +98,7 @@ describe('e2e', () => {
9898
expect(last.amount).to.have.keys('raw', 'value', 'decimals')
9999
expect(last.amount.value).to.eq('1.5')
100100
expect(last.extraData).to.eq(extraData)
101-
expect(last.messageId).to.be.a('null')
101+
expect(last.transferId).to.be.a('null')
102102
expect(last.paymentRequestId).to.be.a('null')
103103
expect(last.logIndex).to.be.a('number')
104104
expect(last.blockHash).to.be.a('string')
@@ -110,7 +110,7 @@ describe('e2e', () => {
110110
let acceptTxHash
111111
let cancelUpdateTxHash
112112
let tlTransferTxHash
113-
let tlTransferMessageId
113+
let tlTransferTransferId
114114
let depositTxHash
115115
let withdrawTxHash
116116
let transferTxHash
@@ -164,7 +164,7 @@ describe('e2e', () => {
164164
1,
165165
{ paymentRequestId }
166166
)
167-
tlTransferMessageId = tlTransferTx.messageId
167+
tlTransferTransferId = tlTransferTx.transferId
168168
tlTransferTxHash = await tl1.payment.confirm(tlTransferTx.rawTx)
169169
await wait()
170170

@@ -338,8 +338,8 @@ describe('e2e', () => {
338338
(tlTransferEvents[0] as NetworkTransferEvent).paymentRequestId
339339
).to.equal(paymentRequestId)
340340
expect(
341-
(tlTransferEvents[0] as NetworkTransferEvent).messageId
342-
).to.equal(tlTransferMessageId)
341+
(tlTransferEvents[0] as NetworkTransferEvent).transferId
342+
).to.equal(tlTransferTransferId)
343343

344344
// events thrown on deposit
345345
const depositEvents = allEvents.filter(
@@ -564,7 +564,7 @@ describe('e2e', () => {
564564
'paymentRequestId',
565565
paymentRequestId
566566
)
567-
expect(transferEvent).to.have.property('messageId')
567+
expect(transferEvent).to.have.property('transferId')
568568
expect(transferEvent.blockHash).to.be.a('string')
569569
expect(transferEvent.logIndex).be.a('number')
570570

tests/e2e/Messaging.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('e2e', () => {
9999
'test message'
100100
)
101101
expect(sentPaymentMessage.type).to.equal('PaymentMessage')
102-
expect(sentPaymentMessage.messageId).to.equal('0x10')
102+
expect(sentPaymentMessage.transferId).to.equal('0x10')
103103
expect(sentPaymentMessage.subject).to.equal('test message')
104104
})
105105
})
@@ -177,7 +177,7 @@ describe('e2e', () => {
177177
it('should receive payment message', async () => {
178178
expect(messages[4]).to.have.property('type', 'PaymentMessage')
179179
expect(messages[4].timestamp).to.be.a('number')
180-
expect(messages[4].messageId).to.be.a('string')
180+
expect(messages[4].transferId).to.be.a('string')
181181
expect(messages[4]).to.have.property('subject', 'payment message')
182182
})
183183

0 commit comments

Comments
 (0)