Skip to content

Commit f797ce7

Browse files
committed
reverted payment channel create amount type
1 parent 27df013 commit f797ce7

File tree

2 files changed

+2
-182
lines changed

2 files changed

+2
-182
lines changed

xrpl/transaction/payment_channel_create.go

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package transaction
22

33
import (
4-
"encoding/json"
5-
64
addresscodec "github.com/Peersyst/xrpl-go/address-codec"
75
"github.com/Peersyst/xrpl-go/pkg/typecheck"
86
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
@@ -31,7 +29,7 @@ type PaymentChannelCreate struct {
3129
BaseTx
3230
// Amount of XRP, in drops, to deduct from the sender's balance and set aside in this channel.
3331
// While the channel is open, the XRP can only go to the Destination address. When the channel closes, any unclaimed XRP is returned to the source address's balance.
34-
Amount types.CurrencyAmount
32+
Amount types.XRPCurrencyAmount
3533
// Address to receive XRP claims against this channel. This is also known as the "destination address" for the channel. Cannot be the same as the sender (Account).
3634
Destination types.Address
3735
// Amount of time the source address must wait before closing the channel if it has unclaimed XRP.
@@ -56,7 +54,7 @@ func (*PaymentChannelCreate) TxType() TxType {
5654
func (p *PaymentChannelCreate) Flatten() FlatTransaction {
5755
flattened := p.BaseTx.Flatten()
5856

59-
flattened["Amount"] = p.Amount.Flatten()
57+
flattened["Amount"] = p.Amount.String()
6058
flattened["Destination"] = p.Destination.String()
6159
flattened["SettleDelay"] = p.SettleDelay
6260
flattened["PublicKey"] = p.PublicKey
@@ -72,37 +70,6 @@ func (p *PaymentChannelCreate) Flatten() FlatTransaction {
7270
return flattened
7371
}
7472

75-
// UnmarshalJSON unmarshals the PaymentChannelCreate transaction from JSON.
76-
func (p *PaymentChannelCreate) UnmarshalJSON(data []byte) error {
77-
type paymentChannelCreateHelper struct {
78-
BaseTx
79-
Amount json.RawMessage
80-
Destination types.Address
81-
SettleDelay uint32
82-
PublicKey string
83-
CancelAfter uint32 `json:",omitempty"`
84-
DestinationTag *uint32 `json:",omitempty"`
85-
}
86-
var h paymentChannelCreateHelper
87-
if err := json.Unmarshal(data, &h); err != nil {
88-
return err
89-
}
90-
*p = PaymentChannelCreate{
91-
BaseTx: h.BaseTx,
92-
Destination: h.Destination,
93-
SettleDelay: h.SettleDelay,
94-
PublicKey: h.PublicKey,
95-
CancelAfter: h.CancelAfter,
96-
DestinationTag: h.DestinationTag,
97-
}
98-
amount, err := types.UnmarshalCurrencyAmount(h.Amount)
99-
if err != nil {
100-
return err
101-
}
102-
p.Amount = amount
103-
return nil
104-
}
105-
10673
// Validate validates the PaymentChannelCreate fields.
10774
func (p *PaymentChannelCreate) Validate() (bool, error) {
10875
ok, err := p.BaseTx.Validate()

xrpl/transaction/payment_channel_create_test.go

Lines changed: 0 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -93,62 +93,6 @@ func TestPaymentChannelCreate_Flatten(t *testing.T) {
9393
"PublicKey": "32D2471DB72B27E3310F355BB33E339BF26F8392D5A93D3BC0FC3B566612DA0F0A"
9494
}`,
9595
},
96-
{
97-
name: "pass - Optional fields omitted and Amount as IssuedCurrencyAmount",
98-
tx: &PaymentChannelCreate{
99-
BaseTx: BaseTx{
100-
Account: "r2UeJh4HhYc5VtYc8U2YpZfQzY5Lw8kZV",
101-
TransactionType: PaymentChannelCreateTx,
102-
},
103-
Amount: types.IssuedCurrencyAmount{
104-
Currency: "USD",
105-
Value: "10000",
106-
Issuer: "rEXAMPLE123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
107-
},
108-
Destination: types.Address("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn"),
109-
SettleDelay: 86400,
110-
PublicKey: "32D2471DB72B27E3310F355BB33E339BF26F8392D5A93D3BC0FC3B566612DA0F0A",
111-
},
112-
expected: `{
113-
"Account": "r2UeJh4HhYc5VtYc8U2YpZfQzY5Lw8kZV",
114-
"TransactionType": "PaymentChannelCreate",
115-
"Amount": {
116-
"issuer": "rEXAMPLE123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
117-
"currency": "USD",
118-
"value": "10000"
119-
},
120-
"Destination": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
121-
"SettleDelay": 86400,
122-
"PublicKey": "32D2471DB72B27E3310F355BB33E339BF26F8392D5A93D3BC0FC3B566612DA0F0A"
123-
}`,
124-
},
125-
{
126-
name: "pass - Optional fields omitted and Amount as MPTCurrencyAmount",
127-
tx: &PaymentChannelCreate{
128-
BaseTx: BaseTx{
129-
Account: "r2UeJh4HhYc5VtYc8U2YpZfQzY5Lw8kZV",
130-
TransactionType: PaymentChannelCreateTx,
131-
},
132-
Amount: types.MPTCurrencyAmount{
133-
MPTIssuanceID: "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF",
134-
Value: "10000",
135-
},
136-
Destination: types.Address("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn"),
137-
SettleDelay: 86400,
138-
PublicKey: "32D2471DB72B27E3310F355BB33E339BF26F8392D5A93D3BC0FC3B566612DA0F0A",
139-
},
140-
expected: `{
141-
"Account": "r2UeJh4HhYc5VtYc8U2YpZfQzY5Lw8kZV",
142-
"TransactionType": "PaymentChannelCreate",
143-
"Amount": {
144-
"mpt_issuance_id": "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF",
145-
"value": "10000"
146-
},
147-
"Destination": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
148-
"SettleDelay": 86400,
149-
"PublicKey": "32D2471DB72B27E3310F355BB33E339BF26F8392D5A93D3BC0FC3B566612DA0F0A"
150-
}`,
151-
},
15296
}
15397

15498
for _, tt := range tests {
@@ -315,97 +259,6 @@ func TestPaymentChannelCreate_Unmarshal(t *testing.T) {
315259
expectedTag: func() *uint32 { v := uint32(12345); return &v }(),
316260
expectUnmarshalError: false,
317261
},
318-
{
319-
name: "pass - full PaymentChannelCreate with IssuedCurrencyAmount",
320-
jsonData: `{
321-
"TransactionType": "PaymentChannelCreate",
322-
"Account": "rEXAMPLE123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
323-
"Destination": "rDEST123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
324-
"Amount": {
325-
"issuer": "rEXAMPLE123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
326-
"currency": "USD",
327-
"value": "1000000"
328-
},
329-
"Fee": "10",
330-
"Sequence": 1,
331-
"Flags": 2147483648,
332-
"CancelAfter": 695123456,
333-
"FinishAfter": 695000000,
334-
"Condition": "A0258020C4F71E9B01F5A78023E932ABF6B2C1F020986E6C9E55678FFBAE67A2F5B474680103080000000000000000000000000000000000000000000000000000000000000000",
335-
"DestinationTag": 12345,
336-
"SourceTag": 54321,
337-
"OwnerNode": "0000000000000000",
338-
"PreviousTxnID": "C4F71E9B01F5A78023E932ABF6B2C1F020986E6C9E55678FFBAE67A2F5B47468",
339-
"LastLedgerSequence": 12345678,
340-
"NetworkID": 1024,
341-
"Memos": [
342-
{
343-
"Memo": {
344-
"MemoType": "657363726F77",
345-
"MemoData": "457363726F77206372656174656420666F72207061796D656E74"
346-
}
347-
}
348-
],
349-
"Signers": [
350-
{
351-
"Signer": {
352-
"Account": "rSIGNER123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
353-
"SigningPubKey": "ED5F93AB1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF12345678",
354-
"TxnSignature": "3045022100D7F67A81F343...B87D"
355-
}
356-
}
357-
],
358-
"SigningPubKey": "ED5F93AB1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF12345678",
359-
"TxnSignature": "3045022100D7F67A81F343...B87D"
360-
}`,
361-
expectedTag: func() *uint32 { v := uint32(12345); return &v }(),
362-
expectUnmarshalError: false,
363-
},
364-
{
365-
name: "pass - full PaymentChannelCreate with MPTCurrencyAmount",
366-
jsonData: `{
367-
"TransactionType": "PaymentChannelCreate",
368-
"Account": "rEXAMPLE123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
369-
"Destination": "rDEST123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
370-
"Amount": {
371-
"mpt_issuance_id": "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF",
372-
"value": "1000000"
373-
},
374-
"Fee": "10",
375-
"Sequence": 1,
376-
"Flags": 2147483648,
377-
"CancelAfter": 695123456,
378-
"FinishAfter": 695000000,
379-
"Condition": "A0258020C4F71E9B01F5A78023E932ABF6B2C1F020986E6C9E55678FFBAE67A2F5B474680103080000000000000000000000000000000000000000000000000000000000000000",
380-
"DestinationTag": 12345,
381-
"SourceTag": 54321,
382-
"OwnerNode": "0000000000000000",
383-
"PreviousTxnID": "C4F71E9B01F5A78023E932ABF6B2C1F020986E6C9E55678FFBAE67A2F5B47468",
384-
"LastLedgerSequence": 12345678,
385-
"NetworkID": 1024,
386-
"Memos": [
387-
{
388-
"Memo": {
389-
"MemoType": "657363726F77",
390-
"MemoData": "457363726F77206372656174656420666F72207061796D656E74"
391-
}
392-
}
393-
],
394-
"Signers": [
395-
{
396-
"Signer": {
397-
"Account": "rSIGNER123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
398-
"SigningPubKey": "ED5F93AB1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF12345678",
399-
"TxnSignature": "3045022100D7F67A81F343...B87D"
400-
}
401-
}
402-
],
403-
"SigningPubKey": "ED5F93AB1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF12345678",
404-
"TxnSignature": "3045022100D7F67A81F343...B87D"
405-
}`,
406-
expectedTag: func() *uint32 { v := uint32(12345); return &v }(),
407-
expectUnmarshalError: false,
408-
},
409262
{
410263
name: "pass - partial PaymentChannelCreate with DestinationTag set to 0",
411264
jsonData: `{

0 commit comments

Comments
 (0)