-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from ensdomains/set-multiple-abi-records-with…
…-multi-call add set multiple abis in setRecords + get abi by content type
- Loading branch information
Showing
11 changed files
with
212 additions
and
36 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
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
24 changes: 24 additions & 0 deletions
24
packages/ensjs/src/utils/generateSupportedContentTypes.test.ts.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { generateSupportedContentTypes } from './generateSupportedContentTypes.js' | ||
|
||
type FunctionParameters = Parameters<typeof generateSupportedContentTypes> | ||
type EncodeAsParameter = FunctionParameters[0] | ||
|
||
describe('generateSupportedContentTypes', () => { | ||
it.each([ | ||
['json', 1n], | ||
['zlib', 2n], | ||
['cbor', 4n], | ||
['uri', 8n], | ||
['unknown', 0n], | ||
[['json', 'zlib'], 3n], | ||
[['zlib', 'cbor'], 6n], | ||
[['cbor', 'uri'], 12n], | ||
[['json', 'zlib', 'cbor', 'uri'], 15n], | ||
] as [EncodeAsParameter, bigint][])( | ||
'should return the correct bitwise value supportedContentTypes %p (%p)', | ||
(encodedAs, expected) => { | ||
const result = generateSupportedContentTypes(encodedAs) | ||
expect(result).toEqual(expected) | ||
}, | ||
) | ||
}) |
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,21 @@ | ||
import type { AbiEncodeAs } from './encoders/encodeAbi.js' | ||
|
||
const abiEncodeAsMap: { [key in AbiEncodeAs]: bigint } = { | ||
json: 1n, | ||
zlib: 2n, | ||
cbor: 4n, | ||
uri: 8n, | ||
} as const | ||
|
||
export const generateSupportedContentTypes = ( | ||
encodeAsItemOrList: AbiEncodeAs | AbiEncodeAs[], | ||
): bigint => { | ||
const encodeAsList = Array.isArray(encodeAsItemOrList) | ||
? encodeAsItemOrList | ||
: [encodeAsItemOrList] | ||
return encodeAsList.reduce<bigint>((result, encodeAs) => { | ||
const contentType = abiEncodeAsMap[encodeAs] | ||
if (contentType) result |= contentType | ||
return result | ||
}, 0n) | ||
} |
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