Repository: FIBOSIO/fibos
Branch: master
Commit: 0db28d204138
Files: 25
Total size: 97.1 KB
Directory structure:
gitextract_4y4e10f_/
├── .gitignore
├── .gitmodules
├── .vscode/
│ ├── settings.json
│ └── tasks.json
├── CMakeLists.txt
├── LICENSE.md
├── README.md
├── fibos_build
├── idl/
│ └── zh-cn/
│ ├── DBIterator.idl
│ ├── Table.idl
│ ├── action.idl
│ ├── bc_buffer.idl
│ ├── bc_console.idl
│ ├── bc_crypto.idl
│ ├── bc_db.idl
│ ├── collect.json
│ ├── fibos.idl
│ └── trans.idl
├── installer.txt
├── src/
│ └── fibos.cpp
└── tools/
├── arch.cmake
├── config.h.in
├── gitinfo.h.in
├── os.cmake
└── subdirs.cmake
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
/out
/bin
/temp
/docs
*.sdf
*.suo
node_modules
================================================
FILE: .gitmodules
================================================
[submodule "eos"]
path = eos
url = https://github.com/EOSIO/eos.git
[submodule "fibjs"]
path = fibjs
url = https://github.com/fibjs/fibjs.git
branch = dev
================================================
FILE: .vscode/settings.json
================================================
// Place your settings in this file to overwrite the default settings
{
"editor.formatOnSave": true,
"files.associations": {
"*.idl": "java"
},
"C_Cpp.clang_format_sortIncludes": false,
"C_Cpp.clang_format_fallbackStyle": "WebKit"
}
================================================
FILE: .vscode/tasks.json
================================================
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "sh",
"args": [
"fibos_build",
"-j"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
================================================
FILE: CMakeLists.txt
================================================
cmake_minimum_required(VERSION 2.6)
include(tools/arch.cmake)
include(tools/os.cmake)
include(tools/subdirs.cmake)
set(appname fibos)
project(${appname})
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
file(GLOB_RECURSE src_list "src/*.c*")
add_executable(${appname} ${src_list})
set(BIN_DIR ${PROJECT_SOURCE_DIR}/bin/${OS}_${ARCH}_${BUILD_TYPE})
set(FIBJS_DIR ${PROJECT_SOURCE_DIR}/fibjs/bin/${OS}_${ARCH}_${BUILD_TYPE})
set(EOS_DIR ${PROJECT_SOURCE_DIR}/eos)
set(EXECUTABLE_OUTPUT_PATH ${BIN_DIR})
include(CheckIncludeFiles)
include(CheckCSourceCompiles)
set(CMAKE_C_FLAGS "${BUILD_OPTION}")
check_include_files(iconv.h HAVE_ICONV_H)
check_c_source_compiles("void posix_spawnp();
__asm__(\".symver posix_spawnp,posix_spawnp@GLIBC_2.2.5\");
void main(void){posix_spawnp();}" HAVE_GLIB_C_225_H)
check_c_source_compiles("void posix_spawnp();
__asm__(\".symver posix_spawnp,posix_spawnp@GLIBC_2.2\");
void main(void){posix_spawnp();}" HAVE_GLIB_C_22_H)
set(flags "-fsigned-char -fmessage-length=0 -fdata-sections -ffunction-sections -D_FILE_OFFSET_BITS=64")
set(ccflags "-std=c++14")
set(link_flags " ")
if(${OS} STREQUAL "Darwin")
set(link_flags "${link_flags} -mmacosx-version-min=10.9 -framework Carbon -framework IOKit")
set(flags "${flags} -mmacosx-version-min=10.9")
target_link_libraries(${appname} dl iconv stdc++)
endif()
if(${OS} STREQUAL "Linux")
target_link_libraries(${appname} dl rt)
endif()
if(${OS} STREQUAL "FreeBSD")
find_library(execinfo execinfo "/usr/local/lib" "/usr/lib")
target_link_libraries(${appname} ${execinfo})
endif()
if(${BUILD_TYPE} STREQUAL "release")
set(flags "${flags} -O3 -s ${BUILD_OPTION} -w -fvisibility=hidden")
if(${OS} STREQUAL "FreeBSD")
set(flags "${flags} -fno-omit-frame-pointer")
else()
set(flags "${flags} -fomit-frame-pointer")
endif()
set(link_flags "${link_flags} ${BUILD_OPTION}")
add_definitions(-DNDEBUG=1)
if(HAVE_GLIB_C_225_H)
set(link_flags "${link_flags} -Wl,--wrap=memcpy")
endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(link_flags "${link_flags} -static-libgcc -static-libstdc++ -Wl,--no-as-needed")
endif()
endif()
if(${BUILD_TYPE} STREQUAL "debug")
set(flags "${flags} -g -O0 ${BUILD_OPTION} -Wall -Wno-overloaded-virtual")
set(link_flags "${link_flags} ${BUILD_OPTION}")
add_definitions(-DDEBUG=1)
endif()
set(CMAKE_C_FLAGS "${flags}")
set(CMAKE_CXX_FLAGS "${flags} ${ccflags}")
include_directories("${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/fibjs/fibjs/include" "${PROJECT_SOURCE_DIR}/fibjs/vender" "${PROJECT_SOURCE_DIR}/fibjs/vender/v8" "${PROJECT_SOURCE_DIR}/fibjs/vender/v8/include" "${PROJECT_SOURCE_DIR}/fibjs/vender/mbedtls" "${PROJECT_SOURCE_DIR}/fibjs/vender/zlib/include" "${CMAKE_CURRENT_BINARY_DIR}")
MACRO(EOSLIBS dir)
file(GLOB eos_libs "${dir}/*")
foreach(eos_lib ${eos_libs})
if(IS_DIRECTORY "${eos_lib}/include")
include_directories("${eos_lib}/include")
endif()
endforeach()
ENDMACRO()
EOSLIBS("${EOS_DIR}/plugins")
EOSLIBS("${EOS_DIR}/libraries")
EOSLIBS("${EOS_DIR}/build/libraries")
include_directories("${EOS_DIR}/libraries/softfloat/source/include")
if (APPLE)
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
elseif(UNIX AND NOT APPLE)
set(OPENSSL_ROOT_DIR "/usr/include/openssl")
else()
message(FATAL_ERROR "openssl not found and don't know where to look, please specify OPENSSL_ROOT_DIR")
endif()
include_directories("${OPENSSL_ROOT_DIR}/include")
file(GLOB_RECURSE eos_alist "eos/*.a")
target_link_libraries(${appname} ${eos_alist})
find_package(LLVM 4.0 REQUIRED CONFIG)
llvm_map_components_to_libnames(LLVM_LIBS support core passes mcjit native DebugInfoDWARF)
target_link_libraries(${appname} ${LLVM_LIBS})
file(GLOB openssl_alist "${OPENSSL_ROOT_DIR}/lib/*.a")
target_link_libraries(${appname} ${openssl_alist})
target_link_libraries(${appname} boost_iostreams boost_date_time boost_chrono boost_program_options boost_filesystem boost_system secp256k1)
set(libs fibjs expat gumbo gd tiff jpeg png webp zlib leveldb snappy ev pcre sqlite mongo umysql uuid exif mbedtls v8 zmq unzip editline exlib)
foreach(lib ${libs})
target_link_libraries(${appname} "${FIBJS_DIR}/lib${lib}.a")
endforeach()
target_link_libraries(${appname} pthread boost_system)
set_target_properties(${appname} PROPERTIES LINK_FLAGS ${link_flags})
================================================
FILE: LICENSE.md
================================================
GNU GENERAL PUBLIC LICENSE
==========================
Version 3, 29 June 2007
Copyright © 2007 Free Software Foundation, Inc. <>
Everyone is permitted to copy and distribute verbatim copies of this license
document, but changing it is not allowed.
## Preamble
The GNU General Public License is a free, copyleft license for software and other
kinds of works.
The licenses for most software and other practical works are designed to take away
your freedom to share and change the works. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change all versions of a
program--to make sure it remains free software for all its users. We, the Free
Software Foundation, use the GNU General Public License for most of our software; it
applies also to any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not price. Our General
Public Licenses are designed to make sure that you have the freedom to distribute
copies of free software (and charge for them if you wish), that you receive source
code or can get it if you want it, that you can change the software or use pieces of
it in new free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you these rights or
asking you to surrender the rights. Therefore, you have certain responsibilities if
you distribute copies of the software, or if you modify it: responsibilities to
respect the freedom of others.
For example, if you distribute copies of such a program, whether gratis or for a fee,
you must pass on to the recipients the same freedoms that you received. You must make
sure that they, too, receive or can get the source code. And you must show them these
terms so they know their rights.
Developers that use the GNU GPL protect your rights with two steps: (1) assert
copyright on the software, and (2) offer you this License giving you legal permission
to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains that there is
no warranty for this free software. For both users' and authors' sake, the GPL
requires that modified versions be marked as changed, so that their problems will not
be attributed erroneously to authors of previous versions.
Some devices are designed to deny users access to install or run modified versions of
the software inside them, although the manufacturer can do so. This is fundamentally
incompatible with the aim of protecting users' freedom to change the software. The
systematic pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we have designed
this version of the GPL to prohibit the practice for those products. If such problems
arise substantially in other domains, we stand ready to extend this provision to
those domains in future versions of the GPL, as needed to protect the freedom of
users.
Finally, every program is threatened constantly by software patents. States should
not allow patents to restrict development and use of software on general-purpose
computers, but in those that do, we wish to avoid the special danger that patents
applied to a free program could make it effectively proprietary. To prevent this, the
GPL assures that patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and modification follow.
## TERMS AND CONDITIONS
### 0. Definitions.
“This License” refers to version 3 of the GNU General Public License.
“Copyright” also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
“The Program” refers to any copyrightable work licensed under this
License. Each licensee is addressed as “you”. “Licensees” and
“recipients” may be individuals or organizations.
To “modify” a work means to copy from or adapt all or part of the work in
a fashion requiring copyright permission, other than the making of an exact copy. The
resulting work is called a “modified version” of the earlier work or a
work “based on” the earlier work.
A “covered work” means either the unmodified Program or a work based on
the Program.
To “propagate” a work means to do anything with it that, without
permission, would make you directly or secondarily liable for infringement under
applicable copyright law, except executing it on a computer or modifying a private
copy. Propagation includes copying, distribution (with or without modification),
making available to the public, and in some countries other activities as well.
To “convey” a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through a computer
network, with no transfer of a copy, is not conveying.
An interactive user interface displays “Appropriate Legal Notices” to the
extent that it includes a convenient and prominently visible feature that (1)
displays an appropriate copyright notice, and (2) tells the user that there is no
warranty for the work (except to the extent that warranties are provided), that
licensees may convey the work under this License, and how to view a copy of this
License. If the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
### 1. Source Code.
The “source code” for a work means the preferred form of the work for
making modifications to it. “Object code” means any non-source form of a
work.
A “Standard Interface” means an interface that either is an official
standard defined by a recognized standards body, or, in the case of interfaces
specified for a particular programming language, one that is widely used among
developers working in that language.
The “System Libraries” of an executable work include anything, other than
the work as a whole, that (a) is included in the normal form of packaging a Major
Component, but which is not part of that Major Component, and (b) serves only to
enable use of the work with that Major Component, or to implement a Standard
Interface for which an implementation is available to the public in source code form.
A “Major Component”, in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system (if any) on which
the executable work runs, or a compiler used to produce the work, or an object code
interpreter used to run it.
The “Corresponding Source” for a work in object code form means all the
source code needed to generate, install, and (for an executable work) run the object
code and to modify the work, including scripts to control those activities. However,
it does not include the work's System Libraries, or general-purpose tools or
generally available free programs which are used unmodified in performing those
activities but which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for the work, and
the source code for shared libraries and dynamically linked subprograms that the work
is specifically designed to require, such as by intimate data communication or
control flow between those subprograms and other parts of the work.
The Corresponding Source need not include anything that users can regenerate
automatically from other parts of the Corresponding Source.
The Corresponding Source for a work in source code form is that same work.
### 2. Basic Permissions.
All rights granted under this License are granted for the term of copyright on the
Program, and are irrevocable provided the stated conditions are met. This License
explicitly affirms your unlimited permission to run the unmodified Program. The
output from running a covered work is covered by this License only if the output,
given its content, constitutes a covered work. This License acknowledges your rights
of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not convey, without
conditions so long as your license otherwise remains in force. You may convey covered
works to others for the sole purpose of having them make modifications exclusively
for you, or provide you with facilities for running those works, provided that you
comply with the terms of this License in conveying all material for which you do not
control copyright. Those thus making or running the covered works for you must do so
exclusively on your behalf, under your direction and control, on terms that prohibit
them from making any copies of your copyrighted material outside their relationship
with you.
Conveying under any other circumstances is permitted solely under the conditions
stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological measure under any
applicable law fulfilling obligations under article 11 of the WIPO copyright treaty
adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention
of such measures.
When you convey a covered work, you waive any legal power to forbid circumvention of
technological measures to the extent such circumvention is effected by exercising
rights under this License with respect to the covered work, and you disclaim any
intention to limit operation or modification of the work as a means of enforcing,
against the work's users, your or third parties' legal rights to forbid circumvention
of technological measures.
### 4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you receive it, in any
medium, provided that you conspicuously and appropriately publish on each copy an
appropriate copyright notice; keep intact all notices stating that this License and
any non-permissive terms added in accord with section 7 apply to the code; keep
intact all notices of the absence of any warranty; and give all recipients a copy of
this License along with the Program.
You may charge any price or no price for each copy that you convey, and you may offer
support or warranty protection for a fee.
### 5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to produce it from
the Program, in the form of source code under the terms of section 4, provided that
you also meet all of these conditions:
* **a)** The work must carry prominent notices stating that you modified it, and giving a
relevant date.
* **b)** The work must carry prominent notices stating that it is released under this
License and any conditions added under section 7. This requirement modifies the
requirement in section 4 to “keep intact all notices”.
* **c)** You must license the entire work, as a whole, under this License to anyone who
comes into possession of a copy. This License will therefore apply, along with any
applicable section 7 additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no permission to license the
work in any other way, but it does not invalidate such permission if you have
separately received it.
* **d)** If the work has interactive user interfaces, each must display Appropriate Legal
Notices; however, if the Program has interactive interfaces that do not display
Appropriate Legal Notices, your work need not make them do so.
A compilation of a covered work with other separate and independent works, which are
not by their nature extensions of the covered work, and which are not combined with
it such as to form a larger program, in or on a volume of a storage or distribution
medium, is called an “aggregate” if the compilation and its resulting
copyright are not used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work in an aggregate
does not cause this License to apply to the other parts of the aggregate.
### 6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms of sections 4 and
5, provided that you also convey the machine-readable Corresponding Source under the
terms of this License, in one of these ways:
* **a)** Convey the object code in, or embodied in, a physical product (including a
physical distribution medium), accompanied by the Corresponding Source fixed on a
durable physical medium customarily used for software interchange.
* **b)** Convey the object code in, or embodied in, a physical product (including a
physical distribution medium), accompanied by a written offer, valid for at least
three years and valid for as long as you offer spare parts or customer support for
that product model, to give anyone who possesses the object code either (1) a copy of
the Corresponding Source for all the software in the product that is covered by this
License, on a durable physical medium customarily used for software interchange, for
a price no more than your reasonable cost of physically performing this conveying of
source, or (2) access to copy the Corresponding Source from a network server at no
charge.
* **c)** Convey individual copies of the object code with a copy of the written offer to
provide the Corresponding Source. This alternative is allowed only occasionally and
noncommercially, and only if you received the object code with such an offer, in
accord with subsection 6b.
* **d)** Convey the object code by offering access from a designated place (gratis or for
a charge), and offer equivalent access to the Corresponding Source in the same way
through the same place at no further charge. You need not require recipients to copy
the Corresponding Source along with the object code. If the place to copy the object
code is a network server, the Corresponding Source may be on a different server
(operated by you or a third party) that supports equivalent copying facilities,
provided you maintain clear directions next to the object code saying where to find
the Corresponding Source. Regardless of what server hosts the Corresponding Source,
you remain obligated to ensure that it is available for as long as needed to satisfy
these requirements.
* **e)** Convey the object code using peer-to-peer transmission, provided you inform
other peers where the object code and Corresponding Source of the work are being
offered to the general public at no charge under subsection 6d.
A separable portion of the object code, whose source code is excluded from the
Corresponding Source as a System Library, need not be included in conveying the
object code work.
A “User Product” is either (1) a “consumer product”, which
means any tangible personal property which is normally used for personal, family, or
household purposes, or (2) anything designed or sold for incorporation into a
dwelling. In determining whether a product is a consumer product, doubtful cases
shall be resolved in favor of coverage. For a particular product received by a
particular user, “normally used” refers to a typical or common use of
that class of product, regardless of the status of the particular user or of the way
in which the particular user actually uses, or expects or is expected to use, the
product. A product is a consumer product regardless of whether the product has
substantial commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
“Installation Information” for a User Product means any methods,
procedures, authorization keys, or other information required to install and execute
modified versions of a covered work in that User Product from a modified version of
its Corresponding Source. The information must suffice to ensure that the continued
functioning of the modified object code is in no case prevented or interfered with
solely because modification has been made.
If you convey an object code work under this section in, or with, or specifically for
use in, a User Product, and the conveying occurs as part of a transaction in which
the right of possession and use of the User Product is transferred to the recipient
in perpetuity or for a fixed term (regardless of how the transaction is
characterized), the Corresponding Source conveyed under this section must be
accompanied by the Installation Information. But this requirement does not apply if
neither you nor any third party retains the ability to install modified object code
on the User Product (for example, the work has been installed in ROM).
The requirement to provide Installation Information does not include a requirement to
continue to provide support service, warranty, or updates for a work that has been
modified or installed by the recipient, or for the User Product in which it has been
modified or installed. Access to a network may be denied when the modification itself
materially and adversely affects the operation of the network or violates the rules
and protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided, in accord with
this section must be in a format that is publicly documented (and with an
implementation available to the public in source code form), and must require no
special password or key for unpacking, reading or copying.
### 7. Additional Terms.
“Additional permissions” are terms that supplement the terms of this
License by making exceptions from one or more of its conditions. Additional
permissions that are applicable to the entire Program shall be treated as though they
were included in this License, to the extent that they are valid under applicable
law. If additional permissions apply only to part of the Program, that part may be
used separately under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option remove any
additional permissions from that copy, or from any part of it. (Additional
permissions may be written to require their own removal in certain cases when you
modify the work.) You may place additional permissions on material, added by you to a
covered work, for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you add to a
covered work, you may (if authorized by the copyright holders of that material)
supplement the terms of this License with terms:
* **a)** Disclaiming warranty or limiting liability differently from the terms of
sections 15 and 16 of this License; or
* **b)** Requiring preservation of specified reasonable legal notices or author
attributions in that material or in the Appropriate Legal Notices displayed by works
containing it; or
* **c)** Prohibiting misrepresentation of the origin of that material, or requiring that
modified versions of such material be marked in reasonable ways as different from the
original version; or
* **d)** Limiting the use for publicity purposes of names of licensors or authors of the
material; or
* **e)** Declining to grant rights under trademark law for use of some trade names,
trademarks, or service marks; or
* **f)** Requiring indemnification of licensors and authors of that material by anyone
who conveys the material (or modified versions of it) with contractual assumptions of
liability to the recipient, for any liability that these contractual assumptions
directly impose on those licensors and authors.
All other non-permissive additional terms are considered “further
restrictions” within the meaning of section 10. If the Program as you received
it, or any part of it, contains a notice stating that it is governed by this License
along with a term that is a further restriction, you may remove that term. If a
license document contains a further restriction but permits relicensing or conveying
under this License, you may add to a covered work material governed by the terms of
that license document, provided that the further restriction does not survive such
relicensing or conveying.
If you add terms to a covered work in accord with this section, you must place, in
the relevant source files, a statement of the additional terms that apply to those
files, or a notice indicating where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the form of a
separately written license, or stated as exceptions; the above requirements apply
either way.
### 8. Termination.
You may not propagate or modify a covered work except as expressly provided under
this License. Any attempt otherwise to propagate or modify it is void, and will
automatically terminate your rights under this License (including any patent licenses
granted under the third paragraph of section 11).
However, if you cease all violation of this License, then your license from a
particular copyright holder is reinstated (a) provisionally, unless and until the
copyright holder explicitly and finally terminates your license, and (b) permanently,
if the copyright holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is reinstated permanently
if the copyright holder notifies you of the violation by some reasonable means, this
is the first time you have received notice of violation of this License (for any
work) from that copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the licenses of
parties who have received copies or rights from you under this License. If your
rights have been terminated and not permanently reinstated, you do not qualify to
receive new licenses for the same material under section 10.
### 9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or run a copy of the
Program. Ancillary propagation of a covered work occurring solely as a consequence of
using peer-to-peer transmission to receive a copy likewise does not require
acceptance. However, nothing other than this License grants you permission to
propagate or modify any covered work. These actions infringe copyright if you do not
accept this License. Therefore, by modifying or propagating a covered work, you
indicate your acceptance of this License to do so.
### 10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically receives a license
from the original licensors, to run, modify and propagate that work, subject to this
License. You are not responsible for enforcing compliance by third parties with this
License.
An “entity transaction” is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an organization, or
merging organizations. If propagation of a covered work results from an entity
transaction, each party to that transaction who receives a copy of the work also
receives whatever licenses to the work the party's predecessor in interest had or
could give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if the predecessor
has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the rights granted or
affirmed under this License. For example, you may not impose a license fee, royalty,
or other charge for exercise of rights granted under this License, and you may not
initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging
that any patent claim is infringed by making, using, selling, offering for sale, or
importing the Program or any portion of it.
### 11. Patents.
A “contributor” is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The work thus
licensed is called the contributor's “contributor version”.
A contributor's “essential patent claims” are all patent claims owned or
controlled by the contributor, whether already acquired or hereafter acquired, that
would be infringed by some manner, permitted by this License, of making, using, or
selling its contributor version, but do not include claims that would be infringed
only as a consequence of further modification of the contributor version. For
purposes of this definition, “control” includes the right to grant patent
sublicenses in a manner consistent with the requirements of this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license
under the contributor's essential patent claims, to make, use, sell, offer for sale,
import and otherwise run, modify and propagate the contents of its contributor
version.
In the following three paragraphs, a “patent license” is any express
agreement or commitment, however denominated, not to enforce a patent (such as an
express permission to practice a patent or covenant not to sue for patent
infringement). To “grant” such a patent license to a party means to make
such an agreement or commitment not to enforce a patent against the party.
If you convey a covered work, knowingly relying on a patent license, and the
Corresponding Source of the work is not available for anyone to copy, free of charge
and under the terms of this License, through a publicly available network server or
other readily accessible means, then you must either (1) cause the Corresponding
Source to be so available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner consistent with
the requirements of this License, to extend the patent license to downstream
recipients. “Knowingly relying” means you have actual knowledge that, but
for the patent license, your conveying the covered work in a country, or your
recipient's use of the covered work in a country, would infringe one or more
identifiable patents in that country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or arrangement, you
convey, or propagate by procuring conveyance of, a covered work, and grant a patent
license to some of the parties receiving the covered work authorizing them to use,
propagate, modify or convey a specific copy of the covered work, then the patent
license you grant is automatically extended to all recipients of the covered work and
works based on it.
A patent license is “discriminatory” if it does not include within the
scope of its coverage, prohibits the exercise of, or is conditioned on the
non-exercise of one or more of the rights that are specifically granted under this
License. You may not convey a covered work if you are a party to an arrangement with
a third party that is in the business of distributing software, under which you make
payment to the third party based on the extent of your activity of conveying the
work, and under which the third party grants, to any of the parties who would receive
the covered work from you, a discriminatory patent license (a) in connection with
copies of the covered work conveyed by you (or copies made from those copies), or (b)
primarily for and in connection with specific products or compilations that contain
the covered work, unless you entered into that arrangement, or that patent license
was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting any implied
license or other defenses to infringement that may otherwise be available to you
under applicable patent law.
### 12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or otherwise)
that contradict the conditions of this License, they do not excuse you from the
conditions of this License. If you cannot convey a covered work so as to satisfy
simultaneously your obligations under this License and any other pertinent
obligations, then as a consequence you may not convey it at all. For example, if you
agree to terms that obligate you to collect a royalty for further conveying from
those to whom you convey the Program, the only way you could satisfy both those terms
and this License would be to refrain entirely from conveying the Program.
### 13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have permission to link or
combine any covered work with a work licensed under version 3 of the GNU Affero
General Public License into a single combined work, and to convey the resulting work.
The terms of this License will continue to apply to the part which is the covered
work, but the special requirements of the GNU Affero General Public License, section
13, concerning interaction through a network will apply to the combination as such.
### 14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of the GNU
General Public License from time to time. Such new versions will be similar in spirit
to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies that
a certain numbered version of the GNU General Public License “or any later
version” applies to it, you have the option of following the terms and
conditions either of that numbered version or of any later version published by the
Free Software Foundation. If the Program does not specify a version number of the GNU
General Public License, you may choose any version ever published by the Free
Software Foundation.
If the Program specifies that a proxy can decide which future versions of the GNU
General Public License can be used, that proxy's public statement of acceptance of a
version permanently authorizes you to choose that version for the Program.
Later license versions may give you additional or different permissions. However, no
additional obligations are imposed on any author or copyright holder as a result of
your choosing to follow a later version.
### 15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE
QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
### 16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY
COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS
PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE
OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
### 17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided above cannot be
given local legal effect according to their terms, reviewing courts shall apply local
law that most closely approximates an absolute waiver of all civil liability in
connection with the Program, unless a warranty or assumption of liability accompanies
a copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
## How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible use to
the public, the best way to achieve this is to make it free software which everyone
can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them
to the start of each source file to most effectively state the exclusion of warranty;
and each file should have at least the “copyright” line and a pointer to
where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short notice like this
when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type 'show c' for details.
The hypothetical commands 'show w' and 'show c' should show the appropriate parts of
the General Public License. Of course, your program's commands might be different;
for a GUI interface, you would use an “about box”.
You should also get your employer (if you work as a programmer) or school, if any, to
sign a “copyright disclaimer” for the program, if necessary. For more
information on this, and how to apply and follow the GNU GPL, see
<>.
The GNU General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may consider it
more useful to permit linking proprietary applications with the library. If this is
what you want to do, use the GNU Lesser General Public License instead of this
License. But first, please read
<>.
================================================
FILE: README.md
================================================
# JavaScript Toolchain on EOS
FIBOS is a JavaScript runtime that combines EOS and fibjs. It provides programmability to eos and allows the use of JavaScript to write smart contracts.
## Community
* website: https://fibos.io
* telegram: https://t.me/FIBOSIO
* twitter: https://twitter.com/fibos_io
* medium: https://medium.com/@fibosio
* issue: https://github.com/fibosio/fibos/issues
================================================
FILE: fibos_build
================================================
#!/bin/bash
usage()
{
echo ""
echo "Usage: `basename $0` [options] [-jn] [-v] [-h]"
echo "Options:"
echo " release, debug: "
echo " Specifies the build type."
echo " clean: "
echo " Clean the build folder."
echo " -h, --help:"
echo " Print this message and exit."
echo ""
exit 0
}
HOST_OS=`uname`
HOST_ARCH=`uname -m`
case ${HOST_ARCH} in
i386|i686) HOST_ARCH="i386"
;;
x86_64|amd64) HOST_ARCH="amd64"
;;
armv6|armv7|armv7s|armv7l) HOST_ARCH="arm"
;;
aarch64) HOST_ARCH="arm64"
;;
mips|mipsel) HOST_ARCH="mips"
;;
mips64) HOST_ARCH="mips64"
;;
powerpc) HOST_ARCH="ppc"
;;
ppc64) HOST_ARCH="ppc64"
;;
esac
TARGET_OS=$HOST_OS
TARGET_ARCH=$HOST_ARCH
BUILD_TYPE="release"
for i in "$@"
do
case $i in
release|debug|clean) BUILD_TYPE=$i
;;
ci) CI="ci"
;;
-j*) ENABLE_JOBS=1; BUILD_JOBS="${i#-j}"
;;
--help|-h) usage
;;
*) echo "illegal option $i"
usage
;;
esac
done
if [ "$ENABLE_JOBS" = "1" -a "$BUILD_JOBS" = "" ]; then
#get cpu core count
CPU_CORE=1
case ${HOST_OS} in
Darwin)
CPU_CORE=$(sysctl hw.ncpu | awk '{print $2}')
;;
Linux)
CPU_CORE=$(cat /proc/cpuinfo | grep processor | wc -l)
;;
Windows)
CPU_CORE=$(echo $NUMBER_OF_PROCESSORS)
;;
esac
echo "host machine has ${CPU_CORE} core"
if [ "$CPU_CORE" = "1" ]; then
BUILD_JOBS=""
else
# set build jobs with cpu core count
BUILD_JOBS=${CPU_CORE}
fi
fi
FIBOS_PATH=`pwd`
OUT_PATH=${FIBOS_PATH}/out
BIN_ROOT=${FIBOS_PATH}/bin
BIN_PATH=${FIBOS_PATH}/bin/${TARGET_OS}_${TARGET_ARCH}_${BUILD_TYPE}
if [ ${BUILD_TYPE} = 'clean' ]; then
if [ -e "${OUT_PATH}" ]; then
rm -rf ${OUT_PATH}
fi
if [ -e "${BIN_ROOT}" ]; then
rm -rf ${BIN_ROOT}
fi
exit 0
fi
cd eos
sed "s/\.git/docs/g;" eosio_build.sh | sh
# sed "s/\.git/docs/g;s/=Release/=Debug/g" eosio_build.sh | sh
if [ $? != 0 ]; then
exit 1
fi
cd ..
cd fibjs
if [ ! "$BUILD_JOBS" = "" ]; then
sh build -j${BUILD_JOBS}
else
sh build -j
fi
if [ $? != 0 ]; then
exit 1
fi
cd ..
if [ ! -e "${OUT_PATH}" ]; then
mkdir "${OUT_PATH}"
fi
OUT_PATH=${OUT_PATH}/${TARGET_OS}_${TARGET_ARCH}_${BUILD_TYPE}
if [ ! -e ${OUT_PATH} ]; then
mkdir ${OUT_PATH}
fi
OUT_PATH=${OUT_PATH}/program
if [ ! -e ${OUT_PATH} ]; then
mkdir ${OUT_PATH}
fi
cd ${OUT_PATH}
cmake -DBUILD_TYPE=${BUILD_TYPE} -DBUILD_OPTION="${BUILD_OPTION}" ${FIBOS_PATH} > CMake.log
if [ $? != 0 ]; then
exit 1
fi
if [ ! "$BUILD_JOBS" = "" ]; then
sh -c "${BUILD_VERBOSE} make -j${BUILD_JOBS}"
else
sh -c "${BUILD_VERBOSE} make"
fi
if [ $? != 0 ]; then
exit 1
fi
if [ "${BUILD_TYPE}" = "release" ]; then
cd "${BIN_PATH}"
cp "${FIBOS_PATH}/installer.txt" "installer.sh"
tar -zcf fibos.tar.gz fibos
echo '[100%] Built target fibos.tar.gz'
cat fibos.tar.gz >> installer.sh
chmod 777 installer.sh
echo '[100%] Built target install.sh'
if [ $TARGET_OS = "Linux" ]; then
echo ''
echo '==== GLIBC ===='
objdump fibos -p | grep GLIBC_[0-9.]* -o | sort | uniq
fi
if [ "${CI}" = "ci" ]; then
xz -cz -T2 fibos > fibos.xz
echo '[100%] Built target fibos.xz'
fi
fi
cd "${FIBOS_PATH}"
txtbld=$(tput bold)
bldred=${txtbld}$(tput setaf 1)
txtrst=$(tput sgr0)
printf "\n\n${bldred}"
printf "\t _______ _________ ______ _______ _______\n"
printf "\t( ____ \\\\\\__ __/( ___ \\ ( ___ )( ____ \\\\\n"
printf "\t| ( \\/ ) ( | ( ) )| ( ) || ( \\/\n"
printf "\t| (__ | | | (__/ / | | | || (_____ \n"
printf "\t| __) | | | __ ( | | | |(_____ )\n"
printf "\t| ( | | | ( \\ \\ | | | | ) |\n"
printf "\t| (_ ___) (___| (___) )| (___) |/\\____) |\n"
printf "\t(__/ \\_______/(______/ (_______)\\_______)\n"
printf "${txtrst}"
printf "\\n\\tFIBOS has been successfully built.\\n\\n"
printf "\\tFor more information:\\n\\n"
printf "\\tFIBOS website: http://fibos.io\\n"
================================================
FILE: idl/zh-cn/DBIterator.idl
================================================
/*! @brief
multi index DBIterator 对象
*/
interface DBIterator : object
{
/*! @brief 判断数据是否为首数据
实例:
```JavaScript
exports.hi1 = v => {
var players = db.players(action.account, action.account);
var itr = players.find(v);
console.log(itr.is_begin());
};
```
*/
Boolean is_begin();
/*! @brief 判断数据是否为尾数据
实例:
```JavaScript
exports.hi1 = v => {
var players = db.players(action.account, action.account);
var itr = players.find(v);
console.log(itr.is_end());
};
```
*/
Boolean is_end();
/*! @brief 获取下一个数据
实例:
```JavaScript
exports.hi1 = v => {
var players = db.players(action.account, action.account);
var itr = players.find(v);
var itr1 = itr.next();
console.log(itr1.toJSON());
};
```
*/
DBIterator next();
/*! @brief 获取上一个数据
实例:
```JavaScript
exports.hi1 = v => {
var players = db.players(action.account, action.account);
var itr = players.find(v);
var itr1 = itr.next();
var itr2 = itr1.previous();
console.log(itr2.toJSON());
};
```
*/
DBIterator previous();
/*! @brief 删除数据
实例:
```JavaScript
exports.hi1 = v => {
var players = db.players(action.account, action.account);
var itr = players.find(v);
itr.remove();
};
```
*/
remove();
/*! @brief 更新数据
实例:
```JavaScript
exports.hi1 = v => {
var players = db.players(action.account, action.account);
var itr = players.find(v);
itr.data.age = 18;
itr.update(action.account);
};
```
@param payer 为此次操作支付 RAM 的账户
*/
update(String payer);
/*! @brief 查询当前数据,返回所有数据对象,每个数据是一个新的 DBIterator 对象 */
readonly Object data;
};
================================================
FILE: idl/zh-cn/Table.idl
================================================
/*! @brief
multi index table 对象
*/
interface Table : object
{
/*! @brief table 名
*/
readonly String name;
/*! @brief 指向合约发布者的名称
*/
readonly String code;
/*! @brief table 中数据所属的 account_name
*/
readonly String scope;
/*! @brief 向 table 存入新数据
实例:
```JavaScript
exports.hi = v => {
var players = db.players(action.account, action.account);
players.emplace(action.account, {
title: "ceo",
age:48,
nickname:"lion1",
id:123
});
};
```
@param payer 为此次操作付费的账户
@param val 将要存入到 table 的值
*/
emplace(String payer, Object val);
/*! @brief 从 table 查找数据
实例:
```JavaScript
exports.hi = v => {
var players = db.players(action.account, action.account);
console.log(players.find(v).data)
};
```
@param id 查询的参数
*/
DBIterator find(Value id);
/*! @brief 生成自增主键
实例:
```JavaScript
exports.hi = v => {
var players = db.players(action.account, action.account);
console.log(players.get_primary_key())
};
```
*/
Value get_primary_key();
/*! @brief 获取 Table 的 begin
实例:
```JavaScript
exports.hi = v => {
var players = db.players(action.account, action.account);
console.log(players.begin())
};
```
*/
DBIterator begin();
/*! @brief 获取 Table 的 end
实例:
```JavaScript
exports.hi = v => {
var players = db.players(action.account, action.account);
console.log(players.end().is_end(), players.end().previous().data);
};
```
*/
DBIterator end();
/*! @brief 从 table 查找小于参数结果
实例:
```JavaScript
exports.hi1 = v => {
var players = db.players1(action.account, action.account);
var data = players.lowerbound(123);
console.log(data.data, data1.data);
};
```
@param id 查询的参数
*/
DBIterator lowerbound(Value id);
/*! @brief 从 table 查找大于参数结果
实例:
```JavaScript
exports.hi1 = v => {
var players = db.players1(action.account, action.account);
var data1 = players.upperbound(123);
console.log(data.data, data1.data);
};
```
@param id 查询的参数
*/
DBIterator upperbound(Value id);
/*! @brief 查询当前索引,返回所有索引对象,每个索引是一个新的 Table 对象 */
readonly Object indexes;
};
================================================
FILE: idl/zh-cn/action.idl
================================================
/*! @brief action 对象
使用方法:在 fibos 的 js 合约中使用
```JavaScript
var js_code = `exports.hi = v => console.error(action.is_account(action.account), action.is_account("notexists"));`;
fibos.setcodeSync(name, 0, 0, fibos.compileCode(js_code));
```
*/
module action {
/*! @brief action 名称
实例:
```JavaScript
exports.hi = v => {
console.log(action.name)
};
```
*/
static readonly String name;
/*! @brief action 发送者的账户名
实例:
```JavaScript
exports.hi = v => {
console.log(action.account)
};
```
*/
static readonly String account;
/*! @brief action 接收者
实例:
```JavaScript
exports.hi = v => {
console.log(action.receiver)
};
```
*/
static readonly String receiver;
/*! @brief 返回从1970年1月1日0时0分0秒(UTC,即协调世界时)距离出块时间的毫秒数。
实例:
```JavaScript
exports.hi = v => {
console.log(action.publication_time)
};
```
*/
static readonly Long publication_time;
/*! @brief 执行该 action 需要得到数组中所有账户的授权
实例:
```JavaScript
exports.hi = v => {
console.log(action.authorization)
};
```
*/
static readonly Array authorization;
/*! @brief 该 action 所在 transaction 的哈希 id
实例:
```JavaScript
exports.hi = v => {
console.log(action.id)
};
```
*/
static readonly String id;
/*! @brief 判断账户是否存在
实例:
```JavaScript
exports.hi = v => {
if(action.is_account(account)) console.notice("account exists");
else console.error("account notexists")
};
```
@param name 账户名
@return 账户存在则返回 true,不存在返回 false
*/
static Boolean is_account(String name);
/*! @brief action 执行成后,名为 name 的账号是否会收到通知
实例:
```JavaScript
exports.hi = v => {
if(action.has_recipient(receiver)) console.notice("action received")
else console.error("action not received");
};
```
@param name 账户名
@return 若名为 name 的账户会收到通知则返回 true,否则返回 false
*/
static Boolean has_recipient(String name);
/*! @brief 向通知列表增加特定账号
实例:
```JavaScript
exports.hi = v => {
action.require_recipient(action.receiver);
};
```
@param name 账户名
*/
static require_recipient(String name);
/*! @brief 验证 action 是否需要特定账户的授权
实例:
```JavaScript
exports.hi = v => {
if(action.has_auth(account)) console.notice("action be authed")
};
```
@param name 待验证的账号名
@return 需要该账户授权则返回 true,否则返回 false
*/
static Boolean has_auth(String name);
/*! @brief 向 action 的授权列表中添加特定账户及对应的权限,若添加失败则会抛出异常
实例:
```JavaScript
exports.hi = v => {
if(action.require_auth(account)) console.notice("auth success")
};
```
@param name 待验证的账号名
@param permission 需要该账户授权的权限
*/
static require_auth(String name, String permission = "");
};
================================================
FILE: idl/zh-cn/bc_buffer.idl
================================================
/*! @brief 二进制数据缓存对象,用于 io 读写的数据处理
Buffer 对象为全局基础类,在任何时候都可以直接以 new Buffer(...) 创建:
```JavaScript
var buf = new Buffer();
```
*/
interface bc_buffer
{
/*! @brief 缓存对象构造函数
```JavaScript
exports.hi = v => {
var buf = new Buffer([0x31, 0x32, 0x33, 0x34])
console.log(buf.toString());
}
```
@param datas 初始化数据数组
*/
Buffer(Array datas);
/*! @brief 缓存对象构造函数
```JavaScript
exports.hi = v => {
var arr = new Uint16Array(2);
arr[0] = 5000;
arr[1] = 4000;
var buf = new Buffer(arr.buffer);
console.log(buf.hex());
}
```
@param datas 初始化数据数组
*/
Buffer(ArrayBuffer datas);
/*! @brief 缓存对象构造函数
```JavaScript
exports.hi = v => {
var arr = new Uint8Array(2);
arr[0] = 50;
arr[1] = 40;
var buf = new Buffer(arr);
console.log(buf.hex());
var arr = new Uint16Array(2);
arr[0] = 5000;
arr[1] = 4000;
var buf = new Buffer(arr);
console.log(buf.hex());
var arr = new Uint8Array([0x10, 0x20, 0x30]);
var arr1 = new Uint8Array(arr.buffer, 1, 2);
var buf = new Buffer(arr1);
console.log(buf.hex());
}
```
@param datas 初始化数据数组
*/
Buffer(TypedArray datas);
/*! @brief 缓存对象构造函数
```JavaScript
exports.hi = v => {
var arr = new DataView(new ArrayBuffer(2));
arr.setInt8(0, 0x10);
arr.setInt8(1, 0x20);
var buf = new Buffer(arr);
console.log(buf.hex());
}
```
@param datas 初始化数据数组
*/
Buffer(ArrayBufferView datas);
/*! @brief 缓存对象构造函数
```JavaScript
exports.hi = v => {
var buf = new Buffer(new Buffer("abcd"));
console.log(buf.toString());
}
```
@param buffer 初始化Buffer对象
*/
Buffer(Buffer buffer);
/*! @brief 缓存对象构造函数
```JavaScript
exports.hi = v => {
var buf = new Buffer("abcd","utf8");
console.log(buf.toString());
}
```
@param str 初始化字符串,字符串将以 utf-8 格式写入,缺省则创建一个空对象
@param codec 指定编码格式,允许值为:"hex", "base64", "utf8", 或者系统支持的字符集
*/
Buffer(String str, String codec = "utf8");
/*! @brief 缓存对象构造函数
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer(100);
console.log(buf.length);
}
```
@param size 初始化缓冲区大小
*/
Buffer(Integer size = 0);
/*! @brief 检测给定的变量是否是 Buffer 对象
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer("abcd");
var str = "abcd"
console.log(Buffer.isBuffer(buf));
console.log(Buffer.isBuffer(str));
}
```
@param v 给定需要检测的变量
@return 传入对象是否 Buffer 对象
*/
static Boolean isBuffer(Value v);
/*! @brief 通过其他 Buffer 创建 Buffer 对象
实例:
```JavaScript
exports.hi = v => {
var buf = Buffer.from(new Buffer("abcd"), 1, 2);
console.log(buf.toString());
}
```
@param buffer 给定 Buffer 类型变量用于创建 Buffer 对象
@param byteOffset 指定数据起始位置,起始为 0
@param length 指定数据长度,起始位 -1,表示剩余所有数据
@return 返回 Buffer 实例
*/
static Buffer from(Buffer buffer, Integer byteOffset = 0, Integer length = -1);
/*! @brief 通过字符串创建 Buffer 对象
实例:
```JavaScript
exports.hi = v => {
var buf = Buffer.from("abcd",0,2);
console.log(buf.toString());
}
```
@param str 初始化字符串,字符串将以 utf-8 格式写入
@param byteOffset 指定数据起始位置,起始为 0
@param length 指定数据长度,起始位 -1,表示剩余所有数据
@return 返回 Buffer 实例
*/
static Buffer from(String str, Integer byteOffset = 0, Integer length = -1);
/*! @brief 通过字符串创建 Buffer 对象
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer("厉害!","utf8");
console.log(buf.toString());
}
```
@param str 初始化字符串,字符串将以 utf-8 格式写入,缺省则创建一个空对象
@param codec 指定编码格式,允许值为:"hex", "base64", "utf8", 或者系统支持的字符集
@return 返回 Buffer 实例
*/
static Buffer from(String str, String codec = "utf8");
/*! @brief 拼接多个缓存区中的数据
实例:
```JavaScript
exports.hi = v => {
var buf1 = new Buffer("abcd");
var buf2 = new Buffer("efg");
var buf3 = new Buffer();
var bufArray = [buf1];
var bufRes = Buffer.concat(bufArray);
console.log(bufRes.toString());
bufArray = [buf1, buf2];
bufRes = Buffer.concat(bufArray);
console.log(bufRes.toString());
bufRes = Buffer.concat(bufArray, 6);
console.log(bufRes.toString());
buf1 = new Buffer([0x31, 0x32, 0x33, 0x34]);
buf2 = new Buffer([0x35, 0x36, 0x37, 0x38]);
bufArray = [buf1, buf2];
bufRes = Buffer.concat(bufArray);
console.log(bufRes.toString());
var buf2 = Buffer.concat([]);
console.log(buf2.length);
}
```
@param buflist 待拼接的Buffer数组
@param cutLength 截取多少个Buffer对象
@return 拼接后产生的新 Buffer 对象
*/
static Buffer concat(Array buflist, Integer cutLength = -1);
/*! @brief 分配一个指定长度的新缓存区。如果大小为0,将创建一个零长度的缓存区。
实例:
```JavaScript
exports.hi = v => {
var buf1 = Buffer.alloc(10, 0,"utf8");
console.log(buf1.toString());
}
```
@param size 缓冲区的所需长度
@param fill 预先填充新缓冲区的值,可使用 string/buffer/integer 值类型。 默认值:0
@param codec 指定编码格式,允许值为:"hex", "base64", "utf8", 或者系统支持的字符集
@return 填充好的新 Buffer 对象
*/
static Buffer alloc(Integer size, Integer fill = 0, String codec = "utf8");
/*! @brief 分配一个指定长度的新缓存区。如果大小为0,将创建一个零长度的缓存区。
实例:
```JavaScript
exports.hi = v => {
var buf1 = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');
var buf2 = Buffer.alloc(16, 'aGVsbG8gd29ybGQ=', 'base64');
console.log(buf1.toString());
console.log(buf2.toString());
}
```
@param size 缓冲区的所需长度
@param fill 预先填充新缓冲区的值,可使用 string/buffer/integer 值类型。 默认值:0
@param codec 指定编码格式,允许值为:"hex", "base64", "utf8", 或者系统支持的字符集
@return 填充好的新 Buffer 对象
*/
static Buffer alloc(Integer size, String fill = "", String codec = "utf8");
/*! @brief 分配一个指定长度的新缓存区。如果大小为0,将创建一个零长度的缓存区。
实例:
```JavaScript
exports.hi = v => {
var buf1 = Buffer.alloc(11, new Buffer('aGVsbG8gd29ybGQ='), 'base64');
var buf2 = Buffer.alloc(16, new Buffer('aGVsbG8gd29ybGQ='), 'base64');
console.log(buf1.toString());
console.log(buf2.toString());
}
```
@param size 缓冲区的所需长度
@param fill 预先填充新缓冲区的值,可使用 string/buffer/integer 值类型。 默认值:0
@param codec 指定编码格式,允许值为:"hex", "base64", "utf8", 或者系统支持的字符集
@return 填充好的新 Buffer 对象
*/
static Buffer alloc(Integer size, Buffer fill, String codec = "utf8");
/*! @brief 分配一个指定长度的新缓存区。如果大小为0,将创建一个零长度的缓存区。
实例:
```JavaScript
exports.hi = v => {
var buf1 = Buffer.allocUnsafe(10);
console.log(buf1.length);
}
```
@param size 缓冲区的所需长度
@return 指定尺寸的新 Buffer 对象
*/
static Buffer allocUnsafe(Integer size);
/*! @brief 分配一个指定长度的新缓存区。如果大小为0,将创建一个零长度的缓存区。
实例:
```JavaScript
exports.hi = v => {
var buf1 = Buffer.allocUnsafeSlow(10);
console.log(buf1.length);
}
```
@param size 缓冲区的所需长度
@return 指定尺寸的新 Buffer 对象
*/
static Buffer allocUnsafeSlow(Integer size);
/*! @brief 检测编码格式是否被支持
实例:
```JavaScript
exports.hi = v => {
console.log(Buffer.isEncoding('utf8')); // true
console.log(Buffer.isEncoding('utf-8')); // true
console.log(Buffer.isEncoding('gbk')); // false
console.log(Buffer.isEncoding('gb2312')); // false
console.log(Buffer.isEncoding('hex')); // true
console.log(Buffer.isEncoding('base64')); // true
console.log(Buffer.isEncoding('jis')); // false
console.log(Buffer.isEncoding('aaabbbccc')); // false
console.log(Buffer.isEncoding('binary')); // false
console.log(Buffer.isEncoding('latin1')); // false
console.log(Buffer.isEncoding('big5')); // false
}
```
@param codec 待检测的编码格式
@return 是否支持
*/
static Boolean isEncoding(String codec);
/*! @brief 获取缓存对象的尺寸 */
readonly Integer length;
/*! @brief 修改缓存对象尺寸
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer("abcded");
buf.resize(10);
console.log(buf);
}
```
@param sz 指定新尺寸
*/
resize(Integer sz);
/*! @brief 在缓存对象尾部写入一组二进制数据
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer([0x31, 0x32, 0x33, 0x34]);
buf.append("abcd");
buf.append([0x31, 0x32, 0x33, 0x34]);
console.log(buf.toString());
}
```
@param data 初始化二进制数据
*/
append(Buffer data);
/*! @brief 在缓存对象尾部写入字符串,字符串将以 utf-8 格式写入
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer([0x31, 0x32, 0x33, 0x34]);
buf.append("3132", "hex");
buf.append("MTIzNA==", "base64");
console.log(buf.toString());
}
```
@param str 要写入的字符串
@param codec 指定编码格式,允许值为:"hex", "base64", "utf8", 或者系统支持的字符集
*/
append(String str, String codec = "utf8");
/*! @brief 向缓存对象写入指定字符串,字符串默认为utf-8,越界时只写入部分数据
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer(10);
buf.write("abcd", 0, 4,'utf8')
console.log(buf.toString('utf8', 0, 4));
}
```
@param str 待写入的字符串
@param offset 写入起始位置
@param length 写入长度(单位字节,默认值-1),未指定时为待写入字符串的长度
@param codec 指定编码格式,允许值为:"hex", "base64", "utf8", 或者系统支持的字符集
@return 写入的数据字节长度
*/
Integer write(String str, Integer offset = 0, Integer length = -1, String codec = "utf8");
/*! @brief 向缓存对象写入指定字符串,字符串默认为utf-8,越界时只写入部分数据
实例:
```JavaScript
exports.hi = v => {
buf = new Buffer(10);
buf.write("MTIzNA==", 0, "base64");
console.log(buf.toString("utf8", 0, 4));
}
```
@param str 待写入的字符串
@param offset 写入起始位置
@param codec 指定编码格式,允许值为:"hex", "base64", "utf8", 或者系统支持的字符集
@return 写入的数据字节长度
*/
Integer write(String str, Integer offset = 0, String codec = "utf8");
/*! @brief 向缓存对象写入指定字符串,字符串默认为utf-8,越界时只写入部分数据
实例:
```JavaScript
exports.hi = v => {
buf = new Buffer(10);
buf.write("MTIzNA==", "base64");
console.log(buf.toString("utf8"));
}
```
@param str 待写入的字符串
@param codec 指定编码格式,允许值为:"hex", "base64", "utf8", 或者系统支持的字符集
@return 写入的数据字节长度
*/
Integer write(String str, String codec = "utf8");
/*! @brief 为 Buffer 对象填充指定内容数据
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer(10);
buf.fill(1);
console.log(buf.toString());
}
```
@param v 需要填充的数据,如果未指定 offset 和 end,将填充满整个 buffer
@param offset 填充起始位置
@param end 填充终止位置
@return 返回当前 Buffer 对象
*/
Buffer fill(Integer v, Integer offset = 0, Integer end = -1);
/*! @brief 为 Buffer 对象填充指定内容数据
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer(10);
buf.fill(new Buffer("abc"));
console.log(buf.toString());
}
```
@param v 需要填充的数据,如果未指定 offset 和 end,将填充满整个 buffer
@param offset 填充起始位置
@param end 填充终止位置
@return 返回当前 Buffer 对象
*/
Buffer fill(Buffer v, Integer offset = 0, Integer end = -1);
/*! @brief 为 Buffer 对象填充指定内容数据
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer(10);
buf.fill("abc");
console.log(buf.toString());
}
```
@param v 需要填充的数据,如果未指定 offset 和 end,将填充满整个 buffer
@param offset 填充起始位置
@param end 填充终止位置
@return 返回当前 Buffer 对象
*/
Buffer fill(String v, Integer offset = 0, Integer end = -1);
/*! @brief 返回某个指定数据在 Buffer 中首次出现的位置
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer([0x31, 0x32, 0x33, 0x34, 0x00]);
console.log(buf.indexOf(0x33));
console.log(buf.indexOf(0x00));
}
```
@param v 待查找数据,如果未指定 offset,默认从起始位开始
@param offset 起始查找位置
@return 返回查找到的位置,未找到返回 -1
*/
Integer indexOf(Integer v, Integer offset = 0);
/*! @brief 返回某个指定数据在 Buffer 中首次出现的位置
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer("cacdbfcde");
console.log(buf.indexOf("cd", 1));
}
```
@param v 待查找数据,如果未指定 offset,默认从起始位开始
@param offset 起始查找位置
@return 返回查找到的位置,未找到返回 -1
*/
Integer indexOf(String v, Integer offset = 0);
/*! @brief 比较缓存区的内容
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer("abcd");
console.log(buf.compare(new Buffer("abcd")));
console.log(buf.compare(new Buffer("abc")));
console.log(buf.compare(new Buffer("abcde")));
}
```
@param buf 待比较缓存对象
@return 内容比较结果
*/
Integer compare(Buffer buf);
/*! @brief 从源缓存对象区域拷贝数据到目标缓存对象区域
实例:
```JavaScript
exports.hi = v => {
var buf1 = new Buffer([0x31, 0x32, 0x33]);
var arr = [0x34, 0x35, 0x36];
var buf2 = new Buffer(arr);
var sz = buf1.copy(buf2);
console.log(sz);
console.log(buf2.toString());
}
```
@param targetBuffer 目标缓存对象
@param targetStart 目标缓存对象开始拷贝字节位置,缺省为 0
@param sourceStart 源缓存对象开始字节位置, 缺省为 0
@param sourceEnd 源缓存对象结束字节位置, 缺省为 -1,表示源数据长度
@return 拷贝的数据字节长度
*/
Integer copy(Buffer targetBuffer, Integer targetStart = 0, Integer sourceStart = 0, Integer sourceEnd = -1);
/*! @brief 返回一个新缓存对象,包含指定起始到缓存结尾的数据
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer(10);
buf.write("abcdefghih");
console.log(buf.slice(8).toString());
}
```
@param start 指定范围的起始,缺省从头开始
@return 返回新的缓存对象
*/
Buffer slice(Integer start = 0);
/*! @brief 返回一个新缓存对象,包含指定范围的数据,若范围超出缓存,则只返回有效部分数据
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer(10);
buf.write("abcdefghih");
console.log(buf.slice(0, 3).toString());
console.log(buf.slice(0, 11).toString());
}
```
@param start 指定范围的起始
@param end 指定范围的结束
@return 返回新的缓存对象
*/
Buffer slice(Integer start, Integer end);
/*! @brief 把当前对象中的所有元素放入一个字符串
实例:
```JavaScript
exports.hi = v => {
var a = new Buffer([192, 168, 0, 1]);
console.log(a.join('.'));
}
```
@param separator 分割字符,缺省为 ","
@return 返回生成的字符串
*/
String join(String separator = ",");
/*! @brief 返回一个新缓存对象,包含当前对象数据的倒序
实例:
```JavaScript
exports.hi = v => {
var a = new Buffer("abcd");
console.log(a.reverse().toString());
}
```
@return 返回新的缓存对象
*/
Buffer reverse();
/*! @brief 比较当前对象与给定的对象是否相等
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer("abcd");
console.log(buf.equals(new Buffer("abcd")));
console.log(buf.equals(new Buffer("abc")));
}
```
@param expected 制定比较的目标对象
@return 返回对象比较的结果
*/
Boolean equals(object expected);
/*! @brief 使用 16 进制编码缓存对象内容
@return 返回编码字符串
*/
String hex();
/*! @brief 使用 base64 编码缓存对象内容
@return 返回编码字符串
*/
String base64();
/*! @brief 返回全部二进制数据的数组
@return 返回包含对象数据索引的迭代器
*/
Iterator keys();
/*! @brief 返回全部二进制数据的数组
@return 返回包含对象数据值的迭代器
*/
Iterator values();
/*! @brief 返回包含对象数据 [index, byte] 对的迭代器
@return [index, byte] 对的迭代器
实例:
```JavaScript
exports.hi = v => {
const buf = Buffer.from('buffer');
// Prints:
// [0, 98]
// [1, 117]
// [2, 102]
// [3, 102]
// [4, 101]
// [5, 114]
for (const pair of buf.entries()) {
console.log(pair);
}
}
```
*/
Iterator entries();
/*! @brief 返回全部二进制数据的数组
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer("buffer");
console.log(buf.toArray());
}
```
@return 返回包含对象数据的数组
*/
Array toArray();
/*! @brief 返回二进制数据的编码字符串
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer([0x31, 0x32, 0x33, 0x34]);
console.log(buf.toString("utf8", 1, 3));
}
```
@param codec 指定编码格式,允许值为:"hex", "base64", "utf8", 或者系统支持的字符集
@param offset 读取起始位置
@param end 读取终止位置
@return 返回对象的字符串表示
*/
String toString(String codec, Integer offset = 0, Integer end);
/*! @brief 返回二进制数据的编码字符串
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer([0x31, 0x32, 0x33, 0x34]);
console.log(buf.toString("utf8", 1));
console.log(buf.toString("hex", 2));
console.log(buf.toString("base64", 2));
}
```
@param codec 指定编码格式,允许值为:"hex", "base64", "utf8", 或者系统支持的字符集
@param offset 读取起始位置
@return 返回对象的字符串表示
*/
String toString(String codec, Integer offset = 0);
/*! @brief 返回二进制数据的 utf8 编码字符串
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer([0x31, 0x32, 0x33, 0x34]);
console.log(buf.toString());
}
```
@return 返回对象的字符串表示
*/
String toString();
/*! @brief 返回对象的 JSON 格式表示,一般返回对象定义的可读属性集合
实例:
```JavaScript
exports.hi = v => {
var buf = new Buffer("buffer");
console.log(buf.toJSON());
}
```
@return 返回对象的 JSON 格式表示
*/
String toJSON();
};
================================================
FILE: idl/zh-cn/bc_console.idl
================================================
/*! @brief console 对象
控制台访问对象
全局对象。可用于提示信息,警告和错误记录。通过启动配置文件,可将日志定位到不同的设备,以便于跟踪。 */
module bc_console {
/*! @brief loglevel 级别常量 */
const FATAL = 0;
/*! @brief loglevel 级别常量 */
const ALERT = 1;
/*! @brief loglevel 级别常量 */
const CRIT = 2;
/*! @brief loglevel 级别常量 */
const ERROR = 3;
/*! @brief loglevel 级别常量 */
const WARN = 4;
/*! @brief loglevel 级别常量 */
const NOTICE = 5;
/*! @brief loglevel 级别常量 */
const INFO = 6;
/*! @brief loglevel 级别常量 */
const DEBUG = 7;
/*! @brief loglevel 仅用于输出,信息输出后不换行,file 和 syslog 不保存此级别信息 */
const PRINT = 9;
/*! @brief loglevel 级别常量 */
const NOTSET = 10;
/*! @brief 记录普通日志信息,与 info 等同
实例:
```JavaScript
exports.hi = v => {
console.log('hello :%s',"FIBOS")
};
```
记录一般等级的日志信息。通常用于输出非错误性提示信息。
@param fmt 格式化字符串
@param args 可选参数列表
*/
static log(String fmt, ...args);
/*! @brief 记录普通日志信息,与 info 等同
```JavaScript
exports.hi = v => {
console.log('hello FIBOS')
};
```
记录一般等级的日志信息。通常用于输出非错误性提示信息。
@param args 可选参数列表
*/
static log(...args);
/*! @brief 记录调试日志信息
```JavaScript
exports.hi = v => {
console.debug('warn %s','FIBOS')
};
```
记录调试日志信息。通常用于输出调试信息。不重要。
@param fmt 格式化字符串
@param args 可选参数列表
*/
static debug(String fmt, ...args);
/*! @brief 记录调试日志信息
```JavaScript
exports.hi = v => {
console.debug('warn FIBOS')
};
```
记录调试日志信息。通常用于输出调试信息。不重要。
@param args 可选参数列表
*/
static debug(...args);
/*! @brief 记录普通日志信息,与 log 等同
```JavaScript
exports.hi = v => {
console.info('hello :%s','FIBOS')
};
```
记录一般等级的日志信息。通常用于输出非错误性提示信息。
@param fmt 格式化字符串
@param args 可选参数列表
*/
static info(String fmt, ...args);
/*! @brief 记录普通日志信息,与 log 等同
```JavaScript
exports.hi = v => {
console.info('hello FIBOS')
};
```
记录一般等级的日志信息。通常用于输出非错误性提示信息。
@param args 可选参数列表
*/
static info(...args);
/*! @brief 记录警告日志信息
```JavaScript
exports.hi = v => {
console.notice('hello :%s','FIBOS')
};
```
记录警告日志信息。通常用于输出提示性调试信息。一般重要。
@param fmt 格式化字符串
@param args 可选参数列表
*/
static notice(String fmt, ...args);
/*! @brief 记录警告日志信息
```JavaScript
exports.hi = v => {
console.notice('hello FIBOS')
};
```
记录警告日志信息。通常用于输出提示性调试信息。一般重要。
@param args 可选参数列表
*/
static notice(...args);
/*! @brief 记录警告日志信息
```JavaScript
exports.hi = v => {
console.warn('hello :%s','FIBOS')
};
```
记录警告日志信息。通常用于输出警告性调试信息。重要。
@param fmt 格式化字符串
@param args 可选参数列表
*/
static warn(String fmt, ...args);
/*! @brief 记录警告日志信息
```JavaScript
exports.hi = v => {
console.warn('hello FIBOS')
};
```
记录警告日志信息。通常用于输出警告性调试信息。重要。
@param args 可选参数列表
*/
static warn(...args);
/*! @brief 记录错误日志信息
```JavaScript
exports.hi = v => {
console.error('hello %s','FIBOS')
};
```
记录用于错误日志信息。通常用于输出错误信息。非常重要。系统的出错信息也会以此等级记录。
@param fmt 格式化字符串
@param args 可选参数列表
*/
static error(String fmt, ...args);
/*! @brief 记录错误日志信息
```JavaScript
exports.hi = v => {
console.error('hello FIBOS')
};
```
记录用于错误日志信息。通常用于输出错误信息。非常重要。系统的出错信息也会以此等级记录。
@param args 可选参数列表
*/
static error(...args);
/*! @brief 记录关键错误日志信息
```JavaScript
exports.hi = v => {
console.crit('hello %s','FIBOS')
};
```
记录用于关键错误日志信息。通常用于输出关键错误信息。非常重要。
@param fmt 格式化字符串
@param args 可选参数列表
*/
static crit(String fmt, ...args);
/*! @brief 记录关键错误日志信息
```JavaScript
exports.hi = v => {
console.crit('hello FIBOS')
};
```
记录用于关键错误日志信息。通常用于输出关键错误信息。非常重要。
@param args 可选参数列表
*/
static crit(...args);
/*! @brief 记录警报错误日志信息
```JavaScript
exports.hi = v => {
console.alert('hello %s','FIBOS')
};
```
记录用于警报错误日志信息。通常用于输出警报错误信息。非常重要。为最高级别信息。
@param fmt 格式化字符串
@param args 可选参数列表
*/
static alert(String fmt, ...args);
/*! @brief 记录警报错误日志信息
```JavaScript
exports.hi = v => {
console.alert('hello FIBOS')
};
```
记录用于警报错误日志信息。通常用于输出警报错误信息。非常重要。为最高级别信息。
@param args 可选参数列表
*/
static alert(...args);
/*! @brief 用 JSON 格式输出对象
```JavaScript
exports.hi = v => {
var a = {};
console.dir(a);
};
```
@param obj 给定要显示的对象
*/
static dir(Value obj);
/*! @brief 输出当前调用堆栈
通过日志输出当前调用堆栈。
@param label 标题,缺省为空字符串。
*/
static trace(String label = "trace");
/*! @brief 断言测试,如果测试值为假,则报错
@param value 测试的数值
@param msg 报错信息
*/
static assert(Value value, String msg = "");
};
================================================
FILE: idl/zh-cn/bc_crypto.idl
================================================
/*! @brief bc_crypto 模块
加密算法模块
bc_crypto 是 FIBOS 中的加密模块,支持 SHA1 、SHA256 、SHA 512等加密算法,在 js 合约中可以直接使用。
*/
module bc_crypto
{
/*! @brief 从给定的 hash 和签名中恢复公钥
实例:
```JavaScript
exports.hi1 = sig => {
var r = crypto.sha256('I am alive');
var s = crypto.recover_key(r, sig);
console.notice(s);
}
```
@param digest 指定消息的 hash 结果
@param signature 指定的签名
@return 返回恢复的公钥
*/
static String recover_key(String digest, String signature);
/*! @brief 创建一个 SHA1 信息摘要运算对象
实例:
```JavaScript
exports.hi = v => {
var r = crypto.sha1("abcdefg");
console.error(r);
}
```
@param data 创建同时更新的二进制数据
@return 返回信息摘要结果的 hex 编码字符串
*/
static String sha1(Buffer data);
/*! @brief 创建一个 SHA256 信息摘要运算对象
实例:
```JavaScript
exports.hi = v => {
var r = crypto.sha256("abcdefg");
console.error(r);
}
```
@param data 创建同时更新的二进制数据
@return 返回信息摘要结果的 hex 编码字符串
*/
static String sha256(Buffer data);
/*! @brief 创建一个 SHA512 信息摘要运算对象
实例:
```JavaScript
exports.hi = v => {
var r = crypto.sha512("abcdefg");
console.error(r);
}
```
@param data 创建同时更新的二进制数据
@return 返回信息摘要结果的 hex 编码字符串
*/
static String sha512(Buffer data);
/*! @brief 创建一个 RIPEMD160 信息摘要运算对象
实例:
```JavaScript
exports.hi = v => {
var r = crypto.ripemd160("abcdefg");
console.error(r);
}
```
@param data 创建同时更新的二进制数据
@return 返回信息摘要结果的 hex 编码字符串
*/
static String ripemd160(Buffer data);
};
================================================
FILE: idl/zh-cn/bc_db.idl
================================================
/*! @brief db 对象
数据库访问对象
FIBOS 中 js 智能合约操作链数据库是很常见的应用场景,一个action在执行时会有上下文变量出现,包括事务机制的处理,这些内容会应用链上
分配的内存资源,而如果没有持久化技术,执行超过作用域时就会丢失掉这些上下文数据。因此要使用持久化技术将关键内容记录在链数据库中,任何时候使用都不受影响。db 模块的作用就是为了将数据持久化到数据库中,并提供数据可查询的能力和服务。*/
module bc_db {
/*! @brief 访问指定数据库表
使用 db 模块首先我们需要在 abi 文件中定义数据表的表名、表结构和主键等信息,如下所示:
```
var db_abi = {
"version": "eosio::abi/1.0",
"types": [{
"new_type_name": "my_account_name",
"type": "name"
}],
"structs": [{
"name": "player2",
"base": "",
"fields": [{
"name": "title",
"type": "string"
}, {
"name": "age",
"type": "int32"
}, {
"name": "weight",
"type": "int32"
}, {
"name": "length",
"type": "int32"
}, {
"name": "width",
"type": "int32"
}]
}, {
"name": "hi",
"base": "",
"fields": [{
"name": "user",
"type": "name"
}]
}],
"actions": [{
"name": "hi",
"type": "hi",
"ricardian_contract": ""
}],
"tables": [{
"name": "players",
"type": "player2",
"index_type": "i64",
"key_names": ["id"],
"key_types": ["int64"]
}]
};
```
在 db_abi 中定义了一个 players 表,表的类型为 player2 ,主键为 id。
那在 js 合约中如何访问某个具体的表呢?例如访问 players 表,只需要 `db.players(scope,code)` 即可。
同样给表建立索引也很简单,以 players 表为例,在 js 合约中作如下定义:
```
const indexes = {
age: [64, o => [o.age]]
};
exports.hi = v => {
var players = db.players(action.account, action.account, indexes);
}
```
上述代码定义了一个名为 age 的索引,并在访问表的时候加上 indexes 这个参数,这样在对表操作的时候就可以使用索引了。
db 模块还支持多索引,只需要在 indexes 加上其它索引,如下所示:
```
const indexes = {
age:[64, o=>[o.age]],
detail1:[128, o => [o.age,o.weight]],
detail2:[192, o => [o.age,o.weight,o.length]],
detail3:[256, o => [o.age,o.weight,o.length,o.width]]
};
```
具体如何对表进行增删改查操作请查看 DBIterator 和 Table 两篇技术手册
@param scope 指向合约发布者的名称
@param code table 中数据所属的 account_name
@param indexes 索引
*/
static table(String scope, String code,String indexes);
};
================================================
FILE: idl/zh-cn/collect.json
================================================
{
"FIBOS": ["fibos"],
"Contract": ["action", "bc_console", "bc_crypto", "bc_db", "trans"]
}
================================================
FILE: idl/zh-cn/fibos.idl
================================================
/*! @brief fibos 实例对象
使用方法:
```JavaScript
var fibos = require('fibos')
```
*/
module fibos : EventEmitter
{
/*! @brief fibos 的数据存放目录
*/
static String data_dir;
/*! @brief fibos 的配置存放目录
*/
static String config_dir;
/*! @brief fibos 主 token 名称
*/
static String core_symbol;
/*! @brief fibos 公钥前缀
*/
static String pubkey_prefix;
/*! @brief 加载系统 plugin
@param name 系统 plugin 名
@param cfg 提供给系统 plugin 的配置,[可选]
*/
static load(String name, Object cfg = {});
/*! @brief 加载配置
------
**参数详解**
### http 插件
| 配置名称 | 配置含义 | 默认值 | 参考值 |
| --------------------------- | ----------------------------------------------- | ---------------- | ------ |
| http-server-address | 本地http服务地址 | 127.0.0.1:8888 | |
| https-server-address | 本地https服务地址 | - | |
| max-body-size | RPC请求允许最大字节 | 1024*1024(bytes) | |
| verbose-http-errors | 显示Http返回的错误日志 | false | |
| http-validate-host | 验证Http请求host | true | |
| access-control-allow-origin | 对每个请求返回特殊的Access-Control-Allow-Origin | - | * |
------
### chain 插件
| 配置名称 | 配置含义 | 默认值 | 参考值 |
| ---------------------- | --------------------------------------------------- | ------ | ------------------------------------------------------------ |
| genesis-json | 指定创世块数据路径 | - | 文件路径 参考文件:[EOS TestNet](https://github.com/CryptoLions/EOS-Jungle-Testnet/blob/aa499583d5e7f19799d93ab569e29b39741d1bb4/genesis.json) [EOS MainNet](https://github.com/EOS-Mainnet/eos/blob/mainnet-1.1.3/mainnet-genesis.json) |
| genesis-timestamp | 覆盖创世块中的初试时间戳 | - | - |
| print-genesis-json | 是否打印创世数据 | false | - |
| fix-reversible-blocks | 是否将数据恢复到不可逆高度 | false | -(无法使用) |
| replay-blockchain | 是否清除状态数据然后回滚所有数据 | false | -(无法使用,猜测为命令行使用?) |
| hard-replay-blockchain | 是否清除状态数据,然后从区块日志中回滚尽可能多的数据 | false | - |
| delete-all-blocks | 是否删除所有的状态数据和区块数据 | false | - |
| truncate-at-block | 停止出块,并在该区块高度回滚 | 0 | -(无法使用) |
| 配置名称 | 配置含义 | 默认值 | 参考值 |
| ---------------------------- | ------------------------------------------------------------ | ----------- | ------ |
| blocks-dir | 区块数据存放地址 | blocks | - |
| abi-serializer-max-time-ms | 覆盖默认 ABI 序列化允许的最大时间 | 15*1000(ms) | - |
| chain-state-db-size-mb | 区块数据库中允许的最大容量 | 1024 (MB) | - |
| chain-state-db-guard-size-mb | 当区块数据库中剩余的数据小于此大小时可以安全地关闭节点 | 128(MB) | - |
| reversible-blocks-db-size-mb | 最大能够回滚的数据量 | 340(MB) | - |
| contracts-console | 是否打印合约输出 | false | - |
| read-mode | mode database contains changes done up to the head block plus changes made by transactions not yet included to the blockchain mode database contains changes done up to the current head block. | speculative | - |
------
### net 插件
| 配置名称 | 配置含义 | 默认值 | 参考值 |
| ------------------------- | -------------------------------- | --------------------------- | ------------------------------------------------------------ |
| p2p-listen-endpoint | 监听 p2p 连接的地址和端口 | 0.0.0.0:9876 | - |
| p2p-server-addrsss | 提供给其它节点 p2p 服务地址 | p2p-listen-endpoint | - |
| p2p-peer-address | 公共的p2p 对等节点地址 | - | FIBOS TestNet [ 103.80.170.107:9876] |
| p2p-max-nodes-per-host | 单个 IP 能够连接的最大客户端数量 | 1 | - |
| allowed-connection | 允许连接 | any | 'any'/'producers'/'specified'/'none'。如果'specified',则必须至少指定一次对等密钥。如果只有'producers',则不需要对等密钥。 |
| peer-private-key | 一个 公钥、私钥组成的数组 | | |
| max-clients | 允许连接客户端的最大数量 | 25 | 0: 无限制 |
| connection-cleanup-period | 清除不可用链接周期 | 30(s) | - |
| network-version-match | 是否需要相同版本的网络 | false | - |
| peer-log-format | 节点日志格式化 | ["${name}" ${_ip}:${_port}] | - |
------
### chain_api 插件
> 提供 RPC 请求
| api | 请求 | 含义 | 参数 | 参考请求 |
| --------------------- | ---- | ------------------------ | ----------------------------- | ------------------------------------------------------------ |
| get_info | GET | 获取与节点相关的最新信息 | - | curl |
| get_block | POST | 获取一个块的信息 | block_num_or_id: 区块高度或id | curl -X POST -d '{"block_num_or_id":1}' |
| get_account | POST | 获取账户的信息 | account_name:账户名称 | curl -X POST -d '{"account_name":"eosio"}' |
| get_code | POST | 获取智能合约代码 | account_name:合约名称 | curl -X POST -d |
------
### producer 插件
| 配置名称 | 配置含义 | 默认值 | 参考值 |
| -------------------------- | ----------------------------- | ------ | ------------- |
| max-transaction-time | 事务最大超时时间 | 30(s) | - |
| greylist-account | 无法使用 CPU 和 NET 的账号 | - | - |
| enable-stale-production | 启用产生区块,即使区块是静止的 | | |
| max-irreversible-block-age | 最大的不可逆块时间 | -1 | >1 |
| producer-name | 控制节点出块的账户名 | | eosio(可多参) |
| private-key | 签名程序的公钥、私钥 | | (可多参数) |
------
### bnet 插件
| 配置名称 | 配置含义 | 默认值 | 参考值 |
| ------------------------ | ------------------------------------------------------------ | ------------ | ------ |
| bnet-endpoint: | 所监听的传入链接的端点 | 0.0.0.0:4321 | |
| bnet-follow-irreversible | 是否只接受从其他端点的不可逆的块 | false | |
| bnet-threads | 用于处理网络消息的线程数 | | |
| bnet-connect | 其他节点的远程端点连接; 根据需要使用多个bnet-connect选项来组成网络 | | |
| bnet-no-trx | 这个peer请求其他节点没有pending的transactions | false | false |
@param cfgs 配置对象
*/
static load(Object cfgs);
/*! @brief 启动 fibos
### 实例
#### bp节点
```JavaScript
var fibos = require('fibos');
var fs = require("fs");
var isInit = false;
var producername = '';
var p2p_peer_address =["p2p-mainnet.fibos123.com:9977",
"seed.fibos.rocks:10100",
"p2p.foshenzhenbp:9877",
"p2p.eoschina.me:10300",
"p2p.mainnet.fibos.me:80",
"fibos-node.slowmist.io:9870",
"se-p2p.fibos.io:9870",
"sl-p2p.fibos.io:9870",
"to-p2p.fibos.io:9870",
"ca-p2p.fibos.io:9870",
"ln-p2p.fibos.io:9870",
"va-p2p.fibos.io:9870"];
console.notice("start FIBOS producer nodes");
fibos.config_dir = "./";
fibos.data_dir = "/blockData";
console.notice("config_dir:", fibos.config_dir);
console.notice("data_dir:", fibos.data_dir);
fibos.load("net", {
"p2p-peer-address": p2p_peer_address,
"p2p-listen-endpoint": "0.0.0.0:9870"
});
fibos.load("producer", {
'producer-name': producername,
'enable-stale-production': true,
'private-key': [active_publickey, active_privateKey]
});
fibos.load("chain",{
// "contracts-console": true,
'chain-state-db-size-mb': 8 * 1024,
'genesis-json': 'genesis.json'
});
//禁止js合约
fibos.enableJSContract = false;
fibos.start();
```
#### 同步节点
```JavaScript
var fibos = require('fibos');
var fs = require("fs");
var producername = '';
var p2p_peer_address = ["p2p-mainnet.fibos123.com:9977",
"seed.fibos.rocks:10100",
"p2p.foshenzhenbp:9877",
"p2p.eoschina.me:10300",
"p2p.mainnet.fibos.me:80",
"fibos-node.slowmist.io:9870",
"se-p2p.fibos.io:9870",
"sl-p2p.fibos.io:9870",
"to-p2p.fibos.io:9870",
"ca-p2p.fibos.io:9870",
"ln-p2p.fibos.io:9870",
"va-p2p.fibos.io:9870"];
console.notice("start FIBOS ABI nodes");
fibos.config_dir = "./";
fibos.data_dir = "/blockData";
console.notice("config_dir:", fibos.config_dir);
console.notice("data_dir:", fibos.data_dir);
fibos.load("http", {
"http-server-address": "0.0.0.0:8870",
"access-control-allow-origin": "*"
});
fibos.load("net", {
"p2p-peer-address": p2p_peer_address,
"p2p-listen-endpoint": "0.0.0.0:9870"
});
fibos.load("producer");
fibos.load("chain", {
'chain-state-db-size-mb': 8 * 1024,
'genesis-json': 'genesis.json'
});
fibos.load("chain_api");
fibos.load("history");
fibos.load("history_api");
//禁止js合约
fibos.enableJSContract = false;
fibos.start();
```
##### 支持mangodb
```JavaScript
var fibos = require('fibos');
var fs = require("fs");
var producername = '';
var p2p_peer_address = ["p2p-mainnet.fibos123.com:9977",
"seed.fibos.rocks:10100",
"p2p.foshenzhenbp:9877",
"p2p.eoschina.me:10300",
"p2p.mainnet.fibos.me:80",
"fibos-node.slowmist.io:9870",
"se-p2p.fibos.io:9870",
"sl-p2p.fibos.io:9870",
"to-p2p.fibos.io:9870",
"ca-p2p.fibos.io:9870",
"ln-p2p.fibos.io:9870",
"va-p2p.fibos.io:9870"];
console.notice("start FIBOS ABI nodes");
fibos.config_dir = "./";
fibos.data_dir = "/blockData";
console.notice("config_dir:", fibos.config_dir);
console.notice("data_dir:", fibos.data_dir);
fibos.load("http", {
"http-server-address": "0.0.0.0:8870",
"access-control-allow-origin": "*"
});
fibos.load("net", {
"p2p-peer-address": p2p_peer_address,
"p2p-listen-endpoint": "0.0.0.0:9870"
});
fibos.load("producer");
fibos.load("chain", {
'chain-state-db-size-mb': 8 * 1024,
'genesis-json': 'genesis.json'
});
fibos.load("chain_api");
fibos.load("history");
fibos.load("history_api");
//禁止js合约
fibos.enableJSContract = false;
fibos.load("mongo_db", {
"mongodb-uri": "mongodb://localhost:27017/eosmain"
});
fibos.start();
```
#### genesis.json 文件
```JavaScript
{
"initial_timestamp": "2018-08-28T00:00:00.000",
"initial_key": "FO6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"initial_configuration": {
"max_block_net_usage": 1048576,
"target_block_net_usage_pct": 1000,
"max_transaction_net_usage": 524288,
"base_per_transaction_net_usage": 12,
"net_usage_leeway": 500,
"context_free_discount_net_usage_num": 20,
"context_free_discount_net_usage_den": 100,
"max_block_cpu_usage": 200000,
"target_block_cpu_usage_pct": 1000,
"max_transaction_cpu_usage": 150000,
"min_transaction_cpu_usage": 100,
"max_transaction_lifetime": 3600,
"deferred_trx_expiration_window": 600,
"max_transaction_delay": 3888000,
"max_inline_action_size": 4096,
"max_inline_action_depth": 4,
"max_authority_depth": 6
},
"initial_chain_id": "6aa7bd33b6b45192465afa3553dedb531acaaff8928cf64b70bd4c5e49b7ec6a"
}
```
*/
static start();
/*! @brief 停止 fibos
*/
static stop();
/*! @brief 查询和设置 JavaScript 智能合约状态,为 True 时支持 JavaScript 智能合约
*/
static Boolean enableJSContract;
};
================================================
FILE: idl/zh-cn/trans.idl
================================================
/*! @brief
trans 模块
*/
module trans {
/*! @brief 向特定帐号发送 inline action
实例:
```JavaScript
// hi acction
exports.hi => (user) {
// 触发hi2 action
trans.send_inline(
"test",
"hi2",
{
user:"user1",
friend:"user2"
},
[{
"actor": "${name}",
"permission": "active"
}])
};
// hi2 action
exports.hi2 = (user, friend) => {
console.log(user, friend);
}
```
@param account action 发送者的帐号名称
@param name action 名称
@param args action 附带的数据
@param authorization action 的权限
*/
static send_inline(String account, String name, Object args, Array authorization = []);
/*! @brief 向特定帐号发送 context_free inline action
实例:
```JavaScript
// hi acction
exports.hi => (user) {
// 触发hi2 action
trans.send_context_free_inline(
"test",
"hi2",
{
user:"user1",
friend:"user2"
}
);
};
// hi2 action
exports.hi2 = (user, friend) => {
console.log(user, friend);
}
```
@param account action 发送者的帐号名称
@param name action 名称
@param args action 附带的数据
*/
static send_context_free_inline(String account, String name, Object args);
};
================================================
FILE: installer.txt
================================================
#!/bin/sh
echo "This program will install fibos into /usr/local/bin."
( read l; read l ; read l; read l; exec cat ) < "$0" | sudo tar -C /usr/local/bin/ -zxf - fibos
exit
================================================
FILE: src/fibos.cpp
================================================
/*
* fibos.cpp
*
* Created on: Jun 1, 2018
* Author: lion
*/
#include "fibjs.h"
#include "object.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace appbase;
using namespace eosio;
namespace fc {
std::unordered_map& get_appender_map();
}
namespace fibjs {
void importModule()
{
IMPORT_MODULE(assert);
IMPORT_MODULE(base32);
IMPORT_MODULE(base64);
IMPORT_MODULE(base64vlq);
IMPORT_MODULE(bson);
IMPORT_MODULE(buffer);
IMPORT_MODULE(coroutine);
IMPORT_MODULE(crypto);
IMPORT_MODULE(db);
IMPORT_MODULE(dgram);
IMPORT_MODULE(dns);
IMPORT_MODULE(encoding);
IMPORT_MODULE(events);
IMPORT_MODULE(fs);
IMPORT_MODULE(gd);
IMPORT_MODULE(hash);
IMPORT_MODULE(hex);
IMPORT_MODULE(http);
IMPORT_MODULE(iconv);
IMPORT_MODULE(io);
IMPORT_MODULE(json);
IMPORT_MODULE(mq);
IMPORT_MODULE(net);
IMPORT_MODULE(os);
IMPORT_MODULE(path);
IMPORT_MODULE(process);
IMPORT_MODULE(profiler);
IMPORT_MODULE(punycode);
IMPORT_MODULE(querystring);
IMPORT_MODULE(ssl);
IMPORT_MODULE(string_decoder);
IMPORT_MODULE(test);
IMPORT_MODULE(timers);
IMPORT_MODULE(tty);
IMPORT_MODULE(url);
IMPORT_MODULE(util);
IMPORT_MODULE(uuid);
IMPORT_MODULE(vm);
IMPORT_MODULE(ws);
IMPORT_MODULE(xml);
IMPORT_MODULE(zip);
IMPORT_MODULE(zlib);
IMPORT_MODULE(zmq);
}
}
int32_t main(int32_t argc, char* argv[])
{
fibjs::importModule();
fibjs::start(argc, argv, fibjs::main_fiber);
fibjs::run_gui();
app().register_plugin();
return 0;
}
================================================
FILE: tools/arch.cmake
================================================
set(archdetect_c_code "
# if defined(i386) || defined(__i386__) || defined(_M_IX86) || defined(_X86_) || defined(x86)
#error cmake_ARCH i386
# endif
# if defined(__amd64) || defined(__x86_64__) || defined(_M_X64)
#error cmake_ARCH amd64
# endif
# if defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
#error cmake_ARCH ia64
# endif
# if defined(__AARCH64EL__)
#error cmake_ARCH arm64
# endif
# if defined(__ARMEL__)
#error cmake_ARCH arm
# endif
# if (defined(__MIPSEB__) || defined(__MIPSEL__))
# if defined(__mips64)
#error cmake_ARCH mips64
# else
#error cmake_ARCH mips
# endif
# endif
#if defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\
|| defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \\
|| defined(_M_MPPC) || defined(_M_PPC)
# if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__)
#error cmake_ARCH ppc64
# else
#error cmake_ARCH ppc
#endif
#error cmake_ARCH unknown
")
file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}")
enable_language(C)
set(CMAKE_C_FLAGS "${BUILD_OPTION}")
try_run(
run_result_unused
compile_result_unused
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/arch.c"
COMPILE_OUTPUT_VARIABLE ARCH
)
set(CMAKE_C_FLAGS "")
string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}")
string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}")
if (NOT ARCH)
set(ARCH unknown)
endif()
================================================
FILE: tools/config.h.in
================================================
#cmakedefine HAVE_ICONV_H 1
#cmakedefine HAVE_GLIB_C_225_H 1
#cmakedefine HAVE_GLIB_C_22_H 1
================================================
FILE: tools/gitinfo.h.in
================================================
#cmakedefine GIT_INFO "@GIT_INFO@"
================================================
FILE: tools/os.cmake
================================================
set(os_c_code "
# if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
#error cmake_OS Windows
# endif
# if defined(linux) || defined(__linux) || defined(__linux__)
#error cmake_OS Linux
# endif
# if defined(__NetBSD__)
#error cmake_OS NetBSD
# endif
# if defined(__OpenBSD__)
#error cmake_OS OpenBSD
# endif
# if (defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)) && !defined(FREEBSD)
#error cmake_OS FreeBSD
# endif
# if defined(sun) || defined(__sun)
#error cmake_OS Solaris
# endif
# if defined(macosx) || (defined(__APPLE__) && defined(__MACH__))
#error cmake_OS Darwin
# endif
#error cmake_OS unknown
")
file(WRITE "${CMAKE_BINARY_DIR}/os.c" "${os_c_code}")
enable_language(C)
try_run(
run_result_unused
compile_result_unused
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/os.c"
COMPILE_OUTPUT_VARIABLE OS
)
string(REGEX MATCH "cmake_OS ([a-zA-Z0-9_]+)" OS "${OS}")
string(REPLACE "cmake_OS " "" OS "${OS}")
if (NOT OS)
set(OS unknown)
endif()
================================================
FILE: tools/subdirs.cmake
================================================
MACRO(SUBDIRLIST result curdir)
FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
SET(dirlist "")
FOREACH(child ${children})
IF(IS_DIRECTORY ${curdir}/${child})
LIST(APPEND dirlist ${child})
ENDIF()
ENDFOREACH()
SET(${result} ${dirlist})
ENDMACRO()