-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: encode reference type and id into the Kin memo field
- Loading branch information
Showing
18 changed files
with
167 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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 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
7 changes: 7 additions & 0 deletions
7
libs/solana/src/lib/helpers/__snapshots__/create-reference-key.spec.ts.snap
This file contains 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,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`createReferenceKey should create a reference key based on id 1`] = `"my-reference-id"`; | ||
|
||
exports[`createReferenceKey should create a reference key based on type 1`] = `"my-type"`; | ||
|
||
exports[`createReferenceKey should create a reference key based on type and id 1`] = `"my-type:my-reference-id"`; |
This file contains 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,39 @@ | ||
import { createReferenceKey } from './create-reference-key' | ||
|
||
describe('createReferenceKey', () => { | ||
it('should create a reference key based on type and id', () => { | ||
const key = createReferenceKey({ type: 'my-type', id: 'my-reference-id' }) | ||
|
||
expect(key).toMatchSnapshot() | ||
}) | ||
|
||
it('should create a reference key based on type', () => { | ||
const key = createReferenceKey({ type: 'my-type' }) | ||
|
||
expect(key).toMatchSnapshot() | ||
}) | ||
|
||
it('should create a reference key based on id', () => { | ||
const key = createReferenceKey({ id: 'my-reference-id' }) | ||
|
||
expect(key).toMatchSnapshot() | ||
}) | ||
|
||
it('should return undefined if no type or id is provided', () => { | ||
const key = createReferenceKey({}) | ||
|
||
expect(key).toBeUndefined() | ||
}) | ||
|
||
it('should fail if a type is longer than 10 characters', () => { | ||
expect(() => createReferenceKey({ type: 'my-type-is-longer-than-10-characters' })).toThrow( | ||
'Reference type must be 10 characters or less', | ||
) | ||
}) | ||
|
||
it('should fail if an id is longer than 64 characters', () => { | ||
expect(() => createReferenceKey({ id: 'abcdefghijklmnopqrstuvwxyz1111' })).toThrow( | ||
'Reference id must be 26 characters or less', | ||
) | ||
}) | ||
}) |
This file contains 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,31 @@ | ||
/** | ||
* Create a reference key from a type and id. | ||
* @param {string} type | ||
* @param {string} id | ||
* @returns {string} | ||
*/ | ||
export function createReferenceKey({ type, id }: { type?: string | null; id?: string | null }): string | undefined { | ||
if (!type && !id) { | ||
return undefined | ||
} | ||
|
||
// Fail if type is longer than 10 characters | ||
if (type && type.length > 10) { | ||
throw new Error('Reference type must be 10 characters or less') | ||
} | ||
// Fail if id is longer than 26 characters | ||
if (id && id.length > 26) { | ||
throw new Error('Reference id must be 26 characters or less') | ||
} | ||
|
||
if (type && id) { | ||
return `${type}:${id}` | ||
} | ||
if (type) { | ||
return type | ||
} | ||
if (id) { | ||
return id | ||
} | ||
return undefined | ||
} |
This file contains 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 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 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 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 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 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 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 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 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 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 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
2 changes: 2 additions & 0 deletions
2
libs/solana/src/lib/kin/generate-kin-memo-instruction.spec.ts
This file contains 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
Oops, something went wrong.