Skip to content

Commit

Permalink
feat(objectariumhandler): add config and limits field to objectarium …
Browse files Browse the repository at this point in the history
…init handler
  • Loading branch information
ErikssonJoakim committed Sep 6, 2023
1 parent aae852f commit fd4a3a3
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 3 deletions.
45 changes: 45 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,43 @@ type ObjectariumObject @entity {
messages: [Message]! @derivedFrom(field: "objectariumObject")
}

"""
BucketConfig is the type of the configuration of a bucket.
"""
type BucketConfig @jsonField {
"""
The algorithm used to hash the content of the objects to generate the id of the objects.
"""
hashAlgorithm: String
"""
The acceptable compression algorithms for the objects in the bucket.
"""
acceptedCompressionAlgorithms: [String!]
}

"""
BucketLimits is the type of the limits of a Objectarium bucket.
The limits are optional and if not set, there is no limit.
"""
type BucketLimits @jsonField {
"""
The maximum total size of the objects in the bucket.
"""
maxTotalSize: BigInt
"""
The maximum number of objects in the bucket.
"""
maxObjects: BigInt
"""
The maximum size of the objects in the bucket.
"""
maxObjectSize: BigInt
"""
The maximum number of pins in the bucket for an object.
"""
maxObjectPins: BigInt
}

"""
Objectarium smart contract instance (aka bucket).
"""
Expand All @@ -183,6 +220,14 @@ type Objectarium @entity {
"""
name: String!
"""
The configuration of the bucket.
"""
config: BucketConfig
"""
The limits of the bucket.
"""
limits: BucketLimits
"""
List of objects contained within the Objectarium instance.
"""
objectariumObjects: [ObjectariumObject] @derivedFrom(field: "objectarium")
Expand Down
41 changes: 38 additions & 3 deletions src/mappings/objectariumHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import type {
MsgExecuteContract,
MsgInstantiateContract,
} from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { Message, ObjectariumObject, Objectarium } from "../types";
import {
Message,
ObjectariumObject,
Objectarium,
BucketConfig,
BucketLimits,
} from "../types";
import { messageId } from "./helper";
import type { Event } from "@cosmjs/tendermint-rpc/build/tendermint37";

Expand All @@ -17,8 +23,24 @@ type Execute = Omit<MsgExecuteContract, "msg"> & {
};
};

type ObjectariumBucketConfig = {
hash_algorithm?: string;
accepted_compression_algorithms?: string[];
};

type ObjectariumBucketLimits = {
max_total_size?: bigint;
max_objects?: bigint;
max_object_size?: bigint;
max_object_pins?: bigint;
};

type Instantiate = Omit<MsgInstantiateContract, "msg"> & {
msg: { bucket: string };
msg: {
bucket: string;
config?: ObjectariumBucketConfig;
limits?: ObjectariumBucketLimits;
};
};

type ContractCalls = Execute | Instantiate;
Expand Down Expand Up @@ -117,13 +139,26 @@ export const handleInitObjectarium = async (

const {
sender,
msg: { bucket },
msg: { bucket, limits: bucketLimits, config: bucketConfig },
} = msg.msg.decodedMsg;
const limits: BucketLimits = {
maxTotalSize: bucketLimits?.max_total_size,
maxObjectSize: bucketLimits?.max_object_size,
maxObjects: bucketLimits?.max_objects,
maxObjectPins: bucketLimits?.max_object_pins,
};
const config: BucketConfig = {
hashAlgorithm: bucketConfig?.hash_algorithm,
acceptedCompressionAlgorithms:
bucketConfig?.accepted_compression_algorithms,
};

await Objectarium.create({
id: contractAddress,
owner: sender,
name: bucket,
config,
limits,
}).save();
};

Expand Down

0 comments on commit fd4a3a3

Please sign in to comment.