github.com/igggame/nebulas-go@v2.1.0+incompatible/nf/nvm/v8/lib/storage.d.ts (about)

     1  // Copyright (C) 2017 go-nebulas authors
     2  //
     3  // This file is part of the go-nebulas library.
     4  //
     5  // the go-nebulas library is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // the go-nebulas library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU General Public License
    16  // along with the go-nebulas library.  If not, see <http://www.gnu.org/licenses/>.
    17  //
    18  
    19  interface StorageHandler {
    20  }
    21  
    22  interface Descriptor {
    23      // serialize value to string;
    24      stringify?(value: any): string;
    25  
    26      // deserialize value from string;
    27      parse?(value: string): any;
    28  }
    29  
    30  interface DescriptorMap {
    31      [fieldName: string]: Descriptor;
    32  }
    33  
    34  interface ContractStorageConstructor {
    35      new(handler: StorageHandler): ContractStorage;
    36  }
    37  
    38  declare const ContractStorage: ContractStorageConstructor;
    39  
    40  interface ContractStorage {
    41      // get and return value by key from Native Storage.
    42      rawGet(key: string): string;
    43      // set key and value pair to Native Storage,
    44      // return 0 for success, otherwise failure.
    45      rawSet(key: string, value: string): number;
    46  
    47      // define a object property named `fieldname` to `obj` with descriptor.
    48      // default descriptor is JSON.parse/JSON.stringify descriptor.
    49      // return this.
    50      defineProperty(obj: any, fieldName: string, descriptor?: Descriptor): any;
    51  
    52      // define object properties to `obj` from `props`.
    53      // default descriptor is JSON.parse/JSON.stringify descriptor.
    54      // return this.
    55      defineProperties(obj: any, props: DescriptorMap): any;
    56  
    57      // define a StorageMap property named `fieldname` to `obj` with descriptor.
    58      // default descriptor is JSON.parse/JSON.stringify descriptor.
    59      // return this.
    60      defineMapProperty(obj: any, fieldName: string, descriptor?: Descriptor): any;
    61  
    62      // define StorageMap properties to `obj` from `props`.
    63      // default descriptor is JSON.parse/JSON.stringify descriptor.
    64      // return this.
    65      defineMapProperties(obj: any, props: DescriptorMap): any;
    66  
    67      // delete key from Native Storage.
    68      // return 0 for success, otherwise failure.
    69      del(key: string): number;
    70  
    71      // get value by key from Native Storage,
    72      // deserialize value by calling `descriptor.parse` and return.
    73      get(key: string): any;
    74  
    75      // set key and value pair to Native Storage,
    76      // the value will be serialized to string by calling `descriptor.stringify`.
    77      // return 0 for success, otherwise failure.
    78      set(key: string, value: any): number;
    79  }
    80  
    81  interface StorageMapConstructor {
    82      new(contractStorage: ContractStorage, fieldName: string, descriptor: Descriptor): StorageMap;
    83  }
    84  
    85  declare const StorageMap: StorageMapConstructor;
    86  
    87  interface StorageMap {
    88      // delete key from Native Storage, return 0 for success, otherwise failure.
    89      del(key: string): number;
    90  
    91      // get value by key from Native Storage,
    92      // deserialize value by calling `descriptor.parse` and return.
    93      get(key: string): any;
    94  
    95      // set key and value pair to Native Storage,
    96      // the value will be serialized to string by calling `descriptor.stringify`.
    97      // return 0 for success, otherwise failure.
    98      set(key: string, value: any): number;
    99  }
   100  
   101  declare const lcs: ContractStorage;
   102  declare const gcs: ContractStorage;