forked from xyield/xrpl-go
-
Notifications
You must be signed in to change notification settings - Fork 18
[TA-5164] Add PermissionedDomain ledger entry type #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cea3dc2
refactor(xrpl): remove unused SubmitBatchOptions struct from client_o…
banasa44 808df05
feat(xrpl): add PermissionedDomain ledger entry type
banasa44 f0f6598
chore(changelog): add PermissionedDomain ledger entry type
banasa44 207d9c2
feat(xrpl): add Flatten method and corresponding tests for Permission…
banasa44 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package ledger | ||
|
|
||
| import "github.com/Peersyst/xrpl-go/xrpl/transaction/types" | ||
|
|
||
| // A PermissionedDomain ledger entry describes a single permissioned domain instance. | ||
| // You can create a permissioned domain by sending a PermissionedDomainSet transaction. | ||
| // | ||
| // ```json | ||
| // | ||
| // { | ||
| // "LedgerEntryType": "PermissionedDomain", | ||
| // "Fee": "10", | ||
| // "Flags": 0, | ||
| // "Owner": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", | ||
| // "OwnerNode": "0000000000000000", | ||
| // "Sequence": 390, | ||
| // "AcceptedCredentials": [ | ||
| // { | ||
| // "Credential": { | ||
| // "Issuer": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", | ||
| // "CredentialType": "6D795F63726564656E7469616C" | ||
| // } | ||
| // } | ||
| // ], | ||
| // "PreviousTxnID": "E7E3F2BBAAF48CF893896E48DC4A02BDA0C747B198D5AE18BC3D7567EE64B904", | ||
| // "PreviousTxnLgrSeq": 8734523, | ||
| // "index": "3DFA1DDEA27AF7E466DE395CCB16158E07ECA6BC4EB5580F75EBD39DE833645F" | ||
| // } | ||
| // | ||
| // ``` | ||
|
|
||
| type PermissionedDomain struct { | ||
| // The unique ID for this ledger entry. | ||
| // In JSON, this field is represented with different names depending on the context and API method. | ||
| // (Note, even though this is specified as "optional" in the code, every ledger entry should have one unless it's legacy data from very early in the XRP Ledger's history.) | ||
| Index types.Hash256 `json:"index,omitempty"` | ||
| // The value 0x0082, mapped to the string PermissionedDomain, indicates that this is a PermissionedDomain ledger entry. | ||
| LedgerEntryType EntryType | ||
| // Fee is the transaction cost, in drops of XRP, that was paid by the | ||
| // PermissionedDomainSet transaction which created or most recently modified | ||
| // this PermissionedDomain ledger entry. | ||
| Fee types.XRPCurrencyAmount | ||
| // Set of bit-flags for this ledger entry. | ||
| Flags uint32 | ||
| // The address of the account that owns this domain. | ||
| Owner types.Address | ||
| // A hint indicating which page of the owner directory links to this entry, | ||
| // in case the directory consists of multiple pages. | ||
| OwnerNode string | ||
| // The Sequence value of the transaction that created this entry. | ||
| Sequence uint32 | ||
| // A list of 1 to 10 Credential objects that grant access to this domain. | ||
| // The array is stored sorted by issuer. | ||
| AcceptedCredentials types.AuthorizeCredentialList | ||
| // The identifying hash of the transaction that most recently modified this entry. | ||
| PreviousTxnID types.Hash256 | ||
| // The index of the ledger that contains the transaction that most recently modified this object. | ||
| PreviousTxnLgrSeq uint32 | ||
| } | ||
|
|
||
| func (*PermissionedDomain) EntryType() EntryType { | ||
| return PermissionedDomainEntry | ||
| } | ||
|
|
||
| func (p *PermissionedDomain) Flatten() FlatLedgerObject { | ||
| flattened := make(FlatLedgerObject) | ||
| if p.Index.String() != "" { | ||
| flattened["index"] = p.Index.String() | ||
| } | ||
| flattened["LedgerEntryType"] = p.LedgerEntryType | ||
| flattened["Fee"] = p.Fee.Flatten() | ||
| flattened["Flags"] = p.Flags | ||
| flattened["Owner"] = p.Owner.String() | ||
| flattened["OwnerNode"] = p.OwnerNode | ||
| flattened["Sequence"] = p.Sequence | ||
| flattened["AcceptedCredentials"] = p.AcceptedCredentials.Flatten() | ||
| flattened["PreviousTxnID"] = p.PreviousTxnID.String() | ||
| flattened["PreviousTxnLgrSeq"] = p.PreviousTxnLgrSeq | ||
|
|
||
| return flattened | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| package ledger | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/Peersyst/xrpl-go/xrpl/testutil" | ||
| "github.com/Peersyst/xrpl-go/xrpl/transaction/types" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestPermissionedDomain_EntryType(t *testing.T) { | ||
| permissionedDomain := &PermissionedDomain{} | ||
| require.Equal(t, permissionedDomain.EntryType(), PermissionedDomainEntry) | ||
| } | ||
|
|
||
| func TestPermissionedDomain(t *testing.T) { | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| permissionedDomain *PermissionedDomain | ||
| expected string | ||
| }{ | ||
| { | ||
| name: "pass - valid PermissionedDomain", | ||
| permissionedDomain: &PermissionedDomain{ | ||
| Index: types.Hash256("3DFA1DDEA27AF7E466DE395CCB16158E07ECA6BC4EB5580F75EBD39DE833645F"), | ||
| LedgerEntryType: PermissionedDomainEntry, | ||
| Fee: types.XRPCurrencyAmount(10), | ||
| Flags: 0, | ||
| Owner: types.Address("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn"), | ||
| OwnerNode: "0000000000000000", | ||
| Sequence: 390, | ||
| AcceptedCredentials: types.AuthorizeCredentialList{ | ||
| { | ||
| Credential: types.Credential{ | ||
| Issuer: types.Address("ra5nK24KXen9AHvsdFTKHSANinZseWnPcX"), | ||
| CredentialType: types.CredentialType("6D795F63726564656E7469616C"), | ||
| }, | ||
| }, | ||
| }, | ||
| PreviousTxnID: types.Hash256("E7E3F2BBAAF48CF893896E48DC4A02BDA0C747B198D5AE18BC3D7567EE64B904"), | ||
| PreviousTxnLgrSeq: 8734523, | ||
| }, | ||
| expected: `{ | ||
| "index": "3DFA1DDEA27AF7E466DE395CCB16158E07ECA6BC4EB5580F75EBD39DE833645F", | ||
| "LedgerEntryType": "PermissionedDomain", | ||
| "Fee": "10", | ||
| "Flags": 0, | ||
| "Owner": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", | ||
| "OwnerNode": "0000000000000000", | ||
| "Sequence": 390, | ||
| "AcceptedCredentials": [ | ||
| { | ||
| "Credential": { | ||
| "Issuer": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", | ||
| "CredentialType": "6D795F63726564656E7469616C" | ||
| } | ||
| } | ||
| ], | ||
| "PreviousTxnID": "E7E3F2BBAAF48CF893896E48DC4A02BDA0C747B198D5AE18BC3D7567EE64B904", | ||
| "PreviousTxnLgrSeq": 8734523 | ||
| }`, | ||
| }, | ||
| } | ||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| if err := testutil.SerializeAndDeserialize(t, test.permissionedDomain, test.expected); err != nil { | ||
| t.Error(err) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestPermissionedDomain_Flatten(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| permissionedDomain *PermissionedDomain | ||
| expected string | ||
| }{ | ||
| { | ||
| name: "pass - valid PermissionedDomain", | ||
| permissionedDomain: &PermissionedDomain{ | ||
| Index: types.Hash256("3DFA1DDEA27AF7E466DE395CCB16158E07ECA6BC4EB5580F75EBD39DE833645F"), | ||
| LedgerEntryType: PermissionedDomainEntry, | ||
| Fee: types.XRPCurrencyAmount(10), | ||
| Flags: 0, | ||
| Owner: types.Address("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn"), | ||
| OwnerNode: "0000000000000000", | ||
| Sequence: 390, | ||
| AcceptedCredentials: types.AuthorizeCredentialList{ | ||
| { | ||
| Credential: types.Credential{ | ||
| Issuer: types.Address("ra5nK24KXen9AHvsdFTKHSANinZseWnPcX"), | ||
| CredentialType: types.CredentialType("6D795F63726564656E7469616C"), | ||
| }, | ||
| }, | ||
| }, | ||
| PreviousTxnID: types.Hash256("E7E3F2BBAAF48CF893896E48DC4A02BDA0C747B198D5AE18BC3D7567EE64B904"), | ||
| PreviousTxnLgrSeq: 8734523, | ||
| }, | ||
| expected: `{ | ||
| "index": "3DFA1DDEA27AF7E466DE395CCB16158E07ECA6BC4EB5580F75EBD39DE833645F", | ||
| "LedgerEntryType": "PermissionedDomain", | ||
| "Fee": "10", | ||
| "Flags": 0, | ||
| "Owner": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", | ||
| "OwnerNode": "0000000000000000", | ||
| "Sequence": 390, | ||
| "AcceptedCredentials": [ | ||
| { | ||
| "Credential": { | ||
| "Issuer": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", | ||
| "CredentialType": "6D795F63726564656E7469616C" | ||
| } | ||
| } | ||
| ], | ||
| "PreviousTxnID": "E7E3F2BBAAF48CF893896E48DC4A02BDA0C747B198D5AE18BC3D7567EE64B904", | ||
| "PreviousTxnLgrSeq": 8734523 | ||
| }`, | ||
| }, | ||
| } | ||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| if err := testutil.CompareFlattenAndExpected(test.permissionedDomain.Flatten(), []byte(test.expected)); err != nil { | ||
| t.Error(err) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.