Rename Tag to Attribute

This commit is contained in:
Simon Warta 2020-09-21 12:59:22 +02:00
parent 63082a9e85
commit c97c43fbc7
4 changed files with 21 additions and 19 deletions

View File

@ -55,7 +55,7 @@
- @cosmjs/tendermint-rpc: Change type of `GenesisResponse.appState` to
`Record<string, unknown> | undefined`.
- @cosmjs/tendermint-rpc: Remove obsolete `TxData.tags` and make `TxData.events`
non-optional.
non-optional. Rename `Tag` to `Attribute`.
- @cosmjs/utils: Add `assertDefined`.
- @cosmjs/faucet: Rename binary from `cosmwasm-faucet` to `cosmos-faucet`.

View File

@ -55,8 +55,8 @@ export interface BlockResultsResponse {
readonly results: readonly TxData[];
readonly validatorUpdates: readonly Validator[];
readonly consensusUpdates?: ConsensusParams;
readonly beginBlock?: readonly Tag[];
readonly endBlock?: readonly Tag[];
readonly beginBlock?: readonly Attribute[];
readonly endBlock?: readonly Attribute[];
}
export interface BlockchainResponse {
@ -163,14 +163,15 @@ export const getBlockEventHeight = (event: NewBlockEvent): number => event.heade
// Helper items used above
export interface Tag {
/** An event attribute */
export interface Attribute {
readonly key: Uint8Array;
readonly value: Uint8Array;
}
export interface Event {
readonly type: string;
readonly attributes: readonly Tag[];
readonly attributes: readonly Attribute[];
}
export interface TxData {

View File

@ -90,31 +90,31 @@ function decodeAbciQuery(data: RpcAbciQueryResponse): responses.AbciQueryRespons
};
}
interface RpcTag {
interface RpcAttribute {
readonly key: Base64String;
readonly value: Base64String;
}
function decodeTag(tag: RpcTag): responses.Tag {
function decodeAttribute(attribute: RpcAttribute): responses.Attribute {
return {
key: Base64.decode(assertNotEmpty(tag.key)),
value: Base64.decode(assertNotEmpty(tag.value)),
key: Base64.decode(assertNotEmpty(attribute.key)),
value: Base64.decode(assertNotEmpty(attribute.value)),
};
}
function decodeTags(tags: readonly RpcTag[]): readonly responses.Tag[] {
return assertArray(tags).map(decodeTag);
function decodeAttributes(attributes: readonly RpcAttribute[]): responses.Attribute[] {
return assertArray(attributes).map(decodeAttribute);
}
interface RpcEvent {
readonly type: string;
readonly attributes: readonly RpcTag[];
readonly attributes: readonly RpcAttribute[];
}
function decodeEvent(event: RpcEvent): responses.Event {
return {
type: event.type,
attributes: decodeTags(event.attributes),
attributes: decodeAttributes(event.attributes),
};
}
@ -248,8 +248,8 @@ function decodeBlockResults(data: RpcBlockResultsResponse): responses.BlockResul
results: results.map(decodeTxData),
validatorUpdates: validatorUpdates.map(decodeValidatorUpdate),
consensusUpdates: may(decodeConsensusParams, data.consensus_param_updates),
beginBlock: may(decodeTags, data.begin_block_events),
endBlock: may(decodeTags, data.end_block_events),
beginBlock: may(decodeAttributes, data.begin_block_events),
endBlock: may(decodeAttributes, data.end_block_events),
};
}

View File

@ -47,8 +47,8 @@ export interface BlockResultsResponse {
readonly results: readonly TxData[];
readonly validatorUpdates: readonly Validator[];
readonly consensusUpdates?: ConsensusParams;
readonly beginBlock?: readonly Tag[];
readonly endBlock?: readonly Tag[];
readonly beginBlock?: readonly Attribute[];
readonly endBlock?: readonly Attribute[];
}
export interface BlockchainResponse {
readonly lastHeight: number;
@ -126,13 +126,14 @@ export interface TxEvent {
export declare const getTxEventHeight: (event: TxEvent) => number;
export declare const getHeaderEventHeight: (event: NewBlockHeaderEvent) => number;
export declare const getBlockEventHeight: (event: NewBlockEvent) => number;
export interface Tag {
/** An event attribute */
export interface Attribute {
readonly key: Uint8Array;
readonly value: Uint8Array;
}
export interface Event {
readonly type: string;
readonly attributes: readonly Tag[];
readonly attributes: readonly Attribute[];
}
export interface TxData {
readonly code: number;