Skip to content

Commit 35c1f96

Browse files
committed
channel claim reverted
1 parent f797ce7 commit 35c1f96

File tree

2 files changed

+5
-271
lines changed

2 files changed

+5
-271
lines changed

xrpl/transaction/payment_channel_claim.go

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

33
import (
4-
"encoding/json"
5-
64
"github.com/Peersyst/xrpl-go/pkg/typecheck"
75
"github.com/Peersyst/xrpl-go/xrpl/transaction/types"
86
)
@@ -68,10 +66,10 @@ type PaymentChannelClaim struct {
6866
CredentialIDs types.CredentialIDs `json:",omitempty"`
6967
// (Optional) Total amount of XRP, in drops, delivered by this channel after processing this claim. Required to deliver XRP.
7068
// Must be more than the total amount delivered by the channel so far, but not greater than the Amount of the signed claim. Must be provided except when closing the channel.
71-
Balance types.CurrencyAmount `json:",omitempty"`
69+
Balance types.XRPCurrencyAmount `json:",omitempty"`
7270
// The amount of XRP, in drops, or fungible tokens authorized by the Signature. This must match the amount in the signed message.
7371
// This is the cumulative amount that can be dispensed by the channel, including funds previously redeemed. Non-XRP tokens can only be used if the TokenEscrow amendment is enabled.
74-
Amount types.CurrencyAmount `json:",omitempty"`
72+
Amount types.XRPCurrencyAmount `json:",omitempty"`
7573
// (Optional) The signature of this claim, as hexadecimal. The signed message contains the channel ID and the amount of the claim.
7674
// Required unless the sender of the transaction is the source address of the channel.
7775
Signature string `json:",omitempty"`
@@ -95,10 +93,10 @@ func (p *PaymentChannelClaim) Flatten() FlatTransaction {
9593
if p.Channel != "" {
9694
flattened["Channel"] = p.Channel.String()
9795
}
98-
if p.Balance != nil {
96+
if p.Balance != 0 {
9997
flattened["Balance"] = p.Balance.Flatten()
10098
}
101-
if p.Amount != nil {
99+
if p.Amount != 0 {
102100
flattened["Amount"] = p.Amount.Flatten()
103101
}
104102
if p.Signature != "" {
@@ -164,38 +162,3 @@ func (p *PaymentChannelClaim) Validate() (bool, error) {
164162

165163
return true, nil
166164
}
167-
168-
// UnmarshalJSON unmarshals the PaymentChannelClaim transaction from JSON.
169-
func (p *PaymentChannelClaim) UnmarshalJSON(data []byte) error {
170-
type paymentChannelClaimHelper struct {
171-
BaseTx
172-
Amount json.RawMessage
173-
Balance json.RawMessage
174-
Channel types.Hash256
175-
Signature string
176-
PublicKey string
177-
CredentialIDs types.CredentialIDs `json:",omitempty"`
178-
}
179-
var h paymentChannelClaimHelper
180-
if err := json.Unmarshal(data, &h); err != nil {
181-
return err
182-
}
183-
*p = PaymentChannelClaim{
184-
BaseTx: h.BaseTx,
185-
Channel: h.Channel,
186-
Signature: h.Signature,
187-
PublicKey: h.PublicKey,
188-
CredentialIDs: h.CredentialIDs,
189-
}
190-
amount, err := types.UnmarshalCurrencyAmount(h.Amount)
191-
if err != nil {
192-
return err
193-
}
194-
p.Amount = amount
195-
balance, err := types.UnmarshalCurrencyAmount(h.Balance)
196-
if err != nil {
197-
return err
198-
}
199-
p.Balance = balance
200-
return nil
201-
}

xrpl/transaction/payment_channel_claim_test.go

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

33
import (
4-
"encoding/json"
5-
"fmt"
64
"testing"
75

86
"github.com/Peersyst/xrpl-go/xrpl/testutil"
@@ -76,7 +74,7 @@ func TestPaymentChannelClaim_Flatten(t *testing.T) {
7674
}`,
7775
},
7876
{
79-
name: "pass - PaymentChannelClaim with Balance and Amount as XRPCurrencyAmount",
77+
name: "pass - PaymentChannelClaim with Balance",
8078
claim: PaymentChannelClaim{
8179
BaseTx: BaseTx{
8280
Account: "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
@@ -92,68 +90,6 @@ func TestPaymentChannelClaim_Flatten(t *testing.T) {
9290
"Amount": "2000"
9391
}`,
9492
},
95-
{
96-
name: "pass - PaymentChannelClaim with Balance and Amount as MPTCurrencyAmount",
97-
claim: PaymentChannelClaim{
98-
BaseTx: BaseTx{
99-
Account: "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
100-
TransactionType: PaymentChannelClaimTx,
101-
},
102-
Balance: types.MPTCurrencyAmount{
103-
MPTIssuanceID: "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF",
104-
Value: "1000",
105-
},
106-
Amount: types.MPTCurrencyAmount{
107-
MPTIssuanceID: "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF",
108-
Value: "2000",
109-
},
110-
},
111-
expected: `{
112-
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
113-
"TransactionType": "PaymentChannelClaim",
114-
"Balance": {
115-
"mpt_issuance_id": "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF",
116-
"value": "1000"
117-
},
118-
"Amount": {
119-
"mpt_issuance_id": "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF",
120-
"value": "2000"
121-
}
122-
}`,
123-
},
124-
{
125-
name: "pass - PaymentChannelClaim with Balance and Amount as IssuedCurrencyAmount",
126-
claim: PaymentChannelClaim{
127-
BaseTx: BaseTx{
128-
Account: "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
129-
TransactionType: PaymentChannelClaimTx,
130-
},
131-
Balance: types.IssuedCurrencyAmount{
132-
Issuer: "rEXAMPLE123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
133-
Currency: "USD",
134-
Value: "1000",
135-
},
136-
Amount: types.IssuedCurrencyAmount{
137-
Issuer: "rEXAMPLE123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
138-
Currency: "USD",
139-
Value: "2000",
140-
},
141-
},
142-
expected: `{
143-
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
144-
"TransactionType": "PaymentChannelClaim",
145-
"Balance": {
146-
"issuer": "rEXAMPLE123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
147-
"currency": "USD",
148-
"value": "1000"
149-
},
150-
"Amount": {
151-
"issuer": "rEXAMPLE123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
152-
"currency": "USD",
153-
"value": "2000"
154-
}
155-
}`,
156-
},
15793
{
15894
name: "pass - PaymentChannelClaim with Signature and PublicKey",
15995
claim: PaymentChannelClaim{
@@ -324,168 +260,3 @@ func TestPaymentChannelClaim_Validate(t *testing.T) {
324260
})
325261
}
326262
}
327-
328-
func TestPaymentChannelClaim_Unmarshal(t *testing.T) {
329-
tests := []struct {
330-
name string
331-
jsonData string
332-
expectUnmarshalError bool
333-
}{
334-
{
335-
name: "pass - full PaymentChannelClaim with IssuedCurrencyAmount",
336-
jsonData: `{
337-
"TransactionType": "PaymentChannelClaim",
338-
"Account": "rEXAMPLE123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
339-
"Channel": "ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC1",
340-
"Amount": {
341-
"issuer": "rEXAMPLE123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
342-
"currency": "USD",
343-
"value": "1000000"
344-
},
345-
"Balance": {
346-
"issuer": "rEXAMPLE123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
347-
"currency": "USD",
348-
"value": "900000"
349-
},
350-
"CredentialIDs": ["1234567890abcdef", "1234567890abcdefg"],
351-
"Fee": "10",
352-
"Sequence": 1,
353-
"Flags": 2147483648,
354-
"CancelAfter": 695123456,
355-
"FinishAfter": 695000000,
356-
"Condition": "A0258020C4F71E9B01F5A78023E932ABF6B2C1F020986E6C9E55678FFBAE67A2F5B474680103080000000000000000000000000000000000000000000000000000000000000000",
357-
"DestinationTag": 12345,
358-
"SourceTag": 54321,
359-
"OwnerNode": "0000000000000000",
360-
"PreviousTxnID": "C4F71E9B01F5A78023E932ABF6B2C1F020986E6C9E55678FFBAE67A2F5B47468",
361-
"LastLedgerSequence": 12345678,
362-
"NetworkID": 1024,
363-
"Memos": [
364-
{
365-
"Memo": {
366-
"MemoType": "657363726F77",
367-
"MemoData": "457363726F77206372656174656420666F72207061796D656E74"
368-
}
369-
}
370-
],
371-
"Signers": [
372-
{
373-
"Signer": {
374-
"Account": "rSIGNER123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
375-
"SigningPubKey": "ED5F93AB1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF12345678",
376-
"TxnSignature": "3045022100D7F67A81F343...B87D"
377-
}
378-
}
379-
],
380-
"SigningPubKey": "ED5F93AB1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF12345678",
381-
"TxnSignature": "3045022100D7F67A81F343...B87D"
382-
}`,
383-
expectUnmarshalError: false,
384-
},
385-
{
386-
name: "pass - full PaymentChannelClaim with MPTCurrencyAmount",
387-
jsonData: `{
388-
"TransactionType": "PaymentChannelClaim",
389-
"Account": "rEXAMPLE123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
390-
"Channel": "ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC1",
391-
"Amount": {
392-
"mpt_issuance_id": "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF",
393-
"value": "1000000"
394-
},
395-
"Balance": {
396-
"mpt_issuance_id": "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF",
397-
"value": "900000"
398-
},
399-
"CredentialIDs": ["1234567890abcdef", "1234567890abcdefg"],
400-
"Fee": "10",
401-
"Sequence": 1,
402-
"Flags": 2147483648,
403-
"CancelAfter": 695123456,
404-
"FinishAfter": 695000000,
405-
"Condition": "A0258020C4F71E9B01F5A78023E932ABF6B2C1F020986E6C9E55678FFBAE67A2F5B474680103080000000000000000000000000000000000000000000000000000000000000000",
406-
"DestinationTag": 12345,
407-
"SourceTag": 54321,
408-
"OwnerNode": "0000000000000000",
409-
"PreviousTxnID": "C4F71E9B01F5A78023E932ABF6B2C1F020986E6C9E55678FFBAE67A2F5B47468",
410-
"LastLedgerSequence": 12345678,
411-
"NetworkID": 1024,
412-
"Memos": [
413-
{
414-
"Memo": {
415-
"MemoType": "657363726F77",
416-
"MemoData": "457363726F77206372656174656420666F72207061796D656E74"
417-
}
418-
}
419-
],
420-
"Signers": [
421-
{
422-
"Signer": {
423-
"Account": "rSIGNER123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
424-
"SigningPubKey": "ED5F93AB1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF12345678",
425-
"TxnSignature": "3045022100D7F67A81F343...B87D"
426-
}
427-
}
428-
],
429-
"SigningPubKey": "ED5F93AB1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF12345678",
430-
"TxnSignature": "3045022100D7F67A81F343...B87D"
431-
}`,
432-
expectUnmarshalError: false,
433-
},
434-
{
435-
name: "pass - full PaymentChannelClaim with XRPCurrencyAmount",
436-
jsonData: `{
437-
"TransactionType": "PaymentChannelClaim",
438-
"Account": "rEXAMPLE123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
439-
"Channel": "ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC123ABC1",
440-
"Amount": "1000000",
441-
"Balance": "30000",
442-
"CredentialIDs": ["1234567890abcdef", "1234567890abcdefg"],
443-
"Fee": "10",
444-
"Sequence": 1,
445-
"Flags": 2147483648,
446-
"CancelAfter": 695123456,
447-
"FinishAfter": 695000000,
448-
"Condition": "A0258020C4F71E9B01F5A78023E932ABF6B2C1F020986E6C9E55678FFBAE67A2F5B474680103080000000000000000000000000000000000000000000000000000000000000000",
449-
"DestinationTag": 12345,
450-
"SourceTag": 54321,
451-
"OwnerNode": "0000000000000000",
452-
"PreviousTxnID": "C4F71E9B01F5A78023E932ABF6B2C1F020986E6C9E55678FFBAE67A2F5B47468",
453-
"LastLedgerSequence": 12345678,
454-
"NetworkID": 1024,
455-
"Memos": [
456-
{
457-
"Memo": {
458-
"MemoType": "657363726F77",
459-
"MemoData": "457363726F77206372656174656420666F72207061796D656E74"
460-
}
461-
}
462-
],
463-
"Signers": [
464-
{
465-
"Signer": {
466-
"Account": "rSIGNER123456789ABCDEFGHJKLMNPQRSTUVWXYZ",
467-
"SigningPubKey": "ED5F93AB1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF12345678",
468-
"TxnSignature": "3045022100D7F67A81F343...B87D"
469-
}
470-
}
471-
],
472-
"SigningPubKey": "ED5F93AB1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF12345678",
473-
"TxnSignature": "3045022100D7F67A81F343...B87D"
474-
}`,
475-
expectUnmarshalError: false,
476-
},
477-
}
478-
479-
for _, tt := range tests {
480-
t.Run(tt.name, func(t *testing.T) {
481-
var paymentChannelCreate PaymentChannelClaim
482-
err := json.Unmarshal([]byte(tt.jsonData), &paymentChannelCreate)
483-
fmt.Println(paymentChannelCreate.TransactionType)
484-
if (err != nil) != tt.expectUnmarshalError {
485-
t.Errorf("Unmarshal() error = %v, expectUnmarshalError %v", err, tt.expectUnmarshalError)
486-
return
487-
}
488-
489-
})
490-
}
491-
}

0 commit comments

Comments
 (0)