id
int64 0
45.1k
| file_name
stringlengths 4
68
| file_path
stringlengths 14
193
| content
stringlengths 32
9.62M
| size
int64 32
9.62M
| language
stringclasses 1
value | extension
stringclasses 6
values | total_lines
int64 1
136k
| avg_line_length
float64 3
903k
| max_line_length
int64 3
4.51M
| alphanum_fraction
float64 0
1
| repo_name
stringclasses 779
values | repo_stars
int64 0
882
| repo_forks
int64 0
108
| repo_open_issues
int64 0
90
| repo_license
stringclasses 8
values | repo_extraction_date
stringclasses 146
values | sha
stringlengths 64
64
| __index_level_0__
int64 0
45.1k
| exdup_ids_cmlisp_stkv2
sequencelengths 1
47
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
7,855 | package.lisp | rotatef_aws-sign4/package.lisp | ;;;; aws-sign4
;;;;
;;;; Copyright (C) 2013 Thomas Bakketun <[email protected]>
;;;;
;;;; This library is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU Lesser General Public License as published
;;;; by the Free Software Foundation, either version 3 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; This library 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 library. If not, see <http://www.gnu.org/licenses/>.
(defpackage #:aws-sign4
(:use :common-lisp)
(:export
#:*aws-credentials*
#:aws-sign4
#:create-canonical-path
#:create-canonical-query-string
#:create-canonical-headers
#:create-canonical-request
#:calculate-signature
#:get-credentials))
| 1,050 | Common Lisp | .lisp | 27 | 36.814815 | 78 | 0.716243 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 080fefa2e11b08cfb6897d0630461b522a85928534545176742b324348be3fb1 | 7,855 | [
-1
] |
7,856 | example.lisp | rotatef_aws-sign4/example/example.lisp | (in-package :aws-sign4-example)
(defun swf-request (region action payload)
(let ((host (format nil "swf.~(~A~).amazonaws.com" region)))
(multiple-value-bind (authz date)
(aws-sign4 :region region
:service :swf
:method :post
:host host
:path "/"
:headers `((:x-amz-target . ,(format nil "SimpleWorkflowService.~A" action))
(:content-type . "application/x-amz-json-1.0"))
:payload payload)
(flex:octets-to-string
(http-request (format nil "https://~A/" host)
:method :post
:additional-headers `((:x-amz-target . ,(format nil "SimpleWorkflowService.~A" action))
(:x-amz-date . ,date)
(:authorization . ,authz))
:content-type "application/x-amz-json-1.0"
:content payload
:force-binary t)))))
(defun credentials-from-file ()
(let (access-key secret)
(with-open-file (in (merge-pathnames ".aws" (user-homedir-pathname)))
(setf access-key (read-line in))
(setf secret (read-line in)))
(lambda ()
(values access-key secret))))
(defmacro with-aws-credentials (&body body)
`(let ((*aws-credentials* (credentials-from-file)))
,@body))
(defun test ()
(with-aws-credentials
(swf-request :eu-west-1 "ListDomains" "{\"registrationStatus\":\"REGISTERED\"}")))
| 1,553 | Common Lisp | .lisp | 34 | 32.705882 | 108 | 0.530033 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | e237281b9e2119bc272386797b9869a7cf258c9a1568877174654d91f5d84b6d | 7,856 | [
-1
] |
7,857 | package.lisp | rotatef_aws-sign4/tests/package.lisp | ;;;; aws-sign4
;;;;
;;;; Copyright (C) 2013 Thomas Bakketun <[email protected]>
;;;;
;;;; This library is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU Lesser General Public License as published
;;;; by the Free Software Foundation, either version 3 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; This library 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 library. If not, see <http://www.gnu.org/licenses/>.
(defpackage #:aws-sign4-tests
(:use :common-lisp)
(:export))
| 850 | Common Lisp | .lisp | 19 | 43.473684 | 78 | 0.715663 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | ed310008753a616b3dfc70df0be17e5d933cbccd5ada0bfe267b3630115990e5 | 7,857 | [
-1
] |
7,858 | test.lisp | rotatef_aws-sign4/tests/test.lisp | (in-package :aws-sign4-tests)
(defun file-content (filename)
(with-open-file (bin filename :element-type 'flex:octet)
(with-open-stream (in (flex:make-flexi-stream bin :external-format '(:utf-8 :eol-style :crlf)))
(with-output-to-string (out)
(loop
(multiple-value-bind (line nl) (read-line in nil)
(unless line
(return))
(write-string line out)
(unless nl
(write-char #\Newline out))))))))
(defun load-request (filename)
(with-open-file (bin filename :element-type 'flex:octet)
(with-open-stream (in (flex:make-flexi-stream bin :external-format '(:utf-8 :eol-style :crlf)))
(let* ((req-line (read-line in))
(method-end (position #\Space req-line))
(uri-start (1+ method-end))
(uri-end (position #\Space req-line :start uri-start))
(q-pos (position #\? req-line :start uri-start))
(path-end (or q-pos uri-end))
(query-start (when q-pos (1+ q-pos))))
(list :method (intern (subseq req-line 0 method-end) :keyword)
:path (subseq req-line uri-start path-end)
:params (when query-start (query-decode (subseq req-line query-start uri-end)))
:headers (loop with name
for header = (read-line in nil)
while header
until (string= "" header)
collect (if (member (char header 0) '(#\Space #\Tab))
(cons name header)
(let ((colon-pos (position #\: header)))
(cons (setf name (subseq header 0 colon-pos))
(subseq header (1+ colon-pos))))))
:content (let* ((content-length (- (file-length bin)
(file-position bin)))
(content (make-array content-length :element-type 'flex:octet)))
(read-sequence content bin)
content))))))
(defun load-test (filename)
(list :name (pathname-name filename)
:req (load-request filename)
:creq (file-content (make-pathname :type "creq" :defaults filename))
:sts (file-content (make-pathname :type "sts" :defaults filename))
:authz (file-content (make-pathname :type "authz" :defaults filename))))
(defun uri-decode (string)
(flex:octets-to-string
(loop with pos = 0
while (< pos (length string))
append (cond ((and (char= #\% (char string pos))
(< pos (- (length string) 2)))
(let ((code (parse-integer string
:start (+ 1 pos)
:end (+ 3 pos)
:radix 16)))
(cond (code
(incf pos 3)
(list code))
(t
(incf pos)
(list (char-code #\%))))))
((char= #\+ (char string pos))
(incf pos)
(list 32))
(t
(incf pos)
(coerce (flex:string-to-octets string :start (1- pos)
:end pos
:external-format :utf-8)
'list))))
:external-format :utf-8))
(defun query-decode (string)
(loop for kv in (split-sequence:split-sequence #\& string)
for key-end = (position #\= kv)
collect (if key-end
(cons (uri-decode (subseq kv 0 key-end))
(uri-decode (subseq kv (1+ key-end))))
(cons (uri-decode kv) ""))))
(defun expect (what expect got)
(unless (string= expect got)
(format t "Expected ~A:~%~S~%~%Got:~%~S~%" what expect got)
(break)))
(defun test-presigning ()
(let ((aws-sign4:*aws-credentials* (lambda ()
(values "AKIAIOSFODNN7EXAMPLE"
"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"))))
(expect "presigned url"
"https://examplebucket.s3.amazonaws.com/test.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIOSFODNN7EXAMPLE%2F20130524%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20130524T000000Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Signature=aeeed9bbccd4d02ee5c0109b86d86835f995330da4c265957d157751f604d404"
(aws-sign4:aws-sign4 :region :us-east-1
:service :s3
:method :get
:host "examplebucket.s3.amazonaws.com"
:path "test.txt"
:request-date (local-time:parse-timestring "2013-05-24T00:00:00Z")
:expires 86400))))
(defun do-test (&key name req creq sts authz)
(format t "~%Test: ~A~%~S~%" name req)
(multiple-value-bind (my-authz my-date my-creq my-sts)
(aws-sign4:aws-sign4 :service :service
:region :us-east-1
:method (getf req :method)
:path (getf req :path)
:params (getf req :params)
:headers (getf req :headers)
:request-date (local-time:parse-timestring "2015-08-30T12:36:00Z")
:payload (getf req :content))
(declare (ignore my-date))
(expect "creq" creq my-creq)
(expect "sts" sts my-sts)
(expect "authz" authz my-authz)))
(defun run-tests ()
(let ((aws-sign4:*aws-credentials* (lambda ()
(values "AKIDEXAMPLE" "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"))))
(test-presigning)
(dolist (req (directory
(make-pathname :directory (append
(pathname-directory
(asdf:system-relative-pathname
:aws-sign4 "tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/"))
'(:wild))
:name :wild
:type "req")))
(apply #'do-test (load-test req)))))
| 6,691 | Common Lisp | .lisp | 123 | 34.276423 | 329 | 0.468426 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 8aadfed79b6049d90034f92b2b9a1b34f2cb26507b3c45037ada4aadb4cfbf21 | 7,858 | [
-1
] |
7,859 | aws-sign4.asd | rotatef_aws-sign4/aws-sign4.asd | ;;;; aws-sign4
;;;;
;;;; Copyright (C) 2013 Thomas Bakketun <[email protected]>
;;;;
;;;; This library is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU Lesser General Public License as published
;;;; by the Free Software Foundation, either version 3 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; This library 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 library. If not, see <http://www.gnu.org/licenses/>.
(defsystem #:aws-sign4
:name "aws-sign4"
:licence "GNU Lesser General Public Licence 3.0"
:author "Thomas Bakketun <[email protected]>"
:description "A library for Amazon Web Services signing version 4"
:depends-on (:local-time
:cl-ppcre
:ironclad
:split-sequence
:flexi-streams
:secret-values)
:serial t
:components ((:file "package")
(:file "aws-sign4")))
(defsystem #:aws-sign4-example
:name "aws-sign4-example"
:licence "Example"
:depends-on (:aws-sign4 :drakma)
:components ((:module example
:serial t
:components ((:file "package")
(:file "example")))))
(defsystem #:aws-sign4-tests
:name "aws-sign4-tests"
:licence "GNU Lesser General Public Licence 3.0"
:author "Thomas Bakketun <[email protected]>"
:description "Tests for aws-sign4"
:depends-on (:aws-sign4)
:components ((:module tests
:serial t
:components ((:file "package")
(:file "test")))))
(defmethod perform ((o test-op) (c (eql (find-system '#:aws-sign4))))
(operate 'load-op '#:aws-sign4-tests)
(funcall (find-symbol (string :run-tests)
:aws-sign4-tests)))
| 2,157 | Common Lisp | .asd | 52 | 34.192308 | 78 | 0.621905 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 290afd0d8de6d7a075c6800793feded70730cd20021cc70e10717e58cc01c2c3 | 7,859 | [
-1
] |
7,862 | .travis.yml | rotatef_aws-sign4/.travis.yml | language: lisp
sudo: required
branches:
only:
- master
env:
matrix:
- LISP=sbcl
- LISP=abcl
- LISP=ccl
- LISP=clisp
install:
- curl -L https://github.com/luismbo/cl-travis/raw/master/install.sh | sh
script:
- cl -e "(ql:quickload :aws-sign4) (asdf:test-system :aws-sign4)"
| 305 | Common Lisp | .l | 15 | 17.2 | 75 | 0.678322 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 8ad283159b92e8908da6d8f9b3a443b717b8fdb79ecc820f86304af5cf605242 | 7,862 | [
-1
] |
7,866 | get-vanilla-empty-query-key.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/get-vanilla-empty-query-key/get-vanilla-empty-query-key.sreq | GET /?Param1=value1 HTTP/1.1
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=a67d582fa61cc504c4bae71f336f98b97f1ea3c7a6bfe1b6e45aec72011b9aeb | 285 | Common Lisp | .l | 4 | 70.5 | 201 | 0.875887 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | a838af0466ea291fdd32f70ad94a5c1adc0c3cca352dd6309270487eda8c0f69 | 7,866 | [
-1
] |
7,867 | get-vanilla-utf8-query.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/get-vanilla-utf8-query/get-vanilla-utf8-query.sreq | GET /?ሴ=bar HTTP/1.1
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=2cdec8eed098649ff3a119c94853b13c643bcf08f8b0a1d91e12c9027818dd04 | 279 | Common Lisp | .l | 4 | 69 | 201 | 0.869565 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 272f0d2ef6d10a1e71b98c1619c31fa0c6b80c1956df3a679ab775a678cdca80 | 7,867 | [
-1
] |
7,868 | get-vanilla-query-order-key.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/get-vanilla-query-order-key/get-vanilla-query-order-key.sreq | GET /?Param1=value2&Param1=Value1 HTTP/1.1
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=eedbc4e291e521cf13422ffca22be7d2eb8146eecf653089df300a15b2382bd1 | 299 | Common Lisp | .l | 4 | 74 | 201 | 0.875 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | b0312bd0227612672000a5619cb47539fadae37b10d743e42635a5e03a2f37d3 | 7,868 | [
-1
] |
7,869 | post-vanilla.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/post-vanilla/post-vanilla.sreq | POST / HTTP/1.1
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5da7c1a2acd57cee7505fc6676e4e544621c30862966e37dddb68e92efbe5d6b | 272 | Common Lisp | .l | 4 | 67.25 | 201 | 0.877323 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | e8670646e32c8b65599e342b7ebcdcab172e581271ab801a59c0b716c0115536 | 7,869 | [
-1
] |
7,870 | get-header-value-multiline.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/get-header-value-multiline/get-header-value-multiline.sreq | GET / HTTP/1.1
Host:example.amazonaws.com
My-Header1:value1
value2
value3
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;x-amz-date, Signature=ba17b383a53190154eb5fa66a1b836cc297cc0a3d70a5d00705980573d8ff790 | 321 | Common Lisp | .l | 7 | 44 | 212 | 0.860317 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | da52c7fb353dd90a4b97b5062ed96011168f9a71f4a31d9ed69f64a6558da161 | 7,870 | [
-1
] |
7,871 | get-header-key-duplicate.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/get-header-key-duplicate/get-header-key-duplicate.sreq | GET / HTTP/1.1
Host:example.amazonaws.com
My-Header1:value2
My-Header1:value2
My-Header1:value1
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;x-amz-date, Signature=c9d5ea9f3f72853aea855b47ea873832890dbdd183b4468f858259531a5138ea | 336 | Common Lisp | .l | 7 | 47.142857 | 212 | 0.875758 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 0a7ca55894badb3bdd5b3b225997fa1b8e70984b2d3d3d6423b9dcd367d8404d | 7,871 | [
-1
] |
7,872 | get-vanilla-query.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/get-vanilla-query/get-vanilla-query.sreq | GET / HTTP/1.1
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5fa00fa31553b73ebf1942676e86291e8372ff2a2260956d9b8aae1d763fbf31 | 271 | Common Lisp | .l | 4 | 67 | 201 | 0.876866 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 372198b964e1dda3f7b2085c8e5d78bb310d65e99fa5e817a411256a34d5d33f | 7,872 | [
-1
] |
7,874 | get-vanilla-query-order-key-case.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/get-vanilla-query-order-key-case/get-vanilla-query-order-key-case.sreq | GET /?Param2=value2&Param1=value1 HTTP/1.1
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=b97d918cfa904a5beff61c982a1b6f458b799221646efd99d3219ec94cdf2500 | 299 | Common Lisp | .l | 4 | 74 | 201 | 0.875 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 52c7a03be90022c1d5765c8db4c59da30cccae68c3f29916cc2a99d7855b1d71 | 7,874 | [
-1
] |
7,875 | normalize-path.txt | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/normalize-path/normalize-path.txt | A note about signing requests to Amazon S3:
In exception to this, you do not normalize URI paths for requests to Amazon S3. For example, if you have a bucket with an object named my-object//example//photo.user, use that path. Normalizing the path to my-object/example/photo.user will cause the request to fail. For more information, see Task 1: Create a Canonical Request in the Amazon Simple Storage Service API Reference: http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html#canonical-request | 521 | Common Lisp | .l | 2 | 258.5 | 474 | 0.799228 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | bb71c45a370a77fa18d752cdc3891b9dc46b4b37075a675452153e99c046f06e | 7,875 | [
-1
] |
7,876 | get-slash-dot-slash.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/normalize-path/get-slash-dot-slash/get-slash-dot-slash.sreq | GET /./ HTTP/1.1
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5fa00fa31553b73ebf1942676e86291e8372ff2a2260956d9b8aae1d763fbf31 | 273 | Common Lisp | .l | 4 | 67.5 | 201 | 0.87037 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 3b78557fc4adb077d4ddf1687ea8c90ec86c8d226a38ec351c2b612c145072f8 | 7,876 | [
-1
] |
7,877 | get-slash.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/normalize-path/get-slash/get-slash.sreq | GET // HTTP/1.1
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5fa00fa31553b73ebf1942676e86291e8372ff2a2260956d9b8aae1d763fbf31 | 272 | Common Lisp | .l | 4 | 67.25 | 201 | 0.873606 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | d46cc9a4f999867df8e59f98de742907a10c105bd343b50dad9d293ced5a2a50 | 7,877 | [
-1
] |
7,878 | get-slash-pointless-dot.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/normalize-path/get-slash-pointless-dot/get-slash-pointless-dot.sreq | GET /./example HTTP/1.1
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=ef75d96142cf21edca26f06005da7988e4f8dc83a165a80865db7089db637ec5 | 280 | Common Lisp | .l | 4 | 69.25 | 201 | 0.873646 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | c7e7871fcd4482b69bbf6946dcb87e2ab5efae3f9c27e5e51065e373038899bf | 7,878 | [
-1
] |
7,879 | get-relative.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/normalize-path/get-relative/get-relative.sreq | GET /example/.. HTTP/1.1
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5fa00fa31553b73ebf1942676e86291e8372ff2a2260956d9b8aae1d763fbf31 | 281 | Common Lisp | .l | 4 | 69.5 | 201 | 0.870504 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 4c200b75ed748ce9990272a2d8dfbebb396fb71795e2fa1b0e59d79c91caf7e1 | 7,879 | [
-1
] |
7,880 | get-slashes.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/normalize-path/get-slashes/get-slashes.sreq | GET //example// HTTP/1.1
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=9a624bd73a37c9a373b5312afbebe7a714a789de108f0bdfe846570885f57e84 | 281 | Common Lisp | .l | 4 | 69.5 | 201 | 0.870504 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 3492d23392f6e3ffbc3a29f8729ced6b120530385231bce1ec51cd7126e7b1f8 | 7,880 | [
-1
] |
7,881 | get-relative-relative.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/normalize-path/get-relative-relative/get-relative-relative.sreq | GET /example1/example2/../.. HTTP/1.1
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5fa00fa31553b73ebf1942676e86291e8372ff2a2260956d9b8aae1d763fbf31 | 294 | Common Lisp | .l | 4 | 72.75 | 201 | 0.862543 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | b4f2253c905f0d0184b807c1d9e8875c428dfac9959832eea642e09b386682bc | 7,881 | [
-1
] |
7,882 | post-vanilla-query.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/post-vanilla-query/post-vanilla-query.sreq | POST /?Param1=value1 HTTP/1.1
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=28038455d6de14eafc1f9222cf5aa6f1a96197d7deb8263271d420d138af7f11 | 286 | Common Lisp | .l | 4 | 70.75 | 201 | 0.876325 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | c4bf0759138371440664ec5052f3598886c00cadc01094fe07124ac178541ff6 | 7,882 | [
-1
] |
7,883 | get-header-value-order.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/get-header-value-order/get-header-value-order.sreq | GET / HTTP/1.1
Host:example.amazonaws.com
My-Header1:value4
My-Header1:value1
My-Header1:value3
My-Header1:value2
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;x-amz-date, Signature=08c7e5a9acfcfeb3ab6b2185e75ce8b1deb5e634ec47601a50643f830c755c01 | 354 | Common Lisp | .l | 8 | 43.375 | 212 | 0.876081 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | d85a14bc668a46f6aa97bfdbda497141f586f0cbba4949bd7c372850a9bd137a | 7,883 | [
-1
] |
7,884 | post-x-www-form-urlencoded.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/post-x-www-form-urlencoded/post-x-www-form-urlencoded.sreq | POST / HTTP/1.1
Content-Type:application/x-www-form-urlencoded
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=ff11897932ad3f4e8b18135d722051e5ac45fc38421b1da7b9d196a0fe09473a
Param1=value1 | 347 | Common Lisp | .l | 6 | 56.833333 | 214 | 0.876833 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | e9aafd32455c588a2c0d72c2e5c6d79da5182fcff067f149ac653661c5f29d6b | 7,884 | [
-1
] |
7,885 | get-vanilla-query-unreserved.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/get-vanilla-query-unreserved/get-vanilla-query-unreserved.sreq | GET /?-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz HTTP/1.1
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=9c3e54bfcdf0b19771a7f523ee5669cdf59bc7cc0884027167c21bb143a40197 | 405 | Common Lisp | .l | 4 | 100.5 | 201 | 0.893035 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 43b44295732a1e32f2b3cd1c95f74c08cc266e768e61907be3c26187d6bc7af5 | 7,885 | [
-1
] |
7,886 | get-header-value-trim.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/get-header-value-trim/get-header-value-trim.sreq | GET / HTTP/1.1
Host:example.amazonaws.com
My-Header1: value1
My-Header2: "a b c"
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;my-header2;x-amz-date, Signature=acc3ed3afb60bb290fc8d2dd0098b9911fcaa05412b367055dee359757a9c736 | 336 | Common Lisp | .l | 6 | 55.166667 | 223 | 0.845921 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 30cb8400b3bd877666c6d74d7a2f8da7816e9d7fe1d87179eae2b7699d4dfcfb | 7,886 | [
-1
] |
7,887 | get-header-value-trim.creq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/get-header-value-trim/get-header-value-trim.creq | GET
/
host:example.amazonaws.com
my-header1:value1
my-header2:"a b c"
x-amz-date:20150830T123600Z
host;my-header1;my-header2;x-amz-date
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 | 202 | Common Lisp | .l | 8 | 24.125 | 64 | 0.88601 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | f753c98691a22babecaeb8d5ce82d8b75fcb39c6668133780a75d0ddcc663eb5 | 7,887 | [
-1
] |
7,888 | get-header-value-trim.req | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/get-header-value-trim/get-header-value-trim.req | GET / HTTP/1.1
Host:example.amazonaws.com
My-Header1: value1
My-Header2: "a b c"
X-Amz-Date:20150830T123600Z | 112 | Common Lisp | .l | 5 | 21.6 | 27 | 0.768519 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | ac19d33c73a3bac6b667a589d1d912178134138c40898409634c9c06ea4e00a5 | 7,888 | [
-1
] |
7,889 | get-vanilla-query-order-value.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/get-vanilla-query-order-value/get-vanilla-query-order-value.sreq | GET /?Param1=value2&Param1=value1 HTTP/1.1
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5772eed61e12b33fae39ee5e7012498b51d56abc0abb7c60486157bd471c4694 | 299 | Common Lisp | .l | 4 | 74 | 201 | 0.875 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 0f48f5bfd0ce39e2eed6c400b1feede687d63b0750b4c71418c5e911b43fdfcd | 7,889 | [
-1
] |
7,891 | post-x-www-form-urlencoded-parameters.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/post-x-www-form-urlencoded-parameters/post-x-www-form-urlencoded-parameters.sreq | POST / HTTP/1.1
Content-Type:application/x-www-form-urlencoded; charset=utf8
Host:example.amazonaws.com
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=1a72ec8f64bd914b0e42e42607c7fbce7fb2c7465f63e3092b3b0d39fa77a6fe
Param1=value1 | 361 | Common Lisp | .l | 6 | 59.166667 | 214 | 0.873239 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | eb4f0ed995d47ccaad9f0149e72bb586a8897c8408e8426fe68c6f3c15cca60b | 7,891 | [
-1
] |
7,892 | post-header-value-case.sreq | rotatef_aws-sign4/tests/aws-sig-v4-test-suite/aws-sig-v4-test-suite/post-header-value-case/post-header-value-case.sreq | POST / HTTP/1.1
Host:example.amazonaws.com
My-Header1:VALUE1
X-Amz-Date:20150830T123600Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;x-amz-date, Signature=cdbc9802e29d2942e5e10b5bccfdd67c5f22c7c4e8ae67b53629efa58b974b7d | 301 | Common Lisp | .l | 5 | 59.4 | 212 | 0.875421 | rotatef/aws-sign4 | 18 | 6 | 4 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | f197132859e00ec929b92e3a12d62c1246f0efb58a455036d9561abb6474f03e | 7,892 | [
-1
] |
7,907 | log.lisp | troydm_myweb/log.lisp | ;;; myweb - simple web server written in Common Lisp
;;;
;;; log.lisp
;;;
;;; Author: Dmitry Geurkov <[email protected]>
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
(in-package :cl-log)
(setf (log-manager)
(make-instance 'log-manager :message-class 'formatted-message))
(start-messenger 'text-file-messenger :filename (merge-pathnames #p"log/web.log" myweb.config:*base-directory*))
(defmethod format-message ((self formatted-message))
(format nil "~a ~a ~?~&"
(local-time:format-timestring nil
(local-time:universal-to-timestamp
(timestamp-universal-time (message-timestamp self))))
(message-category self)
(message-description self)
(message-arguments self)))
| 1,185 | Common Lisp | .lisp | 26 | 42.961538 | 112 | 0.739168 | troydm/myweb | 11 | 5 | 0 | LGPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 2c73a1817cf06b44ac2acd2a8232e1787618dd646b911604515e3f423c5f6dff | 7,907 | [
-1
] |
7,908 | package.lisp | troydm_myweb/package.lisp | ;;; myweb - simple web server written in Common Lisp
;;;
;;; package.lisp
;;;
;;; Author: Dmitry Geurkov <[email protected]>
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
(in-package :cl-user)
(defpackage :myweb
(:use :cl :usocket :bordeaux-threads)
(:export :start-http :stop-http :stop-thread :list-workers :list-requests))
(defpackage :myweb.util
(:use :cl :local-time)
(:export :parse-request :read-utf-8-string :response-write :get-param :get-header :http-response :file-response :html-template :log-info :log-warning :log-error))
(defpackage :myweb.handler
(:use :cl)
(:export :process-request))
| 1,098 | Common Lisp | .lisp | 24 | 44.041667 | 164 | 0.743686 | troydm/myweb | 11 | 5 | 0 | LGPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 1e10116c2eb26dac340eb7058bca055e727f5b0b3e2722489e6a6cbc72eaa644 | 7,908 | [
-1
] |
7,909 | util.lisp | troydm_myweb/util.lisp | ;;; myweb - simple web server written in Common Lisp
;;;
;;; util.lisp
;;;
;;; Author: Dmitry Geurkov <[email protected]>
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
(in-package :myweb.util)
(defvar *new-line* (concatenate 'string (string #\Return) (string #\Newline)))
(defun parse-request (stream)
(let ((header (read-utf-8-string stream 10)))
(if (eq (length header) 0)
'()
(if (equal (subseq header 0 4) "POST")
(parse-post-header header stream)
(parse-get-header header stream)))))
(defun read-utf-8-string (stream &optional (end 0))
(let ((byte -1)
(buffer (make-array 1 :fill-pointer 0 :adjustable t)))
(handler-case
(loop do
(setq byte (read-byte stream))
(if (/= byte end) (vector-push-extend byte buffer))
while (/= byte end))
(end-of-file ()))
(trivial-utf-8:utf-8-bytes-to-string buffer)))
(defun response-write (text stream)
(trivial-utf-8::write-utf-8-bytes text stream))
(defun parse-get-header (header stream)
(cons "GET"
(cons (parse-path (subseq header (position #\/ header) (position #\Space header :from-end t)))
(parse-headers stream))))
(defun parse-headers (stream)
(let ((headers nil)
(header nil))
(loop do
(setq header (read-utf-8-string stream 10))
(if (> (length header) 2) (setq headers (cons (parse-header header) headers)))
while (> (length header) 2))
(reverse headers)))
(defun parse-header (header)
(let ((pos (position #\: header)))
(if pos (cons (string-downcase (subseq header 0 pos)) (string-trim (concatenate 'string (string #\Space) (string #\Return)) (subseq header (1+ pos)))))))
(defun parse-post-header (header stream)
(cons "POST" nil))
(defun file-response (filename type request stream)
(handler-case
(with-open-file (in (merge-pathnames (merge-pathnames filename "web/") myweb.config:*base-directory*) :element-type '(unsigned-byte 8))
(if (equal (get-header "if-modified-since" request) (format-timestring nil (universal-to-timestamp (file-write-date in)) :format +asctime-format+))
(http-response "304 Not Modified" nil stream)
(progn
(http-response "200 OK"
(cons
(cons "Last-Modified" (format-timestring nil (universal-to-timestamp (file-write-date in)) :format +asctime-format+))
(cons (cons "Content-Type" type) nil))
stream)
(let ((buf (make-array 4096 :element-type (stream-element-type in))))
(loop for pos = (read-sequence buf in)
while (plusp pos)
do (write-sequence buf stream :end pos)))
)))
(file-error ()
(http-404-not-found "404 File Not Found" stream)
)))
(defun html-template (filename type params request stream)
(handler-case
(with-open-file (in (merge-pathnames (merge-pathnames filename "web/") myweb.config:*base-directory*) :element-type '(unsigned-byte 8))
(loop for line = (read-utf-8-string in 10)
while (and line (> (length line) 0))
do (progn
(mapcar (lambda (i)
(let* ((key (concatenate 'string "${" (car i) "}")))
(loop for pos = (search key line)
while pos
do
(setq line
(concatenate 'string
(subseq line 0 pos) (cdr i)
(subseq line (+ pos (length key)))))
)
)) params)
(response-write line stream)
(response-write (string #\Return) stream))
)
)
(file-error ()
(http-404-not-found "404 File Not Found" stream)
)))
(defun http-response (code headers stream)
(response-write (concatenate 'string "HTTP/1.1 " code *new-line*) stream)
(mapcar (lambda (header)
(response-write
(concatenate 'string (car header) ": " (cdr header) *new-line*) stream)) headers)
(response-write *new-line* stream))
(defun http-404-not-found (message stream)
(http-response "404 Not Found" nil stream)
(response-write message stream))
(defun parse-path (path)
(if (position #\? path)
(cons (subseq path 0 (position #\? path)) (parse-params (subseq path (1+ (position #\? path)))))
(cons path nil)))
(defun http-char (c1 c2 &optional (default #\Space))
(let ((code (parse-integer (coerce (list c1 c2) 'string) :radix 16 :junk-allowed t)))
(if code
(code-char code)
default)))
(defun decode-param (s)
(labels ((f (1st)
(when 1st
(case (car 1st)
(#\% (cons (http-char (cadr 1st) (caddr 1st))
(f (cdddr 1st))))
(#\+ (cons #\Space (f (cdr 1st))))
(otherwise (cons (car 1st) (f (cdr 1st))))))))
(coerce (f (coerce s 'list)) 'string)))
(defun decode-kv (s)
(let ((p1 (position #\= s)))
(if p1 (cons (decode-param (subseq s 0 p1)) (decode-param (subseq s (1+ p1))))
(cons (decode-param s) nil))))
(defun decode-params (s)
(let ((p1 (position #\& s)))
(if p1 (cons (decode-kv (subseq s 0 p1)) (parse-params (subseq s (1+ p1))))
(list (decode-kv s)))))
(defun parse-params (s)
(let ((params (decode-params s)))
(remove-duplicates params :test (lambda (x1 x2) (equal (car x1) (car x2))) :from-end nil)))
(defun get-param (name request)
(cdr (assoc name (cdadr request) :test #'equal)))
(defun get-header (name request)
(cdr (assoc (string-downcase name) (cddr request) :test #'equal)))
(defvar *log-queue-lock* (bt:make-lock))
(defvar *log-queue-cond* (bt:make-condition-variable))
(defvar *log-queue-cond-lock* (bt:make-lock))
(defvar *log-queue* nil)
(defvar *log-queue-time* (get-universal-time))
(defun log-worker ()
(bt:with-lock-held (*log-queue-lock*)
(progn
(mapcar (lambda (i) (if (cdr i) (cl-log:log-message (car i) (cdr i)))) (reverse *log-queue*))
(setq *log-queue* nil)
))
(bt:with-lock-held (*log-queue-cond-lock*)
(bt:condition-wait *log-queue-cond* *log-queue-cond-lock*)
)
(log-worker))
(bt:make-thread #'log-worker :name "log-worker")
(defun log-info (message)
(bt:with-lock-held (*log-queue-lock*)
(progn
(push (cons :info message) *log-queue*)
(if (> (- (get-universal-time) *log-queue-time*) 0)
(bt:condition-notify *log-queue-cond*))
)))
(defun log-warning (message)
(bt:with-lock-held (*log-queue-lock*)
(progn
(push (cons :warning message) *log-queue*)
(if (> (- (get-universal-time) *log-queue-time*) 0)
(bt:condition-notify *log-queue-cond*))
)))
(defun log-error (message)
(bt:with-lock-held (*log-queue-lock*)
(progn
(push (cons :error message) *log-queue*)
(if (> (- (get-universal-time) *log-queue-time*) 0)
(bt:condition-notify *log-queue-cond*))
)))
| 6,964 | Common Lisp | .lisp | 174 | 35.821839 | 157 | 0.652026 | troydm/myweb | 11 | 5 | 0 | LGPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 914457da05aac6031c691ec36b2670d241a4cd8430b2d00faeb1dd91410854a2 | 7,909 | [
-1
] |
7,910 | load.lisp | troydm_myweb/load.lisp | ;;; myweb - simple web server written in Common Lisp
;;;
;;; load.lisp
;;;
;;; Author: Dmitry Geurkov <[email protected]>
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
(in-package :cl-user)
(quicklisp:quickload "swank")
(quicklisp:quickload "usocket")
(quicklisp:quickload "bordeaux-threads")
(quicklisp:quickload "trivial-utf-8")
(quicklisp:quickload "cl-log")
(quicklisp:quickload "local-time")
(pushnew '*default-pathname-defaults* asdf:*central-registry*)
(asdf:load-system 'myweb)
(swank:create-server)
| 992 | Common Lisp | .lisp | 24 | 40.125 | 79 | 0.764278 | troydm/myweb | 11 | 5 | 0 | LGPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | f30b70b6d1ba5416983400de69c0cd3777b32c5f6393b204d643fcbf21be9e99 | 7,910 | [
-1
] |
7,911 | web.lisp | troydm_myweb/web.lisp | ;;; myweb - simple web server written in Common Lisp
;;;
;;; web.lisp
;;;
;;; Author: Dmitry Geurkov <[email protected]>
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
(in-package :myweb)
(defvar *listen-socket* nil)
(defvar *listen-thread* nil)
(defvar *request-mutex* (make-lock "request-mutex"))
(defvar *request-threads* (list))
(defvar *worker-mutex* (make-lock "worker-mutex"))
(defvar *workers* (list))
(defvar *worker-num* 0)
(defvar *idle-workers* (list))
(defvar *idle-workers-num* 0)
(defvar *request-queue* (list))
(defun start-http (host port &key (worker-limit 10) (idle-workers 1))
(if (not *listen-socket*)
(setq *listen-thread*
(make-thread (lambda () (http-acceptor host port worker-limit idle-workers))
:name "socket-acceptor"))
"http server already started"))
(defun http-acceptor (host port worker-limit idle-workers)
;; Start Listening on specified host and port
(setq *listen-socket* (socket-listen host port
:reuse-address t
:element-type '(unsigned-byte 8)
:backlog (* worker-limit 4)))
(let ((request-id 0)
(worker-id 0))
(loop while *listen-thread* do
(let* ((socket (socket-accept *listen-socket* :element-type '(unsigned-byte 8))))
(incf request-id)
(acquire-lock *worker-mutex*)
(cond
;; All workers busy, append request to queue
((>= *worker-num* worker-limit)
(push (cons request-id socket) *request-queue*))
;; If idle worker available
((> *idle-workers-num* 0)
;; Get worker from idle workers
(push (cons request-id socket) *request-queue*)
(condition-notify (caar *idle-workers*)))
;; Add new Worker
(t (incf worker-id)
(incf *worker-num*)
(setq *workers*
(cons
(make-thread
(lambda ()
(worker-thread request-id socket idle-workers))
:name (concatenate 'string
"socket-worker-"
(prin1-to-string worker-id)))
*workers*)))
)
(release-lock *worker-mutex*)
t))))
(defun worker-thread (request-id socket idle-workers)
;; Process request if it is not nil
(if request-id
(http-worker request-id socket))
(acquire-lock *worker-mutex*)
(cond
;; Process request from queue
(*request-queue*
(let ((request nil))
(setq request (car *request-queue*))
(setq *request-queue* (cdr *request-queue*))
(release-lock *worker-mutex*)
(worker-thread (car request) (cdr request) idle-workers)))
;; If not enough idle workers, make worker idle
((< *idle-workers-num* idle-workers)
(let ((condition (make-condition-variable))
(idle-lock (make-lock))
(request nil))
(push (cons condition (current-thread)) *idle-workers*)
(incf *idle-workers-num*)
(release-lock *worker-mutex*)
(list-workers)
(with-lock-held (idle-lock)
(condition-wait condition idle-lock))
(with-lock-held (*worker-mutex*)
(setq *idle-workers* (cdr *idle-workers*))
(decf *idle-workers-num*)
(setq request (car *request-queue*))
(setq *request-queue* (cdr *request-queue*)))
(worker-thread (car request) (cdr request) idle-workers)))
;; else
(t (setq *workers* (remove (current-thread) *workers*))
(decf *worker-num*)
(release-lock *worker-mutex*))
)
)
(defun http-worker (request-id socket)
(let* ((stream (socket-stream socket))
(request (myweb.util:parse-request stream)))
(with-lock-held (*request-mutex*)
(push (cons request-id (current-thread)) *request-threads*))
(myweb.handler:process-request request stream)
(finish-output stream)
(socket-close socket)
(with-lock-held (*request-mutex*)
(setq *request-threads* (remove request-id *request-threads* :key 'car)))
))
(defun list-workers ()
(with-lock-held (*worker-mutex*)
(setq *workers*
(remove-if (lambda (w) (not (thread-alive-p w))) *workers*))
(setq *worker-num* (length *workers*))
*workers*))
(defun list-requests ()
(with-lock-held (*request-mutex*)
(setq *request-threads*
(remove-if (lambda (r) (not (thread-alive-p (cdr r)))) *request-threads*))
*request-threads*))
(defun stop-http ()
(if *listen-socket*
(progn (stop-thread)
(socket-close *listen-socket*)
(setq *listen-socket* nil)
(setq *request-queue* nil)
(setq *worker-num* 0)
(setq *workers* nil)
(mapcar (lambda (i) (destroy-thread (cdr i))) *idle-workers*)
(setq *idle-workers-num* 0)
(setq *idle-workers* nil)
(release-lock *worker-mutex*)
(setq *request-threads* nil)
(release-lock *request-mutex*)
(setq *request-mutex* (make-lock "request-mutex"))
(setq *worker-mutex* (make-lock "worker-mutex")))))
(defun stop-thread ()
(if (and *listen-thread* (thread-alive-p *listen-thread*))
(destroy-thread *listen-thread*)))
| 5,371 | Common Lisp | .lisp | 144 | 32.368056 | 83 | 0.65655 | troydm/myweb | 11 | 5 | 0 | LGPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 606c54a04788c6cbf9be8153f10ddf3d2a76d65815521b941e5cb1b43844f797 | 7,911 | [
-1
] |
7,912 | handler.lisp | troydm_myweb/handler.lisp | ;;; myweb - simple web server written in Common Lisp
;;;
;;; handler.lisp
;;;
;;; Author: Dmitry Geurkov <[email protected]>
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
(in-package :myweb.handler)
(defun process-request (request stream)
(let ((path (caadr request)))
(cond
((equal path "/logo.jpg") (myweb.util:file-response "logo.jpg" "image/jpeg" request stream))
(t
(process-index request stream)))))
(defun process-index (request stream)
(let ((name (myweb.util:get-param "name" request)))
(if (and name (> (length name) 0))
(myweb.util:html-template "index.html" "text/html;encoding=UTF-8" `(("name" . ,name)) request stream)
(myweb.util:html-template "name.html" "text/html;encoding=UTF-8" nil request stream)
)))
| 1,245 | Common Lisp | .lisp | 27 | 43.481481 | 102 | 0.714992 | troydm/myweb | 11 | 5 | 0 | LGPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 7d67c6250b5153e8ccefe63947007d22bcc11bc4e5115f510dce7a3426703d3a | 7,912 | [
-1
] |
7,913 | myweb.asd | troydm_myweb/myweb.asd | ;;; myweb - simple web server written in Common Lisp
;;;
;;; myweb.asd
;;;
;;; Author: Dmitry Geurkov <[email protected]>
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
;; myweb.asd
(asdf:defsystem #:myweb
:description "simple web server written in common lisp for educational reasons"
:author "Dmitry Geurkov <[email protected]>"
:maintainer "Dmitry Geurkov <[email protected]>"
:license "LGPLv3"
:depends-on ("usocket" "bordeaux-threads" "local-time" "cl-log" "trivial-utf-8")
:serial t
:components ((:file "package")
(:file "util")
(:file "web")
(:file "log")
(:file "handler")))
(defpackage #:myweb.config (:export #:*base-directory*))
(defparameter myweb.config:*base-directory*
(make-pathname :name nil :type nil :defaults *load-truename*))
| 1,291 | Common Lisp | .asd | 30 | 39.966667 | 82 | 0.712919 | troydm/myweb | 11 | 5 | 0 | LGPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 52b21707adf2a73c226f27b1ae630df6b69b99b6b35270feefb200ab8a854e84 | 7,913 | [
-1
] |
7,921 | name.html | troydm_myweb/web/name.html | <html>
<head>
<title>myweb</title>
</head>
<body>
<image src="logo.jpg">
<h2>Hello stranger. What's your name?</h2>
<form action="/" method="GET">
Name: <input type="text" name="name">
<input type="submit" value="Submit">
</form>
</body>
</html>
| 246 | Common Lisp | .l | 13 | 17.923077 | 42 | 0.678112 | troydm/myweb | 11 | 5 | 0 | LGPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | e0ea2b0a9e8ffd62137c9c1349256aa6c415a498fa3caf571643fb942b826aac | 7,921 | [
-1
] |
7,922 | index.html | troydm_myweb/web/index.html | <html>
<head>
<title>myweb</title>
</head>
<body>
<image src="logo.jpg">
<h1>Hello ${name}</h1>
</body>
</html>
| 112 | Common Lisp | .l | 9 | 11.444444 | 22 | 0.650485 | troydm/myweb | 11 | 5 | 0 | LGPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 22a463f9e392b0d33796d52fa323c12184b65fb1ac07d62665a5686931cda1ad | 7,922 | [
-1
] |
7,937 | buffer.lisp | cbaggers_l-lisp/buffer.lisp | ;;; *** buffer.lisp ***
;;;
;;; This file is part of L-Lisp by Knut Arild Erstad.
;;; Implements a growing sequence as a list of vectors.
(in-package :l-systems)
;; *** Buffer data structure ***
(defstruct (buffer (:constructor internal-make-buffer))
(inc-size 0 :type fixnum) ; size of each "minibuffer"
(list nil) ; list of minibuffers
(current nil) ; current minibuffer (for fast access)
(size 0 :type fixnum) ; total number of elements
(current-size 0 :type fixnum) ; number of elements in current buffer
(list-size 0 :type fixnum)) ; length of list
(defun make-buffer (&optional (inc-size 4096))
(internal-make-buffer :inc-size inc-size
:current-size inc-size))
(declaim (inline buffer-push))
(defun buffer-push (elt buffer)
"Add a new element to the end of the buffer (like VECTOR-PUSH-EXTEND)."
(declare (optimize (speed 3) (safety 0)))
(incf (buffer-size buffer))
(if (>= (buffer-current-size buffer) (buffer-inc-size buffer))
(let ((newbuf (make-array (buffer-inc-size buffer))))
(setf (buffer-current buffer) newbuf)
(push newbuf (buffer-list buffer))
(incf (buffer-list-size buffer))
(setf (buffer-current-size buffer) 1)
(setf (svref newbuf 0) elt))
(let ((pos (buffer-current-size buffer)))
(incf (buffer-current-size buffer))
(setf (svref (buffer-current buffer) pos) elt))))
(defun buffer->vector (buffer)
"Returns simple-vector of the buffer elements."
(declare (optimize (speed 3) (safety 0)))
(let ((vector (make-array (buffer-size buffer)))
(i 0)
(list-count (buffer-list-size buffer)))
(declare (type fixnum i list-count))
(dolist (v (reverse (buffer-list buffer)))
(let ((vsize (if (zerop (decf list-count))
(buffer-current-size buffer)
(buffer-inc-size buffer))))
(dotimes (vpos vsize)
(setf (svref vector i) (svref v vpos))
(incf i))))
vector))
(defmacro dobuffer ((var buffer &optional (result nil)) &body body)
(let ((vec (gensym))
(vec-size (gensym))
(vec-pos (gensym))
(list-count (gensym))
(buf (gensym)))
`(let* ((,buf ,buffer)
(,list-count (buffer-list-size ,buf)))
(dolist (,vec (reverse (buffer-list ,buf)) ,result)
(let ((,vec-size (if (zerop (decf ,list-count))
(buffer-current-size ,buf)
(buffer-inc-size ,buf))))
(dotimes (,vec-pos ,vec-size)
(let ((,var (svref ,vec ,vec-pos)))
,@body)))))))
| 2,651 | Common Lisp | .lisp | 61 | 36.344262 | 73 | 0.599458 | cbaggers/l-lisp | 11 | 2 | 2 | GPL-2.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | bdc50cfb3e1580cc9f049ce61ccf5204b3d9f4a0578d1fc64cadb0e5faae4613 | 7,937 | [
-1
] |
7,938 | advanced-examples.lisp | cbaggers_l-lisp/advanced-examples.lisp | (in-package :l-system-examples)
;; *****************************************************
;; *** a schematic plant shaped by a spline function ***
;; *****************************************************
(defun edit-shape (&optional (eps-filename nil))
(edit-spline :filename "shape.spline"
:eps-filename eps-filename))
(defclass shaped-plant (l-system)
((axiom :initform '(S))
(homomorphism-depth :initform 100)
(spline :accessor spline)))
(defmethod rewrite :before ((ls shaped-plant) &optional (depth 0))
(declare (ignore depth))
(setf (spline ls) (input-spline "shape.spline" :make-function t)))
(defmethod homomorphism ((ls shaped-plant))
(let* ((spline (spline ls))
(sfunc (spline-function spline))
(length 1.0)
(width-mult 1.0)
(segments 40)
(segment-length (/ length segments)))
(choose-production ls
(S (--> (F segment-length) (A 0.0)))
((A x) (when (< x length)
(let* ((fval (funcall sfunc (/ x length)))
(width (* fval width-mult)))
(--> [ (+ 90) (F width) ]
[ (- 90) (F width) ]
(F segment-length)
(A (+ x segment-length)))))))))
;; ********************************************************
;; *** a schematic plant shaped by TWO spline functions ***
;; ********************************************************
(defun edit-shape-1 (&optional (eps-filename nil))
(edit-spline :filename "shape1.spline"
:eps-filename eps-filename))
(defun edit-shape-2 (&optional (eps-filename nil))
(edit-spline :filename "shape2.spline"
:eps-filename eps-filename))
(defclass shaped-plant-2 (l-system)
((axiom :initform '(S))
(homomorphism-depth :initform 100)
(spline1 :accessor spline1)
(spline2 :accessor spline2)
))
(defmethod rewrite :before ((ls shaped-plant-2) &optional (depth 0))
(declare (ignore depth))
(setf (spline1 ls) (input-spline "shape1.spline" :make-function t)
(spline2 ls) (input-spline "shape2.spline" :make-function t)))
(defmethod homomorphism ((ls shaped-plant-2))
(let* ((spline1 (spline1 ls))
(sfunc1 (spline-function spline1))
(spline2 (spline2 ls))
(sfunc2 (spline-function spline2))
(length 1.0)
(width-mult 1.0)
(angle-mult 90.0)
(segments 40)
(segment-length (/ length segments)))
(choose-production ls
(S (--> (F segment-length) (A 0.0)))
((A x) (when (< x length)
(let* ((xrel (/ x length))
(fval1 (funcall sfunc1 xrel))
(width (* fval1 width-mult))
(fval2 (funcall sfunc2 xrel))
(angle (* fval2 angle-mult)))
(--> [ (+ 90) (- angle) (F width) ]
[ (- 90) (+ angle) (F width) ]
(F segment-length)
(A (+ x segment-length)))))))))
;; ****************************************************
;; *** a mesh leaf shaped by three spline functions ***
;; ****************************************************
(defun edit-leaf-width ()
(edit-spline :filename "leaf-width.spline"))
(defun edit-leaf-curving ()
(edit-spline :filename "leaf-curving.spline"))
(defun edit-leaf-hcurving ()
(edit-spline :filename "leaf-hcurving.spline"))
(defclass shaped-leaf (l-system)
((axiom :initform '(S))
(homomorphism-depth :initform 100)
(line-style :initform :cylinders)
(cylinder-width :initform 0.005)
(width-spline :accessor width-spline)
(curving-spline :accessor curving-spline)
(hcurving-spline :accessor hcurving-spline)))
(defmethod rewrite :before ((ls shaped-leaf) &optional (depth 0))
(declare (ignore depth))
(setf (width-spline ls) (input-spline "leaf-width.spline" :make-function t)
(curving-spline ls) (input-spline "leaf-curving.spline"
:make-function t)
(hcurving-spline ls) (input-spline "leaf-hcurving.spline"
:make-function t)))
(defmethod homomorphism ((ls shaped-leaf))
(let* ((length 1.0)
(segments 40)
(segment-length (/ length segments))
(width-multiply 1.0)
(curving-multiply 10.0)
(hcurving-multiply -100.0)
(width-func (spline-function (width-spline ls)))
(curving-func (spline-function (curving-spline ls)))
(hcurving-func (spline-function (hcurving-spline ls))))
(choose-production ls
(S (--> (:color #(0.5 1.0 0.5))
(:pitch-down 20)
(:roll-left 20)
(:forward 0.2)
:start-mesh [ (L 0.0) ]
:new-strand [ (M 0.0) ]
:new-strand [ (R 0.0) ]
:end-mesh))
;; left strand
((L x)
(when (< x length)
(let* ((x1 (/ x length))
(w-val (funcall width-func x1))
(c-val (funcall curving-func x1))
(h-val (funcall hcurving-func x1)))
(--> [ (:turn-left 90) (:pitch-down (* hcurving-multiply h-val))
(:forward-mesh-vertex (* width-multiply w-val)) ]
(:pitch-down (* curving-multiply c-val))
(:forward-no-line segment-length)
(L (+ x segment-length))))))
;; middle strand
((M x)
(when (< x length)
(let* ((x1 (/ x length))
(c-val (funcall curving-func x1)))
(--> (:pitch-down (* curving-multiply c-val))
:mesh-vertex
(:forward-no-line segment-length)
(M (+ x segment-length))))))
;; right strand
((R x)
(when (< x length)
(let* ((x1 (/ x length))
(w-val (funcall width-func x1))
(c-val (funcall curving-func x1))
(h-val (funcall hcurving-func x1)))
(--> [ (:turn-right 90) (:pitch-down (* hcurving-multiply h-val))
(:forward-mesh-vertex (* width-multiply w-val)) ]
(:pitch-down (* curving-multiply c-val))
(:forward-no-line segment-length)
(R (+ x segment-length))))))
)))
;; ****************************************************
;; *** growth along a 2D curve defined by curvature ***
;; ****************************************************
(defun edit-curvature (&optional eps-filename)
(edit-spline :filename "curvature.spline"
:eps-filename eps-filename))
(defclass spline-curvature (l-system)
((axiom :initform '((A 0.08 0 0) X))
(decomposition-depth :initform 10)
(homomorphism-depth :initform 10)
(limits :initform '((-0.5 0 0) (0.5 1 1)))
(frame-delay :initform 0.01)
(frame-list :initform '((0 10000)))
(spline-pos :accessor spline-pos)
(spline :accessor spline)))
(defun current-curvature (ls)
(let ((spline-func (spline-function (spline ls))))
(funcall spline-func (spline-pos ls))))
(defmethod rewrite :before ((ls spline-curvature) &optional (depth 0))
(declare (ignore depth))
(setf (spline ls) (input-spline "curvature.spline" :make-function t)))
(defmethod rewrite1 :before ((ls spline-curvature))
(setf (spline-pos ls) 0.0))
(defmethod l-productions ((ls spline-curvature))
(let ((spline-func (spline-function (spline ls))))
(flet ((curvature-at (x) (funcall spline-func x)))
(choose-production ls
((A x c1 c2)
(if (>= (spline-pos ls) 1.0)
(--> nil)
(let* ((new-x (* x 1.01))
(pos1 (spline-pos ls))
(pos2 (+ pos1 new-x)))
(when (> pos2 1.0)
(setq pos2 1.0
new-x (- 1.0 pos1)))
(setf (spline-pos ls) pos2)
(let ((curv1 (curvature-at pos1))
(curv2 (curvature-at pos2)))
(--> (A new-x curv1 curv2))))))
))))
(defmethod decomposition ((ls spline-curvature))
(choose-production ls
((A x c1 c2)
(when (> x 0.05)
;; Use "golden ratio" to split segment;
;; the number of segments will then always be
;; a Fibonacci number.
(let* ((factor 0.61803398875)
(x1 (* x factor))
(x2 (* x (- 1 factor))))
(--> (A x1 c1 c2) (A x2 c1 c2)))))))
(defmethod homomorphism ((ls spline-curvature))
(choose-production ls
(X (--> (A 0 0 0)))
((A x c1 c2)
(let* ((curvature1 (* c1 500.0))
(curvature2 (* c2 500.0))
(angle1 (* curvature1 x))
(angle2 (* curvature2 x)))
(--> (+ angle1) [ (:color #(1.0 0.0 0.0))
(:sphere 5.0) ]
(F x) (+ angle2))))))
;; ********************************************************
;; *** Simple twining plant (adapted from Radomir Mech) ***
;; ********************************************************
(defparameter *st-prad* 10)
(defparameter *st-srad* 1)
(defun in-obstacle (pos)
(let ((x (aref pos 0))
(z (aref pos 2))
(p+r (+ *st-prad* *st-srad*)))
(< (+ (* x x) (* z z)) (* p+r p+r))))
(defclass simple-twining (l-system)
((axiom :initform `([ (! ,*st-prad*) (F 350) ]
(! ,*st-srad*) (:color #(0.2 1.0 0.2))
(+ 90) (\f ,(+ *st-srad* *st-prad* 2)) (- 90)
(S 0 0) (A 1 1)))
(angle-increment :initform 1.0)
(line-style :initform :cylinders)
(homomorphism-depth :initform 10)
(limits :initform '((-50 -5 0) (50 400 1)))
(frame-delay :initform 0.1)
(frame-list :initform '((0 10000)))
(mode :accessor mode)
(rotation-point :accessor rotation-point)
))
(defmethod rewrite :before ((ls simple-twining) &optional (depth 1))
(declare (ignore depth))
(setf (mode ls) :grow
(rotation-point ls) 0))
(defmethod rewrite1 :after ((ls simple-twining))
(setf (mode ls) (if (eql (mode ls) :grow)
:test
:grow)))
(defmethod l-productions ((ls simple-twining))
(let ((ADEL 1)
(RSTEP 2))
(if (eql (mode ls) :grow)
;; Grow
(choose-production ls
((A ord delay)
(if (plusp delay)
(--> (A ord (1- delay)))
(--> (S ord 0) (?P nil ord) (A (1+ ord) ADEL))))
((S ord rang)
(when (= ord (rotation-point ls))
(--> (S ord (+ rang RSTEP))))))
;; Test
(choose-production ls
((?P pos ord)
(when (in-obstacle pos)
(setf (rotation-point ls) ord)
(--> (?P nil ord))))))))
(defmethod homomorphism ((ls simple-twining))
(choose-production ls
((S ord rang)
(--> (/ rang) F +))))
(defun simple-twining-povanim ()
(povray-animation (make-instance 'simple-twining)
:full-scene nil
:frames '((100 1400 100))))
;; ******************************
;; *** Twining plant L-system ***
;; ******************************
(defparameter *timesteps-per-hour* 60d0
"Steps per hour of the simulation")
(defparameter *rotation-per-hour* 180d0
"Rotation angle in degrees")
(defparameter *max-segment-length* 1d0
"Maximum length of a stem segment")
(defparameter *grow-area* 20d0
"Length of the stem's grow area from the tip")
(defparameter *turn-curvature* 2d0
"Amount of turning of the stem")
(defparameter *rotation-step* (/ *rotation-per-hour* *timesteps-per-hour*)
"Rotation per timestep")
(defparameter *backtrack-step* (* -0.2d0 *rotation-step*)
"Backtracking step.")
;; Radii
(defparameter *pole-radius* 1.5d0)
(defparameter *stem-radius* 0.3d0)
(defparameter *pole-xpos* 3.0d0
"Pole's x position (y and z position is zero)")
(defparameter *pole-color* #(1.0 0.6 0.4))
(defparameter *stem-color* #(0.5 1.0 0.5))
(defparameter *time-between-leaves* 5d0
"Time in simulated hours between each new leaf forming.")
(defparameter *max-leaf-size* 500 "An integer around 50-500.")
(defun pole-crash (pos)
(let* ((x (aref pos 0))
(z (aref pos 2))
(x1 (- x *pole-xpos*))
(radius (+ *pole-radius* *stem-radius*)))
(< (+ (* x1 x1) (* z z))
(* radius radius))))
(defun edit-growth ()
(edit-spline :filename "growth.spline"))
(defun grow-segment (segment-length stem-position stem-length
spline-function)
(let ((apex-position (- stem-length stem-position)))
(if (> apex-position *grow-area*)
segment-length ;; no growth outside grow area
(let ((funval (funcall spline-function (/ apex-position *grow-area*))))
(+ segment-length
(* segment-length (/ funval *timesteps-per-hour*)))))))
(defclass twining (l-system)
((axiom :initform `([ (:set-width ,*pole-radius*)
(:set-position #(,*pole-xpos* 0 0))
(:color ,*pole-color*)
(:forward 80) ]
(:set-width ,*stem-radius*)
(:color ,*stem-color*)
(:forward 1)
(T ,*max-segment-length* 0 0 0)
(apex 0)))
(decomposition-depth :initform 10)
(homomorphism-depth :initform 10)
(sensitive :initform t)
(consider-list :initform '(T pre-leaf))
(frame-list :initform '((0 10000)))
(frame-delay :initform 0.01)
(line-style :initform :cylinders)
(spline :accessor spline
:initform (input-spline "growth.spline" :make-function t))
(spline-func :accessor spline-func)
(mode :accessor mode)
(rotation-point :accessor rotation-point)
(new-rotation-point :accessor new-rotation-point)
(exit-backtrack :accessor exit-backtrack)
(stem-pos :accessor stem-pos)
(stem-length :accessor stem-length)
))
(defmethod rewrite :before ((ls twining) &optional (depth 0))
(declare (ignore depth))
(setf (mode ls) :grow
(rotation-point ls) 0d0
(new-rotation-point ls) 0d0
(exit-backtrack ls) nil
(spline-func ls) (spline-function (spline ls))
(stem-pos ls) *max-segment-length*))
(defmethod rewrite1 :before ((ls twining))
(when (eq (mode ls) :grow)
(setf (stem-length ls) (stem-pos ls) ; length of the whole stem
(stem-pos ls) 0d0)) ; position after current segment
;(format t "mode: ~A~%" (mode ls))
)
(defmethod rewrite1 :after ((ls twining))
(case (mode ls)
(:grow
(setf (mode ls) :test))
(:test
(setf (mode ls) (if (= (rotation-point ls)
(new-rotation-point ls))
:grow
:backtrack)))
(:backtrack
(when (exit-backtrack ls)
(setf (exit-backtrack ls) nil
(rotation-point ls) (new-rotation-point ls)
(mode ls) :grow))))
;;(format t "depth ~A mode ~A~%" (current-depth ls) (mode ls))
)
(defmethod l-productions ((ls twining))
(case (mode ls)
(:grow
(choose-production ls
((T length position contact-point roll-angle)
(let* ((new-length (grow-segment length position (stem-length ls)
(spline-func ls)))
(old-stem-pos (stem-pos ls))
(stem-pos (+ old-stem-pos new-length)))
(setf (stem-pos ls) stem-pos)
;;(incf (pos ls) new-length)
(if contact-point
(if (< contact-point old-stem-pos)
;; contact point disappears (to the left)
(--> (T new-length old-stem-pos nil nil))
;; contact point remains
(let ((new-rotation (if (= contact-point (rotation-point ls))
(+ roll-angle *rotation-step*)
roll-angle)))
(--> (T new-length old-stem-pos
contact-point new-rotation))))
(progn
;; new contact point from the right
(with-rc ((T rlen rpos rc rangle))
(when (and rc (< rc stem-pos))
(let ((new-rotation (if (= rc (rotation-point ls))
(+ rangle *rotation-step*)
rangle)))
(--> (T new-length old-stem-pos rc new-rotation)))))
;; just growing
(--> (T new-length old-stem-pos nil nil))))))
((apex n)
(if (>= n *time-between-leaves*)
(--> pre-leaf (apex 0))
(--> (apex (+ n (/ 1d0 *timesteps-per-hour*))))))
(pre-leaf
(--> nil))
((?P pos)
(while-considering ls (T leaf pre-leaf)
(with-rc ((T a b c d) pre-leaf)
(--> (?P nil) (leaf 0 0)))))
((leaf size rotation)
(with-rc ((T len pos contact-point rotation-angle))
;; does the leaf pass through a contact point?
(when (and contact-point (< contact-point (stem-pos ls)))
;; yes: update rotation
(incf rotation rotation-angle)))
;; Slowly move leaf rotation back to normal (zero).
;; Looks a bit strange, but it is pretty much the best
;; thing I can do with this model.
;; The X value of (if (< rotation X) ...) decides which way
;; it will turn, 180 is the obvious value, but smaller values
;; may look better in some cases...?
;;(with-rc ((T len pos contact-point rotation-angle))
;; (when (> pos (rotation-point ls))
;; (incf rotation (* 0.5 *rotation-step*))))
(setq rotation (mod rotation 360.0))
(if (< rotation 90.0)
(setq rotation (max 0.0 (- rotation (* *rotation-step* 0.5))))
(setq rotation (min 360.0 (+ rotation (* *rotation-step* 0.5)))))
(--> (leaf (min (+ size 1) *max-leaf-size*) rotation)))
))
(:test
(choose-production ls
((?P pos)
(with-rc ((T length stem-pos cp ra))
;; choose the LOWEST crash point as the new rotation point
(when (and (> stem-pos (+ (rotation-point ls)
(* *max-segment-length* 1.1)))
(= (new-rotation-point ls) (rotation-point ls))
(pole-crash pos))
;(format t "crash! ~A~%" pos)
(setf (new-rotation-point ls) stem-pos))
;; choose the HIGHEST crash point as the new rotation point
#+nil
(when (and (> stem-pos (+ (rotation-point ls)
(* *max-segment-length* 1.1)))
(pole-crash pos))
(setf (new-rotation-point ls) stem-pos))
;; don't need to change any modules, so just return T
t))))
(:backtrack
(choose-production ls
((T length stem-pos cp ra)
(cond ((= stem-pos (new-rotation-point ls))
;;(format t "~A~%" (current-module ls))
;; when the new rotation point is out of obstacle, exit
;; backtrack mode
(while-considering ls (?P T)
(with-lc ((?P pos))
;;(format t "pos ~A~%" pos)
(when (not (pole-crash pos))
;(format t "exit backtracking at ~A~%" pos)
(setf (exit-backtrack ls) t))))
;; insert contact point at new rotation point
(--> (T length stem-pos stem-pos 0)))
((and cp (= cp (rotation-point ls)))
;; backtrack at (old) rotation point
(--> (T length stem-pos cp (+ ra *backtrack-step*))))))))
))
(defmethod decomposition ((ls twining))
(choose-production ls
((T length pos cp ra)
(when (> length *max-segment-length*)
(let* ((length/2 (/ length 2)))
(cond ((null cp)
(--> (T length/2 pos nil nil) (?P nil)
(T length/2 (+ pos length/2) nil nil)))
((< cp (+ pos length/2))
(--> (T length/2 pos cp ra) (?P nil)
(T length/2 (+ pos length/2) nil nil)))
(t
(--> (T length/2 pos nil nil) (?P nil)
(T length/2 (+ pos length/2) cp ra)))))))))
(defmethod homomorphism ((ls twining))
(choose-production ls
((T length pos cp ra)
(if (null cp)
(let ((angle (* length *turn-curvature*)))
(--> (:turn-left angle) (:forward length) (:turn-left angle) S))
(let* ((len1 (- cp pos))
(len2 (- length len1))
(ang1 (* len1 *turn-curvature*))
(ang2 (* len2 *turn-curvature*)))
(--> (:turn-left ang1) (:forward len1) (:turn-left ang1)
(:roll-right ra) S2
(:turn-left ang2) (:forward len2) (:turn-left ang2) S
))))
(S (--> [ (:color #(1 0 0)) (:sphere (* *stem-radius* 1.1)) ]))
(S2 (--> [ (:color #(0 0 1)) (:sphere (* *stem-radius* 1.1)) ]))
((leaf size rotation)
(--> [ (:roll-left (+ 90 rotation)) (:pitch-down 145)
(:color #(0.5 1.0 0.5))
(:set-width 0.1) (:forward (/ (1+ size) 30)) ] ))
))
;; Pretty twining plant (changes homomorphism from TWINING)
;; also contains some code for outputting povray animations
(defclass ptwining (twining)
((frame-count :accessor frame-count)
(frame-list :initform '((0 1600 100)))))
(defmethod rewrite :before ((ls ptwining) &optional (depth 0))
(declare (ignore depth))
(setf (frame-count ls) 0))
(defmethod rewrite1 :after ((ls ptwining))
(when (eql (mode ls) :test)
(incf (frame-count ls))))
(defmethod homomorphism ((ls ptwining))
(choose-production ls
((T length pos cp ra)
(if (null cp)
(let ((angle (* length *turn-curvature*)))
(--> (:turn-left angle) (:forward length) (:turn-left angle) S))
(let* ((len1 (- cp pos))
(len2 (- length len1))
(ang1 (* len1 *turn-curvature*))
(ang2 (* len2 *turn-curvature*)))
(--> (:turn-left ang1) (:forward len1) (:turn-left ang1)
(:roll-right ra) S
(:turn-left ang2) (:forward len2) (:turn-left ang2) S
))))
(S (--> (:sphere *stem-radius*)))
((leaf size rotation)
(let* ((initial-roll 65)
(steps 5)
(forward-per-step (/ (1+ size) steps 70))
(pitch-per-step 20)
(initial-pitch (* pitch-per-step (1- steps) 0.5))
(down-pitch (min (* 300 (/ size *max-leaf-size*))
180)))
(--> [ (:roll-left (+ 90 rotation))
(:pitch-down 90) (:set-width 0.1) (:forward *stem-radius*)
(:pitch-up 90)
(:pitch-down down-pitch)
(:color #(0.5 1.0 0.5))
:start-mesh
[ (:roll-left initial-roll) (:pitch-up initial-pitch)
(mesh-bow pitch-per-step steps forward-per-step) ]
:new-strand
[ (:roll-right initial-roll) (:pitch-up initial-pitch)
(mesh-bow pitch-per-step steps forward-per-step) ]
;;(:set-width 0.1) (:forward (/ (1+ size) 30)) ] ))
:end-mesh ] )))
((mesh-bow p steps len)
(when (> steps 0)
(--> (:forward-mesh-vertex len) (:pitch-down p)
(mesh-bow p (1- steps) len))))
))
(defun twining-povanim (&optional (nframes nil))
(let ((ls (make-instance 'ptwining)))
(rewrite ls 0)
(do* ((framelist (copy-tree (or nframes (frame-list ls)))))
((null framelist) :done)
(let* ((frame (extract-framelist framelist))
(filename (format nil "twining~A.pov" frame)))
(loop until (<= frame (frame-count ls))
do (rewrite1 ls))
(create-geometry ls)
(format t "Outputting '~A'..." filename)
(force-output)
(output-povray (geometry ls) filename
:full-scene nil
:width-multiplier 1.0)
(format t "done.~%")))))
| 21,122 | Common Lisp | .lisp | 574 | 32.090592 | 77 | 0.593706 | cbaggers/l-lisp | 11 | 2 | 2 | GPL-2.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | d0c249adc16718ca8ff446e2309cf0f001b2ae9e777a2a9e0371a11a76de0677 | 7,938 | [
-1
] |
7,939 | opengl.lisp | cbaggers_l-lisp/opengl.lisp | ;;; *** opengl.lisp ***
;;;
;;; This file is part of L-Lisp by Knut Arild Erstad.
;;; Contains code for OpenGL previews and animations of L-systems
(in-package :l-systems)
;; Load the allegro-xlib-and-gl Xlib/OpenGL bindings by Richard Mann
;; A CMUCL port is available from http://www.ii.uib.no/~knute/lisp/
;; Note: this has been untested a long time
#+allegro
(eval-when (:compile-toplevel :load-toplevel)
(require :gl)
(require :xlib))
#+(or cmu sbcl)
(eval-when (:compile-toplevel :load-toplevel)
(require :cmucl-xlib-and-gl))
;; global GLX variables
(defvar *display* nil)
(defvar *glxcontext* nil)
;;(defvar *window*)
(defstruct (l-window (:conc-name lw-))
;; Xlib/GL variables
display
window
;; L-system
ls
;; line/cylinder settings
(cylinder-width 1.0d0)
(line-width 1.0d0)
(line-style :lines)
(cylinder-slices 8)
;; view settings
minv maxv zoom width height rotate-angle tilt-angle
recenter
(angle-inc 0.1d0)
(zoom-exp 1.002d0)
;; light settings
(enable-lighting t)
light-pos
;; animation settings
animate
frame-delay
original-frame-list
frame-list
clock
)
;; "Callbacks" (not really callbacks, more like event handling functions)
(defun gl-initialize (l-win)
(let* ((ls (lw-ls l-win))
(geometry (geometry ls)))
;; initialize values
(multiple-value-bind (minv maxv)
(find-limits geometry)
(setf (lw-minv l-win) minv)
(setf (lw-maxv l-win) maxv))
(setf (lw-zoom l-win) 1.1d0)
(setf (lw-rotate-angle l-win) 0d0)
(setf (lw-tilt-angle l-win) 0d0)
;; light
(when (lw-enable-lighting l-win)
(setf (lw-light-pos l-win)
(make-array 4 :element-type #-cmu 'fixnum #+cmu '(signed-byte 32)
:initial-contents '#(0 1 0 0)))
(gl:glEnable gl:GL_LIGHTING)
(gl:glLightModeli gl:GL_LIGHT_MODEL_TWO_SIDE 1)
;;(gl:glLightModelf gl:GL_LIGHT_MODEL_LOCAL_VIEWER 0.3)
(let ((ambient (make-array 4 :element-type 'single-float
:initial-contents #(0.2 0.2 0.2 1.0))))
(gl:glLightModelfv gl:GL_LIGHT_MODEL_AMBIENT ambient))
(gl:glEnable gl:GL_LIGHT0))
;; OpenGL init
(gl:glDepthFunc gl:GL_LESS)
(gl:glEnable gl:GL_DEPTH_TEST)
))
(defun gl-reshape (l-win width height)
(setf (lw-width l-win) width)
(setf (lw-height l-win) height)
(let* ((debug nil)
(minv (lw-minv l-win))
(maxv (lw-maxv l-win))
(zoom (lw-zoom l-win))
(x1 (aref minv 0))
(x2 (aref maxv 0))
(xcenter (/ (+ x1 x2) 2))
(xsize (max (* (- x2 x1) zoom) 1d-5))
(y1 (aref minv 1))
(y2 (aref maxv 1))
(ycenter (/ (+ y1 y2) 2))
(ysize (max (* (- y2 y1) zoom) 1d-5))
(z1 (aref minv 2))
(z2 (aref maxv 2))
(zcenter (/ (+ z1 z2) 2))
(zsize (max (* (- z2 z1) zoom) 1d-10))
(geometry-aspect (/ xsize ysize))
(viewport-aspect (/ width height)))
(when debug (format t "xsize ~A ysize ~A~%" xsize ysize))
;; increase either xsize or ysize, depending on aspect
(if (> geometry-aspect viewport-aspect)
(setq ysize (/ xsize viewport-aspect))
(setq xsize (* ysize viewport-aspect)))
(when debug (format t "after: xsize ~A ysize ~A~%" xsize ysize))
(let ((half-x (/ xsize 2))
(half-y (/ ysize 2))
(z-inc (* 2 (max xsize ysize zsize))))
(gl:glViewport 0 0 width height)
(gl:glMatrixMode gl:GL_PROJECTION)
(gl:glLoadIdentity)
(gl:glOrtho (- half-x) half-x
(- half-y) half-y
(- z-inc) z-inc)
(gl:glMatrixMode gl:GL_MODELVIEW)
(gl:glLoadIdentity)
;; rotate model
(gl:glRotated (lw-tilt-angle l-win) 1d0 0d0 0d0)
(gl:glRotated (lw-rotate-angle l-win) 0d0 1d0 0d0)
;; move it to center of the window
(gl:glTranslated (- xcenter) (- ycenter) (- zcenter))
)))
(defvar *black* (make-array 4 :element-type 'single-float
:initial-contents '#(0.0 0.0 0.0 1.0)))
(defun gl-set-color (l-win color)
(let ((col (or color *black*)))
(if (lw-enable-lighting l-win)
(gl:glMaterialfv gl:GL_FRONT_AND_BACK
gl:GL_AMBIENT_AND_DIFFUSE
col)
(gl:glColor4fv col))))
(defmethod gl-code (l-win elt)
(declare (ignore l-win))
(warn "Unkown type ~A passed to GL-CODE." (type-of elt)))
(defmethod gl-code (l-win (line line))
(case (lw-line-style l-win)
;; *** lines ***
(:lines
(let* ((color (line-color line))
(width (line-width line))
(w (* (lw-line-width l-win) (or width 1.0d0)))
(p1 (line-p1 line))
(p2 (line-p2 line)))
;; set color
(gl-set-color l-win color)
;; set linewidth
(gl:glLineWidth (coerce w 'single-float))
;; draw line
(gl:glBegin gl:GL_LINES)
(gl:glVertex3dv p1)
(gl:glVertex3dv p2)
(gl:glEnd)
))
;; *** cylinders ***
(:cylinders
(let ((p1 (line-p1 line))
(p2 (line-p2 line)))
(unless (equalvec p1 p2)
(let* ((color (line-color line))
(width (line-width line))
(prev-width (line-prev-width line))
(w1 (coerce (or prev-width width 1d0) 'double-float))
(w2 (coerce (or width 1d0) 'double-float))
;;(p1 (line-p1 line))
;;(p2 (line-p2 line))
(hvec (vec- p2 p1))
(height (vlength hvec))
(zvec (vec3 0d0 0d0 1d0))
(rvec (cross-product zvec (normalize hvec)))
(dot (aref hvec 2)) ;; [0 0 1] dot hvec = hvec[2]
(rad-angle (acos dot))
(deg-angle (rad-to-deg rad-angle))
(cylinder-width (lw-cylinder-width l-win))
;;quad)
(quad (gl:gluNewQuadric)))
(declare (optimize (speed 3)
#+cmu (ext:inhibit-warnings 3))
(type (simple-array double-float (3))
p1 p2 hvec zvec rvec)
(double-float w1 w2 dot rad-angle deg-angle
cylinder-width))
;; set color
(gl-set-color l-win color)
;; push matrix
(gl:glPushMatrix)
;; translate to p1
(gl:glTranslated (aref p1 0) (aref p1 1) (aref p1 2))
;; rotate to hvec
(gl:glRotated deg-angle (aref rvec 0) (aref rvec 1) (aref rvec 2))
;; now the cylinder can be created
(gl:gluQuadricNormals quad gl:GLU_SMOOTH)
(gl:gluQuadricDrawStyle quad gl:GLU_FILL)
(gl:gluCylinder quad
(* w1 cylinder-width) (* w2 cylinder-width)
height (lw-cylinder-slices l-win) 1)
;; deallocate quad
(gl:gluDeleteQuadric quad)
(gl:glPopMatrix)))))
(t
(error "Unknown LINE-STYLE ~A, should be :LINES or :CYLINDERS."
(lw-line-style l-win))))
)
(defmethod gl-code (l-win (sphere sphere))
(gl-set-color l-win (sphere-color sphere))
(case (lw-line-style l-win)
(:cylinders
(let ((pos (sphere-pos sphere))
(radius (sphere-radius sphere))
(quad (gl:gluNewQuadric))
(cylinder-width (lw-cylinder-width l-win)))
(declare (optimize (speed 3) (safety 0))
(double-float radius cylinder-width)
(type (simple-array double-float (3)) pos))
(gl:glPushMatrix)
(gl:glTranslated (aref pos 0) (aref pos 1) (aref pos 2))
(gl:gluQuadricNormals quad gl:GLU_SMOOTH)
(gl:gluQuadricDrawStyle quad gl:GLU_FILL)
(let* ((slices (lw-cylinder-slices l-win))
(stacks (round slices 2)))
(gl:gluSphere quad
(* cylinder-width radius)
slices stacks))
(gl:gluDeleteQuadric quad)
(gl:glPopMatrix)))
(:lines
(let ((w (* (sphere-radius sphere) (or (lw-line-width l-win) 1.0d0))))
(gl:glPointSize (coerce w 'single-float))
(gl:glBegin GL:GL_POINTS)
(gl:glVertex3dv (sphere-pos sphere))
(gl:glEnd)))))
(defmethod gl-code (l-win (polygon polygon))
(gl-set-color l-win (polygon-color polygon))
(gl:glNormal3dv (polygon-normal polygon))
(gl:glBegin gl:GL_POLYGON)
(dolist (p (polygon-points polygon))
;;(declare (optimize (speed 3)))
;;(declare (type (simple-array double-float (3)) p))
(gl:glVertex3d (aref p 0) (aref p 1) (aref p 2)))
;;(gl:glVertex3dv p))
(gl:glEnd))
(defmethod gl-code (l-win (mesh mesh))
(gl-set-color l-win (mesh-color mesh))
(gl:glBegin gl:GL_TRIANGLES)
(dolist (triangle (mesh-triangles mesh))
(dolist (vertex (triangle-vertices triangle))
(gl:glNormal3dv (vertex-normal vertex))
(gl:glVertex3dv (vertex-pos vertex))))
(gl:glEnd))
(defmethod gl-code (l-win (box box))
(gl-set-color l-win (box-color box))
(let* ((pos1 (box-pos box))
(pos2 (vec+ pos1 (box-size box)))
(x1 (aref pos1 0))
(y1 (aref pos1 1))
(z1 (aref pos1 2))
(x2 (aref pos2 0))
(y2 (aref pos2 1))
(z2 (aref pos2 2)))
;; A box is six rectangles (polygons)...
;; 1: z = z1, normal = -Z
(gl:glBegin gl:GL_POLYGON)
(gl:glNormal3i 0 0 -1)
(gl:glVertex3d x1 y1 z1)
(gl:glVertex3d x1 y2 z1)
(gl:glVertex3d x2 y2 z1)
(gl:glVertex3d x2 y1 z1)
(gl:glEnd)
;; 2: z = z2, normal = Z
(gl:glBegin gl:GL_POLYGON)
(gl:glNormal3i 0 0 1)
(gl:glVertex3d x1 y1 z2)
(gl:glVertex3d x1 y2 z2)
(gl:glVertex3d x2 y2 z2)
(gl:glVertex3d x2 y1 z2)
(gl:glEnd)
;; 3: y = y1, normal = -Y
(gl:glBegin gl:GL_POLYGON)
(gl:glNormal3i 0 -1 0)
(gl:glVertex3d x1 y1 z1)
(gl:glVertex3d x1 y1 z2)
(gl:glVertex3d x2 y1 z2)
(gl:glVertex3d x2 y1 z1)
(gl:glEnd)
;; 4: y = y2, normal = Y
(gl:glBegin gl:GL_POLYGON)
(gl:glNormal3i 0 1 0)
(gl:glVertex3d x1 y2 z1)
(gl:glVertex3d x1 y2 z2)
(gl:glVertex3d x2 y2 z2)
(gl:glVertex3d x2 y2 z1)
(gl:glEnd)
;; 5: x = x1, normal = -X
(gl:glBegin gl:GL_POLYGON)
(gl:glNormal3i -1 0 0)
(gl:glVertex3d x1 y1 z1)
(gl:glVertex3d x1 y1 z2)
(gl:glVertex3d x1 y2 z2)
(gl:glVertex3d x1 y2 z1)
(gl:glEnd)
;; 6: x = x2, normal = X
(gl:glBegin gl:GL_POLYGON)
(gl:glNormal3i 1 0 0)
(gl:glVertex3d x2 y1 z1)
(gl:glVertex3d x2 y1 z2)
(gl:glVertex3d x2 y2 z2)
(gl:glVertex3d x2 y2 z1)
(gl:glEnd)
))
(defun gl-draw (l-win)
(let* ((ls (lw-ls l-win))
(geometry (geometry ls)))
;; initialization
(gl:glClearColor 1.0 1.0 1.0 0.0)
(gl:glClear (+ gl:GL_COLOR_BUFFER_BIT
gl:GL_DEPTH_BUFFER_BIT))
(gl:glPushMatrix)
(gl:glColor3f 0.0 0.0 0.0)
(gl:glLightiv gl:GL_LIGHT0 gl:GL_POSITION (lw-light-pos l-win))
(dotimes (i (length geometry))
(gl-code l-win (aref geometry i)))
(gl:glPopMatrix)
(gl:glxswapbuffers (lw-display l-win) (lw-window l-win))))
(defun gl-mousemotion (l-win x y state)
(let ((debug nil)
(width (lw-width l-win))
(height (lw-height l-win))
(angle-inc (lw-angle-inc l-win)))
(when debug (format t "Mouse motion relative (~A ~A) " x y))
(unless (zerop (boole boole-and state xlib-gl:Button1Mask))
(when debug (write-line "while button 1 down."))
(incf (lw-rotate-angle l-win) (* x angle-inc))
(when (< (lw-rotate-angle l-win) 0d0)
(incf (lw-rotate-angle l-win) 360d0))
(when (>= (lw-rotate-angle l-win) 360d0)
(decf (lw-rotate-angle l-win) 360d0))
(when debug (format t "New rotate-angle ~A~%"
(lw-rotate-angle l-win)))
(incf (lw-tilt-angle l-win) (* y angle-inc))
(when (< (lw-tilt-angle l-win) -89.9d0)
(setf (lw-tilt-angle l-win) -89.9d0))
(when (> (lw-tilt-angle l-win) 89.9d0)
(setf (lw-tilt-angle l-win) 89.9d0))
;; update viewport and redraw
(gl-reshape l-win width height)
(gl-draw l-win))
(unless (zerop (boole boole-and state xlib-gl:Button2Mask))
;; button 2: zooming
(when debug (write-line "while button 2 down."))
(setf (lw-zoom l-win)
(* (lw-zoom l-win) (expt (lw-zoom-exp l-win) y)))
(gl-reshape l-win width height)
(gl-draw l-win))
))
(defun current-clock ()
(/ (get-internal-real-time)
internal-time-units-per-second))
(defun gl-animate (l-win)
(let ((ls (lw-ls l-win))
(frame-delay (lw-frame-delay l-win)))
;; if frame list is empty, end animation
(when (null (lw-frame-list l-win))
(setf (lw-animate l-win) nil)
(return-from gl-animate nil))
;; if frame delay not reached, return
(let ((newclock (current-clock)))
(when (< (- newclock (lw-clock l-win)) frame-delay)
(return-from gl-animate nil))
(setf (lw-clock l-win) newclock))
;; extract from framelist and do the necessary number of rewrites
(do ((num (extract-framelist (lw-frame-list l-win))))
((>= (current-depth ls) num))
(rewrite1 ls)
(when (sensitive ls) (create-geometry ls)))
;; create geometry
(when (null (geometry ls))
(create-geometry ls))
;; maybe find new limits
(when (lw-recenter l-win)
;(format t "recentering~%")
(multiple-value-bind (minv maxv)
(find-limits (geometry ls))
(setf (lw-minv l-win) minv)
(setf (lw-maxv l-win) maxv))
(gl-reshape l-win (lw-width l-win) (lw-height l-win)))
;; draw it
;;(gl-draw l-win)))
(send-expose-event l-win)))
(defun gl-keypress (l-win char)
(case char
;; A : Toggle animate
(#\a (setf (lw-animate l-win) (not (lw-animate l-win))))
;; R : Restart animation
(#\r
(setf (lw-animate l-win) nil)
(setf (lw-frame-list l-win)
(copy-tree (lw-original-frame-list l-win)))
(let ((ls (lw-ls l-win)))
(rewrite ls (extract-framelist (lw-frame-list l-win)))
(when (null (geometry ls))
(create-geometry ls)))
(gl-draw l-win))
;; P : Output povray
(#\p
(let* ((ls (lw-ls l-win))
(class-name (class-name (class-of ls)))
(name (string-downcase (symbol-name class-name)))
(filename (concatenate 'string name ".pov"))
(width (or (lw-cylinder-width l-win) 1.0)))
(format t "Writing file '~A'...~%" filename)
(output-povray (geometry ls) filename :width-multiplier width
:full-scene nil)
(format t "Done.~%")))
;; Q : Quit
(#\q :quit)
))
(defun gl-geometry-loop (l-win)
(setf (lw-clock l-win) (current-clock))
;; event loop
(let ((event (xlib-gl:make-xevent))
(xpos nil)
(ypos nil)
(debug nil)
(display (lw-display l-win)))
(loop
;; if in animation mode, animate until event occurs
(when (lw-animate l-win)
(when debug (format t "Animate..."))
(loop
(gl-animate l-win)
(when (or (> (xlib-gl:xpending display) 0)
(not (lw-animate l-win)))
(return))))
;; wait for event
(when debug (format t "Waiting for event...~%"))
(xlib-gl:xnextevent display event)
(when debug (format t "...event~%"))
(let ((event-type (xlib-gl:xanyevent-type event)))
(when debug (format t "Event: ~A~%" event-type))
;; process event
(cond
((eq event-type xlib-gl:expose)
(when debug (format t "(expose)~%"))
;; expose
;; gobble other expose events
(loop (when (zerop (xlib-gl:xpending display))
(return))
(xlib-gl:xnextevent display event)
(let ((event-type (xlib-gl:xanyevent-type event)))
(unless (eq event-type xlib-gl:expose)
(xlib-gl:xputbackevent display event)
(return))))
;; ... draw after expose
(gl-draw l-win))
((eq event-type xlib-gl:configurenotify)
;; resize
(when debug (format t "(resize)~%"))
(gl-reshape l-win
(xlib-gl:xconfigureevent-width event)
(xlib-gl:xconfigureevent-height event)))
((eq event-type xlib-gl:buttonpress)
(when debug (format t "(buttonpress)~%"))
;; button press--save position
(let ((button (xlib-gl:xbuttonevent-button event)))
(when debug (format t "Button: ~A~%" button))
(setq xpos (xlib-gl:xbuttonevent-x_root event))
(setq ypos (xlib-gl:xbuttonevent-y_root event))
(when debug (format t "pos ~A ~A~%" xpos ypos))
(cond
((eq button xlib-gl:button3)
(return)))))
((eq event-type xlib-gl:motionnotify)
;; mouse moved
(when debug (format t "(mousemotion)~%"))
(let ((new-xpos (xlib-gl:xmotionevent-x_root event))
(new-ypos (xlib-gl:xmotionevent-y_root event))
(state (xlib-gl:xmotionevent-state event)))
;; gobble motion events with same state
(loop (when (zerop (xlib-gl:xpending display))
(return))
(xlib-gl:xnextevent display event)
(let ((event-type (xlib-gl:xanyevent-type event)))
;; if we have the same type of event
(if (and (eq event-type xlib-gl:motionnotify)
(= (xlib-gl:xmotionevent-state event) state))
;; then gobble it
(progn
(setq new-xpos (xlib-gl:xmotionevent-x_root event))
(setq new-ypos (xlib-gl:xmotionevent-y_root event)))
;; else put it back and jump out of the loop
(progn
(xlib-gl:xputbackevent display event)
(return)))))
(when debug (format t "Motion: state ~A pos ~A ~A~%"
state xpos ypos))
(when xpos
(gl-mousemotion l-win
(- new-xpos xpos) (- new-ypos ypos)
state))
(setq xpos new-xpos)
(setq ypos new-ypos)))
((eq event-type xlib-gl:keypress)
;; keypress
(when debug (format t "(keypress)~%"))
(let* ((keysym (xlib-gl:xlookupkeysym event 0))
(char (if (< keysym 256) (code-char keysym) nil)))
(when debug (format t "keysym ~A char ~A~%" keysym char))
(when (= keysym xlib-gl:XK_Escape)
(return))
(when char
(let ((answer (gl-keypress l-win char)))
(when (eq answer :quit) (return))))))
)))
(xlib-gl:free-xevent event)))
(defun send-expose-event (l-win)
(let ((display (lw-display l-win))
(window (lw-window l-win))
(event (xlib-gl:make-xexposeevent)))
(unwind-protect
(progn (xlib-gl:set-xanyevent-type! event xlib-gl:expose)
(xlib-gl:set-xanyevent-serial! event 0)
(xlib-gl:set-xanyevent-send_event! event 0)
(xlib-gl:set-xanyevent-display! event display)
(xlib-gl:set-xanyevent-window! event window)
(xlib-gl:xsendevent display window 0 xlib-gl:ExposureMask event))
(xlib-gl:free-xexposeevent event))))
(defun create-gl-window (display width height name)
;; Create a double buffered, RGBA window
(let* ((screen (xlib-gl:XDefaultScreen display))
(root (xlib-gl:XRootWindow display screen))
;; array of integers, terminated by "None"
(attrib (make-array 11
:element-type
#+cmu '(signed-byte 32) #-cmu 'fixnum
:initial-contents
(list gl:GLX_RGBA
gl:GLX_RED_SIZE 4 gl:GLX_GREEN_SIZE 4
gl:GLX_BLUE_SIZE 4 gl:GLX_DEPTH_SIZE 4
gl:GLX_DOUBLEBUFFER
xlib-gl:None)))
(visinfo (gl:glXChooseVisual display screen attrib)))
(when (zerop visinfo)
(error
"CREATE-GL-WINDOW: Could not get an RGBA, double-buffered visual."))
(let ((attr (xlib-gl:make-xsetwindowattributes)))
(xlib-gl:set-xsetwindowattributes-background_pixel! attr 0)
(xlib-gl:set-xsetwindowattributes-border_pixel! attr 0)
(xlib-gl:set-xsetwindowattributes-colormap!
attr (xlib-gl:XCreateColormap display root
(xlib-gl:XVisualInfo-visual visinfo)
xlib-gl:AllocNone))
(xlib-gl:set-xsetwindowattributes-event_mask!
attr (+ xlib-gl:StructureNotifyMask xlib-gl:ExposureMask
xlib-gl:ButtonPressMask xlib-gl:ButtonReleaseMask
xlib-gl:Button1MotionMask xlib-gl:Button2MotionMask
xlib-gl:KeyPressMask))
(let* ((mask (+ xlib-gl:CWBackPixel xlib-gl:CWBorderPixel
xlib-gl:CWColormap xlib-gl:CWEventMask))
(window (xlib-gl:XCreateWindow display root 0 0 width height
0
(xlib-gl:XVisualInfo-depth visinfo)
xlib-gl:InputOutput
(xlib-gl:XVisualInfo-visual visinfo)
mask attr))
;;(context (gl:glXCreateContext display visinfo xlib-gl:NULL 1)))
(context (setq *glxcontext* (gl:glXCreateContext
display visinfo xlib-gl:NULL 1))))
(gl:glXMakeCurrent display window context)
(xlib-gl:XStoreName display window name)
(xlib-gl:XMapWindow display window)
window))))
(defun gl-show-geometry (l-win
&key
(width nil)
;;(line-style :lines)
;;(lighting t)
(limits nil)
(window-width 400)
(window-height 400))
(unwind-protect
(progn
;; open display/window
(unless *display* (setq *display* (xlib-gl:xopendisplay "")))
(let ((window (create-gl-window *display* window-width window-height
"L-Lisp OpenGL window")))
;; (setq *window* (create-gl-window *display* 300 300
;; "L-lisp OpenGL window"))
;; fill in some values in l-win
(setf (lw-display l-win) *display*
(lw-window l-win) window))
(let ((cyl-width (cylinder-width (lw-ls l-win))))
(when cyl-width
(setf (lw-cylinder-width l-win)
(coerce cyl-width 'double-float))))
(when width
(if (eq (lw-line-style l-win) :lines)
(setf (lw-line-width l-win) (coerce width 'double-float))
(setf (lw-cylinder-width l-win) (coerce width 'double-float))))
;; make sure geometry exists
(let ((ls (lw-ls l-win)))
(when (null (geometry ls))
(create-geometry ls)))
;; initialize limits and OpenGL
(gl-initialize l-win)
;; override limits
(when limits
(flet ((map-double (seq) (map '(simple-array double-float (*))
#'(lambda (x) (coerce x 'double-float))
seq)))
(setf (lw-minv l-win) (map-double (first limits))
(lw-maxv l-win) (map-double (second limits)))))
;; start event loop
(gl-geometry-loop l-win))
;; always cleanup and exit
(let ((event (xlib-gl:make-xevent))
(display (lw-display l-win))
(window (lw-window l-win)))
(gl:glXDestroyContext display *glxcontext*)
(xlib-gl:xdestroywindow display window)
(loop (when (zerop (xlib-gl:xpending display)) (return))
(xlib-gl:xnextevent display event))
(xlib-gl:free-xevent event))))
(defun gl-animation (ls
&key
(width nil)
(line-style (line-style ls))
(cylinder-slices (cylinder-slices ls))
(lighting t)
(limits (limits ls))
(recenter nil)
(frame-delay (frame-delay ls))
(instant-animate t)
;;(frames `((0 ,(depth ls)))))
(frames (or (frame-list ls)
`((0 ,(depth ls)))))
(window-width 400)
(window-height 400))
(let ((l-win (make-l-window :ls ls
:line-style line-style
:cylinder-slices cylinder-slices
:enable-lighting lighting
:animate instant-animate
:recenter recenter
:original-frame-list frames
:frame-list (copy-tree frames)
:frame-delay frame-delay)))
(rewrite ls (extract-framelist (lw-frame-list l-win)))
(gl-show-geometry l-win :width width :limits limits
:window-width window-width
:window-height window-height)))
(defun gl-preview (ls
&key
(width nil)
(line-style (line-style ls))
(cylinder-slices (cylinder-slices ls))
(depth (depth ls))
(lighting t)
(limits (limits ls))
(window-width 400)
(window-height 400))
(when (and (null width) (eq line-style :cylinders))
(setq width (cylinder-width ls)))
(gl-animation ls :width width :line-style line-style
:cylinder-slices cylinder-slices
:lighting lighting :limits limits
:instant-animate nil
:frames (list depth)
:window-width window-width
:window-height window-height))
| 26,864 | Common Lisp | .lisp | 663 | 29.393665 | 81 | 0.536372 | cbaggers/l-lisp | 11 | 2 | 2 | GPL-2.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | fa9fe6ef0d41a0992e13c3c92f2cf7779c8db843047cf57b30d864d60c2125e5 | 7,939 | [
-1
] |
7,940 | lsystem.lisp | cbaggers_l-lisp/lsystem.lisp | ;;; *** lsystem.lisp ***
;;;
;;; This file is part of L-Lisp by Knut Arild Erstad.
;;; Contains the basic L-systems framework, including:
;;; - L-system rewriting
;;; - Homomorphism/decomposition rewriting
;;; - Context matching
;;; - Macros for productions and context sensitivity
(in-package :l-systems)
(defclass l-system ()
;;"The base class for L-systems--not to be used directly."
((axiom
:accessor axiom
:initform nil
:documentation "Axiom/initiator: sequence of modules/symbols")
(depth
:accessor depth
:initform 0
:documentation "Depth: (max) number of rewrites.")
(angle-increment
:accessor angle-increment
:initform 90.0
:documentation "Default angle increment (passed along to turtle).")
(ignore-list
:accessor ignore-list
:initform nil
:documentation "List of symbols to ignore in context.")
(consider-list
:accessor consider-list
:initform nil
:documentation
"List of symbols to consider in context (overrides ignore-list).")
(homomorphism-depth
:accessor homomorphism-depth
:initform 0
:documentation "Max depth of the homomorphism tree.")
(decomposition-depth
:accessor decomposition-depth
:initform 0
:documentation "Max depth of the decomposition tree.")
(sensitive
:accessor sensitive
:initform t
:documentation "Boolean: set to nil to optimize non-environmentally
sensitivite L-systems.")
;; The rewriting strings RSTRING and HSTRING (vectors, actually) should
;; not be set explicitly. Neither should GEOMETRY.
(rstring
:accessor rstring
:initform nil
:documentation "Rewrite string: vector of modules.")
(hstring
:accessor hstring
:initform nil
:documentation "Homomorphism rewriting string: vector of modules.")
(geometry
:accessor geometry
:initform nil
:documentation "3D Geometry created by turtle interpretation.")
(current-depth
:accessor current-depth
:initform nil
:documentation "The number of the current/latest rewrite.")
;; Graphical view/animation parameters (for OpenGL)
(line-style
:accessor line-style
:initform :lines
:documentation "Either :LINES or :CYLINDERS.")
(cylinder-width
:accessor cylinder-width
:initform 1.0d0
:documentation "Width multiplier for cylinders.")
(cylinder-slices
:accessor cylinder-slices
:initform 8
:documentation "Number of slices around cylinders.")
(limits
:accessor limits
:initform nil
:documentation "List of two positions vectors/sequences.")
(frame-delay
:accessor frame-delay
:initform 0.5
:documentation "Delay between animation frames, in seconds.")
(frame-list
:accessor frame-list
:initform nil
:documentation "List of frames and frame intervals (nested lists).")
;; The rest of the slots are for internal use
(current-module
:accessor current-module
:initform nil
:documentation "Current module: used internally during rewriting.")
(pos
:accessor pos
:type fixnum
:initform 0
:documentation "Position: used internally during context checking.")
(context-pos
:accessor context-pos
:type fixnum
:initform 0
:documentation "Used internally during context checking.")
(warning-msg
:accessor warning-msg
:initform nil
:documentation "Used internally to keep track of warnings.")
))
;; *** Methods that should be overridden ***
(defmethod l-productions ((ls l-system))
"Override this when creating L-systems of greater depth than 0."
t)
(defmethod homomorphism ((ls l-system))
"Override this when creating L-systems with homomorphism."
t)
(defmethod decomposition ((ls l-system))
"Override this when creating L-systems with decomposition."
t)
;; *** Helper functions ***
(defun add-bracket-params (vec)
"Add positions of matching brackets as parameters."
(declare (type simple-vector vec))
(let ((bracket-positions nil))
(dotimes (pos (length vec) vec)
(declare (optimize (speed 3) (safety 0))
(type fixnum pos))
(let* ((module (svref vec pos))
(symbol (if (consp module) (first module) module)))
(case symbol
(\[ (push pos bracket-positions))
(\] (let ((bpos (pop bracket-positions)))
(setf (svref vec bpos) (list '\[ pos)
(svref vec pos) (list '\] bpos)))))))))
(defun rlist->vector (rlist length)
"Convert a reverse list RLIST of given length LENGTH to a simple-vector."
(declare (optimize (speed 3) (safety 0))
(fixnum length))
(let ((vec (make-array length)))
(dolist (elt rlist)
(setf (svref vec (decf length)) elt))
vec))
;; *** Rewriting ***
(defmethod rewrite ((ls l-system) &optional (depth (depth ls)))
"Initialize the rewriting string and rewrite DEPTH times.
If DEPTH is 0, the rewriting string is initialized with the axiom,
but no rewriting is done."
;; intialize some slots
(setf (geometry ls) nil)
(setf (current-depth ls) 0)
;; init rstring with the axiom
;;(setf (rstring ls) (apply #'vector (axiom ls)))
(setf (rstring ls) (map 'simple-vector #'copy-tree (axiom ls)))
(add-bracket-params (rstring ls))
;; for enviro-sensitive systems, create geometry
(if (sensitive ls) (create-geometry ls))
;; do the rewrites
(dotimes (i depth)
(rewrite1 ls))
;;(if (sensitive ls) (create-geometry ls)))
(rstring ls))
(defun skip-to-right-bracket (rstring pos)
"Skip to next unmatched ']', and return the new position,
or NIL if there is no unmatched ']'."
;; Note: this could be optimized, but is probably fast enough
(let ((i pos)
(len (length rstring)))
(loop
(when (>= i len)
(return nil))
(let* ((module (svref rstring i))
(symbol (if (consp module) (first module) module)))
(cond ((eql symbol '\[)
(setq i (1+ (skip-to-right-bracket rstring (1+ i)))))
((eql symbol '\])
(return i))
(t
(incf i)))))))
(defmethod rewrite1 ((ls l-system))
"Do a single rewrite of the L-system.
This includes a decomposition rewrite if DECOMPOSITION-DEPTH > 0."
;; If geometry exists, remove it
(setf (geometry ls) nil)
;; Update current-depth
(incf (current-depth ls))
;; Use a buffer to fill in new string
(let* ((oldstr (rstring ls))
;;(strlength (length oldstr))
(newstr (make-buffer)))
(dotimes (pos (length oldstr))
(declare (optimize (speed 3) (safety 0))
(type simple-vector oldstr)
(type fixnum pos))
(setf (pos ls) pos)
(let ((module (svref oldstr pos)))
;; check for cut symbol
(when (member module '(\% :cut-symbol) :test #'eq)
(let ((jump-pos (skip-to-right-bracket oldstr pos)))
(if jump-pos
(setf pos jump-pos
(pos ls) jump-pos
module (svref oldstr pos))
(return))))
(setf (current-module ls) module)
(let ((answer (l-productions ls)))
(if (eq answer t)
;; T means identity production (no change)
(buffer-push module newstr)
;; otherwise we should have a list
(dolist (obj answer)
;; add all non-nil objects to new rstring
(unless (null obj)
(buffer-push obj newstr)))))))
;; convert buffer to simple-vector
(setf (rstring ls) (buffer->vector newstr))
;; set some other slots
(setf (pos ls) 0
(current-module ls) nil)
;; do decomposition if it exists
(when (> (decomposition-depth ls) 0)
(decomposition-rewrite ls))
;; add bracket parameters (for context checking in next step)
(add-bracket-params (rstring ls))
;; create geometry if it is environmentally sensitive
(when (sensitive ls)
(create-geometry ls))
;; return new rstring
(rstring ls)))
(defun tree-rewrite (ls production-func max-depth)
"Common algorithm for homomorphism and decomposition (a bit like
Chomsky grammar rewriting)."
(let* ((oldstr (rstring ls))
(strlength (length oldstr))
(newstring (make-buffer)))
(labels ((expand-module (max-depth)
(declare (optimize (speed 3) (safety 0))
(type fixnum max-depth)
(type compiled-function production-func))
(if (= max-depth 0)
(progn (when (not (warning-msg ls))
(setf (warning-msg ls) "Maximum depth reached."))
(buffer-push (current-module ls) newstring))
(let ((x (funcall production-func ls)))
(if (eq x t)
(buffer-push (current-module ls) newstring)
(dolist (obj x)
(setf (current-module ls) obj)
(expand-module (1- max-depth))))))))
(dotimes (pos strlength)
(declare (optimize (speed 3) (safety 0))
(type fixnum pos))
(setf (current-module ls) (svref oldstr pos))
(expand-module max-depth)))
(buffer->vector newstring)))
;; *** Homomorphism rewriting ***
(defmethod homomorphism-rewrite ((ls l-system))
"Do a homomorphism (visual) rewrite from the current rewriting string."
(let ((newstr (tree-rewrite ls #'homomorphism
(homomorphism-depth ls))))
(when (warning-msg ls)
(format t "Homomorphism warning: ~A" (warning-msg ls))
(setf (warning-msg ls) nil))
(setf (hstring ls) newstr)))
;; *** Decomposition rewriting ***
(defmethod decomposition-rewrite ((ls l-system))
"Do a decomposition rewrite on the current rewriting string."
(let ((newstr (tree-rewrite ls #'decomposition
(decomposition-depth ls))))
(when (warning-msg ls)
(format t "Decomposition warning: ~A" (warning-msg ls))
(setf (warning-msg ls) nil))
(setf (rstring ls) newstr)))
;; *** Context checking ***
(declaim (inline next-module-left))
(defun next-module-left (ls)
(declare (optimize (speed 3) (safety 0) (debug 0)))
(if (= (the fixnum (context-pos ls)) 0)
:empty
(svref (rstring ls) (decf (the fixnum (context-pos ls))))))
(defun next-context-module-left (ls ignore-list consider-list)
"Find next context module to the left, ignoring symbols and skipping
brackets as necessary."
(if consider-list
(let ((new-consider-list (cons :empty consider-list)))
(do* ((module (next-module-left ls)
(next-module-left ls))
(symbol (if (consp module) (first module) module)
(if (consp module) (first module) module)))
((member symbol new-consider-list) module)
(if (eq symbol '\]) ;; skip brackets
(setf (context-pos ls) (second module)))))
(let ((new-ignore-list (append '(\[ \]) ignore-list)))
(do* ((module (next-module-left ls)
(next-module-left ls))
(symbol (if (consp module) (first module) module)
(if (consp module) (first module) module)))
((not (member symbol new-ignore-list)) module)
(if (eq symbol '\]) ;; skip brackets
(setf (context-pos ls) (second module)))))))
(defun match-context-left (ls context-pattern ignore consider)
"If the symbols and lengths in context-pattern match, return t and a
parameter list."
(setf (context-pos ls) (pos ls))
(let ((param-list nil))
(dolist (obj (reverse context-pattern) (values t param-list))
(let* ((module (next-context-module-left ls ignore consider))
(params (if (consp module) (rest module) nil))
(symbol (if params (first module) module)))
(if (and (eql symbol (car obj)) (= (length params) (cdr obj)))
(setf param-list (append params param-list))
(return (values nil nil)))))))
(declaim (inline next-module-right))
(defun next-module-right (ls)
(declare (optimize (speed 3) (safety 0) (debug 0)))
(if (>= (the fixnum (context-pos ls))
(the fixnum (1- (length (the simple-array (rstring ls))))))
:empty
(svref (rstring ls) (incf (the fixnum (context-pos ls))))))
(defun next-context-module-right (ls ignore-list consider-list)
"Find next context module to the right, ignoring symbols as necessary,
but not skipping brackets."
(if consider-list
(let ((new-consider-list (append '(:empty \[ \]) consider-list)))
(do* ((module (next-module-right ls)
(next-module-right ls))
(symbol (if (consp module) (first module) module)
(if (consp module) (first module) module)))
((member symbol new-consider-list) module)))
(do* ((module (next-module-right ls)
(next-module-right ls))
(symbol (if (consp module) (first module) module)
(if (consp module) (first module) module)))
((not (member symbol ignore-list)) module))))
(defun match-context-right (ls context-pattern ignore consider)
"If the symbols, lengths and brackets in context-pattern match, return a
parameter list and t."
(setf (context-pos ls) (pos ls))
(let ((param-list nil)
(mstack nil))
;; local mstack function
(flet ((mstack-empty? () (null mstack))
(mstack-push (elt) (push elt mstack))
(mstack-pop () (pop mstack)))
(dolist (obj context-pattern (values t (nreverse param-list)))
(do ((try-again t))
((not try-again))
(let* ((module (next-context-module-right ls ignore consider))
(params (if (consp module) (rest module) nil))
(symbol (if params (first module) module)))
(setq try-again nil)
(cond ((eql (car obj) '\])
;; skip to unmatched ], or fail if there is none
(if (mstack-empty?)
(return-from match-context-right (values nil nil))
(setf (context-pos ls) (mstack-pop))))
((eql (car obj) '\[)
;; if brackets match, then push end position on
;; mstack, else fail
(if (eql symbol '\[)
(mstack-push (first params))
(return-from match-context-right (values nil nil))))
((and (eql symbol (car obj))
(= (length params) (cdr obj)))
;; found matching module, add params to list
(dolist (param params) (push param param-list)))
((eql symbol '\[)
;; no match, but skip brackets and try again
(setq try-again t)
(setf (context-pos ls) (first params)))
(t ;; no match, no brackets, fail
(return-from match-context-right (values nil nil))))))))))
;; *** Geometry methods ***
(defmethod create-geometry ((ls l-system))
"Create geometry from current rewriting string."
(let ((turtle-string (if (> (homomorphism-depth ls) 0)
(homomorphism-rewrite ls)
(rstring ls))))
(setf (geometry ls)
(turtle-interpret turtle-string
:angle-increment (angle-increment ls)))))
(defmethod rewrite-and-preview ((ls l-system) filename
&key
(depth (depth ls))
(width 0.3)
(sphere-width 0.1))
"Rewrite, create geometry, output EPS file and view it in Ghostview."
(rewrite ls depth)
(if (null (geometry ls)) (create-geometry ls))
(output-simple-eps (geometry ls) filename
:ps-width width
:sphere-width sphere-width)
(asdf:run-shell-command (format nil "gv ~A -scale 10" filename)))
(defmethod rewrite-and-raytrace ((ls l-system) filename
&key
(depth (depth ls))
(width (cylinder-width ls)))
"Rewrite, create geometry, output POV file and raytrace it."
(rewrite ls depth)
(if (null (geometry ls)) (create-geometry ls))
(output-povray (geometry ls) filename :width-multiplier width)
(asdf:run-shell-command (format nil "povray +i~A" filename)))
(defmethod timed-raytrace ((ls l-system)
&key (filename "foo.pov")
(depth (depth ls))
(width-multiplier 0.01))
(format t "~%REWRITE:~%")
(time (rewrite ls depth))
(format t "~%CREATE-GEOMETRY:~%")
(if (geometry ls)
(write-line "(already exists)")
(time (create-geometry ls)))
(format t "~%OUTPUT-POVRAY:~%")
(time (output-povray (geometry ls) filename
:width-multiplier width-multiplier))
(format t "~%Raytracing:~%")
(time (asdf:run-shell-command (format nil "povray +i~A" filename))))
(defmethod timed-preview ((ls l-system)
&key (filename "foo.eps")
(depth (depth ls))
(width-multiplier 0.2))
(format t "~%REWRITE:~%")
(time (rewrite ls depth))
(format t "~%CREATE-GEOMETRY:~%")
(if (geometry ls)
(write-line "(already exists)")
(time (create-geometry ls)))
(format t "~%OUTPUT-SIMPLE-EPS:~%")
(time (output-simple-eps (geometry ls) filename
:ps-width width-multiplier))
(format t "~%Ghostview:~%")
(time (asdf:run-shell-command (print (format nil "gv ~A -scale 10" filename)))))
(defun lsys2eps (classname filename &key (depth nil)
(width-multiplier 0.3))
(let ((lsys (make-instance classname)))
(rewrite lsys (or depth (depth lsys)))
(if (null (geometry lsys)) (create-geometry lsys))
(output-simple-eps (geometry lsys) filename
:ps-width width-multiplier)))
(defun lsys2pov (classname filename &key (depth nil)
(width-multiplier 0.02))
(let ((lsys (make-instance classname)))
(rewrite lsys (or depth (depth lsys)))
(if (null (geometry lsys)) (create-geometry lsys))
(output-povray (geometry lsys) filename
:width-multiplier width-multiplier)))
;; *** Animations ***
;; extracting frame numbers from a list of numbers and intervals
;; each element is a number, a (FROM TO) interval or a (FROM TO STEP) interval
;; ((1 3) 5) => (1 2 3 5)
;; (1 (20 50 10)) => (1 20 30 40 50)
(defun next-framelist (list)
(let ((elt (first list))
(rest (rest list)))
(if (atom elt)
(values elt rest)
(let* ((step (if (null (cddr elt)) 1 (third elt)))
(new-num (min (+ step (first elt))
(second elt)))
(newelt (list new-num (second elt) step)))
(if (>= (first newelt) (second newelt))
(values (first elt) (cons (first newelt) rest))
(values (first elt) (cons newelt rest)))))))
(defun top-of-framelist (list)
(let ((x (car list)))
(cond ((atom x) x)
((atom (car x)) (car x))
(t (error "Invalid framelist ~A." list)))))
(defmacro extract-framelist (list)
(let ((num-sym (gensym))
(newlist-sym (gensym)))
`(multiple-value-bind (,num-sym ,newlist-sym)
(next-framelist ,list)
(setf ,list ,newlist-sym)
,num-sym)))
(defmethod eps-animation ((ls l-system)
&key
(filename-prefix (string-downcase
(class-name (class-of ls))))
(frames (or (frame-list ls)
`((0 ,(depth ls)))))
(border-percent 10.0)
)
(rewrite ls 0)
(do* ((framelist (copy-tree frames)))
((null framelist) :done)
(let* ((frame (extract-framelist framelist))
(filename (format nil "~A~A.eps" filename-prefix frame)))
(loop until (<= frame (current-depth ls))
do (rewrite1 ls))
(create-geometry ls)
(format t "Outputting '~A'..." filename)
(force-output)
(output-simple-eps (geometry ls) filename
:border-percent border-percent)
(format t "done.~%"))))
(defmethod povray-animation ((ls l-system)
&key
(filename-prefix (string-downcase
(class-name (class-of ls))))
(frames (or (frame-list ls)
`((0 ,(depth ls)))))
(width (cylinder-width ls))
(full-scene t)
)
(rewrite ls 0)
(do* ((framelist (copy-tree frames)))
((null framelist) :done)
(let* ((frame (extract-framelist framelist))
(filename (format nil "~A~A.pov" filename-prefix frame)))
(loop until (<= frame (current-depth ls))
do (rewrite1 ls))
(create-geometry ls)
(format t "Outputting '~A'..." filename)
(force-output)
(output-povray (geometry ls) filename
:width-multiplier width
:full-scene full-scene)
(format t "done.~%"))))
;; *** Macros ***
(defun expand-prods-body (expr ls blockname)
"Helper function for the CHOOSE-PRODUCTION macro; makes the necessary
changes to the WITH-*-CONTEXT and --> macros within the expression."
(cond ((atom expr) expr)
;; expand with-contexts with ls
((member (first expr)
'(with-left-context with-right-context with-lc with-rc))
`(,(first expr) ,ls ,@(expand-prods-body (rest expr) ls blockname)))
;; expand --> to return-->
((eq (first expr) '-->)
`(return-from ,blockname
(--> ,@(expand-prods-body (rest expr) ls blockname))))
;; don't expand nested choose-production expressions
((eq (first expr) 'choose-production)
expr)
;; keep searching
(t (cons (expand-prods-body (first expr) ls blockname)
(expand-prods-body (rest expr) ls blockname)))))
(defmacro prod (module module-form &body body)
"This macro makes some testing and variable-binding automatic.
Used by CHOOSE-PRODUCTION, don't call it directly."
(if (consp module-form)
`(when (and (consp ,module)
(eq (first ,module) ',(first module-form))
(= (length ,module) ,(length module-form)))
(destructuring-bind ,(rest module-form)
(rest ,module)
(declare (ignorable ,@(rest module-form)))
,@body))
`(when (eq ',module-form ,module)
,@body)))
(defmacro choose-production (ls &body prods)
"Choose and evaluate the first matching production.
Productions are given as: (sym expr-returning-list)
or with parameters: ((sym param-1 ... param-n) expr-returning-list)"
(let* ((ls-sym (gensym))
(module-sym (gensym))
(blockname (gensym))
(expanded-prods (expand-prods-body prods ls-sym blockname)))
`(block ,blockname
(let* ((,ls-sym ,ls)
(,module-sym (current-module ,ls-sym)))
(or ,@(mapcar #'(lambda (x) (if (consp x)
`(prod ,module-sym ,@x)
`(prod ,module-sym ,x)))
expanded-prods)
t)))))
(defmacro --> (&body args)
"Macro which can be used to specify right hand productions with
parameters as expressions. Use this within CHOOSE-PRODUCTIONS."
`(list ,@(mapcar #'(lambda (x) (if (consp x)
`(list ',(car x) ,@(cdr x))
`',x))
args)))
(defmacro stochastic-choice (&body args)
(let ((sym-list (mapcar #'(lambda (x) (declare (ignore x)) (gensym))
args))
(random-sym (gensym))
(n (length args)))
`(let* ((,(first sym-list) ,(caar args))
,@(maplist
#'(lambda (x y) `(,(second x) (+ ,(first x) ,(caar y))))
sym-list (rest args))
(,random-sym (random ,(nth (1- n) sym-list))))
(cond ,@(mapcar
#'(lambda (x y z) (declare (ignore z))
`((< ,random-sym ,x) ,(second y)))
sym-list args (rest sym-list))
(t ,(second (nth (1- n) args)))))))
(defmacro with-context (ls match-func-name context-form &body body)
(let ((context-params-sym (gensym))
(bool-sym (gensym))
(bind-params nil)
(context-pattern (mapcar #'(lambda (x)
(let* ((params
(if (consp x) (rest x) nil))
(symbol
(if params (first x) x)))
(cons symbol (length params))))
context-form)))
(dolist (obj context-form)
(when (consp obj) (setf bind-params (append bind-params (rest obj)))))
(if bind-params
`(multiple-value-bind (,bool-sym ,context-params-sym)
(,match-func-name ,ls ',context-pattern
(ignore-list ,ls) (consider-list ,ls))
(when ,bool-sym
(destructuring-bind ,bind-params ,context-params-sym
(declare (ignorable ,@bind-params))
,@body)))
`(when (,match-func-name ,ls ',context-pattern
(ignore-list ,ls) (consider-list ,ls))
,@body))))
(defmacro with-left-context (ls context-form &body body)
`(with-context ,ls match-context-left ,context-form ,@body))
(defmacro with-right-context (ls context-form &body body)
`(with-context ,ls match-context-right ,context-form ,@body))
(defmacro with-lc (&body args)
`(with-left-context ,@args))
(defmacro with-rc (&body args)
`(with-right-context ,@args))
;; ignore/consider macros
(defmacro while-ignoring (ls ignore-list &body body)
(let ((save-ignore (gensym))
(save-consider (gensym)))
`(let ((,save-ignore (ignore-list ,ls))
(,save-consider (consider-list ,ls)))
(unwind-protect
(progn (setf (consider-list ,ls) nil
(ignore-list ,ls) ',ignore-list)
,@body)
(setf (consider-list ,ls) ,save-consider
(ignore-list ,ls) ,save-ignore)))))
(defmacro while-considering (ls consider-list &body body)
(let ((save-consider (gensym)))
`(let ((,save-consider (consider-list ,ls)))
(unwind-protect
(progn (setf (consider-list ,ls) ',consider-list)
,@body)
(setf (consider-list ,ls) ,save-consider)))))
| 27,249 | Common Lisp | .lisp | 638 | 32.80094 | 82 | 0.574456 | cbaggers/l-lisp | 11 | 2 | 2 | GPL-2.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 37a7dc7c327a3213c615e52312b5f9d854b12b960a9997c9605bd146fd3832e0 | 7,940 | [
-1
] |
7,941 | demo.lisp | cbaggers_l-lisp/demo.lisp | ;; *** demo.lisp ***
(in-package :lsx)
(defparameter *demos* nil)
(defparameter *demo-num* 0)
(defun reset-demo ()
(setf *demos* (make-array 1000 :fill-pointer 0))
(setf *demo-num* 0))
(defun add-demo (name
&key
(ls (make-instance name))
(depth (depth ls))
(frames (frame-list ls))
(width 800)
(height 800)
(delay (frame-delay ls))
(line-style (line-style ls))
(lwidth nil)
(recenter nil)
(instant-animate nil)
(closure nil))
(when (null frames)
(setf frames `((,depth ,depth))))
(vector-push (lambda ()
(when closure
(funcall closure))
(gl-animation ls
:frames frames
:window-width width
:window-height height
:frame-delay delay
:line-style line-style
:width lwidth
:recenter recenter
:instant-animate instant-animate))
*demos*))
(defun demo (&optional (num *demo-num*))
(when (>= num (length *demos*))
(setf num 0))
(funcall (aref *demos* num))
(setf *demo-num* (1+ num))
num)
(defun init-demos ()
(reset-demo)
(add-demo 'snowflake :frames '((0 5)) :delay 2 :recenter t)
(add-demo 'occult :frames '((0 4)) :delay 2 :recenter t)
(add-demo 'tree1 :frames '((0 4)) :delay 1.5 :recenter t)
(add-demo 'stree :recenter t)
(add-demo 'context-b)
(add-demo 'polytest :depth 6)
(add-demo 'mesh-test-2 :depth 6)
(add-demo 'gtree)
(add-demo 'prune1 :frames '((0 10)))
(add-demo 'prune2face :frames '((0 19)))
(add-demo 'prune3 :frames '((0 17)))
(add-demo 'climbing1 :frames '((0 1000)))
(add-demo 'tropism4)
(add-demo 'tropism3)
(add-demo 'shaped-plant :closure #'edit-shape)
(add-demo 'shaped-plant-2 :closure (lambda ()
(edit-shape-1)
(edit-shape-2)))
(add-demo 'shaped-leaf)
(add-demo 'spline-curvature :closure #'edit-curvature)
(add-demo 'ptwining :frames '((0 3500)))
)
(defun all-demos ()
(init-demos)
(dotimes (i (length *demos*))
(demo i)))
| 1,978 | Common Lisp | .lisp | 69 | 24.231884 | 61 | 0.616395 | cbaggers/l-lisp | 11 | 2 | 2 | GPL-2.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 1506518e91e51f318d52dba5ba73f7219a7108fef177851c55c94f4a383e3a0c | 7,941 | [
-1
] |
7,942 | make.lisp | cbaggers_l-lisp/make.lisp | (defparameter *l-lisp-dir* "/home/knute/hfag/llisp/")
(make:defsystem l-lisp
:source-pathname *l-lisp-dir*
:source-extension "lisp"
:components ((:file "buffer")
(:file "turtle" :depends-on ("buffer"))
(:file "lsystem" :depends-on ("buffer" "turtle"))
(:file "opengl" :depends-on ("turtle" "lsystem"))
(:file "examples" :depends-on ("lsystem"))
(:file "splineed")
(:file "advanced-examples"
:depends-on ("lsystem" "opengl" "splineed"))))
| 501 | Common Lisp | .lisp | 12 | 35.5 | 57 | 0.606557 | cbaggers/l-lisp | 11 | 2 | 2 | GPL-2.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | d7394347d9caf0dd851e988233cec9413e871daab02cf33d4ed168d420e74f0a | 7,942 | [
-1
] |
7,943 | nrandom.lisp | cbaggers_l-lisp/nrandom.lisp | (in-package :l-systems)
;;
;; Density functions
;;
(defun standard-normal-distribution (x)
(/ (exp (- (* x x 0.5d0)))
(sqrt (* 2 pi))))
(defun normal-distrbution (x mean standard-deviation)
(/ (standard-normal-distribution (/ (- x mean) standard-deviation))
standard-deviation))
(defun fast-normal-distribution (x)
(declare (optimize (speed 3) (safety 0))
(double-float x))
(exp (- (* x x 0.5d0))))
;;
;; Numerical integration
;;
(defparameter *integrate-intervals* 50)
(defun integrate (func a b &optional (intervals *integrate-intervals*))
"Integrate function numerically using Simpson's 1/3 rule."
(declare (optimize (speed 3) (safety 0))
(double-float a b)
(fixnum intervals)
(type compiled-function func))
(let* ((sum 0.0d0)
(n (if (evenp intervals)
intervals
(1+ intervals)))
(h (/ (- b a) n))
(n/2 (/ n 2)))
(declare (double-float sum h)
(fixnum n n/2))
;; Add 4f(x1) + 2f(x2) + 4f(x3) + ... + 4f(xn-1)
(dotimes (i n/2)
(let ((x (+ a h (* 2 h i))))
(incf sum (* 4 (the double-float (funcall func x))))
(when (< i (- n/2 1))
(incf sum (* 2 (the double-float (funcall func (+ x h))))))))
;; Add f(a) and f(b)
(incf sum (+ (the double-float (funcall func a))
(the double-float (funcall func b))))
;; Return sum*h/3
(* sum h 1/3)))
;;
;; Finding probabilities
;;
(defun standard-probability-between (a b)
"Find an approximation for Pr(A < Z < B) for the standard normal
distribution."
;; Integrate numerically from a to b
;;(integrate #'standard-normal-distribution a b intervals))
;; use the fast normal-distribution function
(declare (double-float a b))
(/ (integrate #'fast-normal-distribution a b)
(sqrt (* 2 pi))))
(defun standard-probability-< (x)
"Find an approximation for Pr(Z < X) for the standard normal
distribution."
;; integrate from a reasonably small number (<= -10) to x
(declare (optimize (speed 3) (safety 0))
(double-float x))
(let ((startnum (if (< x 0d0)
(- x 10d0)
-10d0)))
(min (/ (the double-float
(integrate #'fast-normal-distribution
startnum x))
(sqrt (* 2 pi)))
1d0)))
(defun standard-probability-> (x)
"Find an approximation for Pr(Z > X) for the standard normal
distribution."
(declare (double-float x))
(- 1d0 (standard-probability-< x)))
(defun probability-between (a b mean standard-deviation)
"Find an approximation for Pr(A < Z < B) for a normal distribution."
(declare (double-float a b mean standard-deviation))
(let ((new-a (/ (- a mean) standard-deviation))
(new-b (/ (- b mean) standard-deviation)))
(standard-probability-between new-a new-b)))
(defun probability-< (x mean standard-deviation)
"Find an approximation for Pr(Z < X) for a normal distribution."
(declare (double-float x mean standard-deviation))
(standard-probability-< (/ (- x mean) standard-deviation)))
(defun probability-> (x mean standard-deviation)
"Find an approximation for Pr(Z > X) for a normal distribution."
(declare (double-float x mean standard-deviation))
(- 1d0 (probability-< x mean standard-deviation)))
;;
;; Finding roots by the regula falsi method
;;
(defparameter *tolerance* 1.0d-9)
(declaim (double-float *tolerance*))
(declaim (inline small-enough))
(defun small-enough (x)
(declare (optimize (speed 3) (safety 0))
(double-float x))
(< (abs x) *tolerance*))
(defun find-root (func x0 x1)
"Find a root of FUNC between X0 and X1 using the regula falsi method."
(declare (optimize (speed 3) (safety 0))
(compiled-function func)
(double-float x0 x1))
(let ((fx0 (funcall func x0))
(fx1 (funcall func x1))
(i 0))
(declare (double-float fx0 fx1)
(fixnum i))
(when (plusp (* fx0 fx1))
(error "func(x0) and func(x1) must be of opposite signs"))
(loop
(incf i)
(let* ((x2 (- x0 (* fx0 (/ (- x0 x1)
(- fx0 fx1)))))
(fx2 (funcall func x2)))
(declare (double-float x2 fx2))
(when (small-enough fx2)
(return (values x2 i)))
(if (minusp (* fx0 fx2))
(setq x1 x2
fx1 fx2)
(setq x0 x2
fx0 fx2))))))
;;
;; Finding variables for given probabilities
;;
(defun find-standard-random-variable (probability)
"Return an X such that Pr(Z < X) approximates PROBABILITY for the standard
normal distribution."
(declare (double-float probability))
(let (a b)
(cond ((= probability 0.5d0)
(return-from find-standard-random-variable 0d0))
((< probability 0.5d0)
(setq a -10d0
b 0d0))
(t
(setq a 0d0
b 10d0)))
(find-root (lambda (x) (- (standard-probability-< x)
probability))
a b)))
(defun find-random-variable (probability mean standard-deviation)
"Return an X such that Pr(Z < X) approximates PROBABILITY for a normal
distribution with the given MEAN and STANDARD-DEVIATION."
(declare (double-float probability mean standard-deviation))
(multiple-value-bind (std-answer i)
(find-standard-random-variable probability)
(declare (ignorable i))
;;(format t "FIND-ROOT iterations: ~A~%" i)
(+ (* std-answer standard-deviation) mean)))
;;
;; NRANDOM
;;
(defun nrandom (mean standard-deviation)
"Pick a random number from a normal distribution."
(find-random-variable (random 1.0d0)
(coerce mean 'double-float)
(coerce standard-deviation 'double-float)))
| 5,800 | Common Lisp | .lisp | 159 | 30.144654 | 76 | 0.610775 | cbaggers/l-lisp | 11 | 2 | 2 | GPL-2.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 0b6f5a97879cb043c4d7e3188430c42a7d4d604588750f564e975a7d060519f3 | 7,943 | [
-1
] |
7,944 | l-lisp.asd | cbaggers_l-lisp/l-lisp.asd | #+sbcl
(eval-when (:compile-toplevel :load-toplevel :execute)
(sb-int:set-floating-point-modes :traps nil))
(asdf:defsystem #:l-lisp
:description "l-system framework"
:author "Knut Arild Erstad <[email protected]>"
:license "GPL v3"
:serial t
:depends-on (#:cffi
#:uiop
#:cl-opengl)
:components ((:file "packages")
(:file "buffer")
(:file "nrandom")
(:file "turtle")
(:file "lsystem")
;; (:file "opengl")
(:file "examples")
;; (:file "splineed")
;; (:file "advanced-examples")
;; (:file "demo")
))
| 691 | Common Lisp | .lisp | 22 | 21.545455 | 54 | 0.491018 | cbaggers/l-lisp | 11 | 2 | 2 | GPL-2.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 210fd581adceaa919877bca38e855fb095296d35d15d7d1572f1d27d6d9b042a | 7,944 | [
-1
] |
7,945 | turtle.lisp | cbaggers_l-lisp/turtle.lisp | ;;; *** turtle.lisp ***
;;;
;;; This file is part of L-Lisp by Knut Arild Erstad.
;;; Contains routines for:
;;; - 3D vector/matrix functions for double-floats.
;;; - Turtle graphics and interpretation.
;;; - Output geometry to Postscript and Povray
(in-package :l-systems)
;; make sure pi is double-float, no larger
(defconstant d-pi (coerce pi 'double-float))
;; Helper trigonometric functions
(defun deg-to-rad (n)
(* n (/ d-pi 180.0d0)))
(defun rad-to-deg (n)
(* n (/ 180.0d0 d-pi)))
(defun cosd (n)
(cos (deg-to-rad n)))
(defun sind (n)
(sin (deg-to-rad n)))
(defun tand (n)
(tan (deg-to-rad n)))
;; Helper 3d vector/matrix functions
(declaim (inline vec3 vlength normalize equalvec zerovec vec- vec+
dot-product cross-product))
(defun v3 (elt1 elt2 elt3)
"Create a 3D vector. Slow, but works for all real numbers."
(make-array 3 :element-type 'double-float
:initial-contents
(list (coerce elt1 'double-float)
(coerce elt2 'double-float)
(coerce elt3 'double-float))))
(defun vec3 (elt1 elt2 elt3)
"Create a 3D vector. All arguments must be double-floats."
(declare (optimize (speed 3) (safety 0) #+cmu (ext:inhibit-warnings 3))
(type double-float elt1 elt2 elt3))
(let ((vec (make-array 3 :element-type 'double-float)))
(declare (type (simple-array double-float (3)) vec))
(setf (aref vec 0) elt1)
(setf (aref vec 1) elt2)
(setf (aref vec 2) elt3)
vec))
(defun vlength (vec)
"Calculate the length of a 3D vector."
(declare (optimize (speed 3) (safety 0) #+cmu (ext:inhibit-warnings 3))
(type (simple-array double-float (3)) vec))
(let ((sum 0.0d0))
(declare (double-float sum))
(dotimes (i 3)
(let ((elt (aref vec i)))
(declare (double-float elt))
(incf sum (* elt elt))))
(the double-float (sqrt sum))))
(defun normalize (vec)
"Change the length of the 3D vector to 1."
(declare (optimize (speed 3) (safety 0) #+cmu (ext:inhibit-warnings 3))
(type (simple-array double-float (3)) vec))
(let ((len (vlength vec)))
(declare (double-float len))
(dotimes (i 3 vec)
(setf (aref vec i) (/ (aref vec i) len)))))
(defun equalvec (vec1 vec2)
"Returns T if two 3D vectors are equal."
(declare (optimize (speed 3) (safety 0) #+cmu (ext:inhibit-warnings 3))
(type (simple-array double-float (3)) vec1 vec2))
(and (= (aref vec1 0) (aref vec2 0))
(= (aref vec1 1) (aref vec2 1))
(= (aref vec1 2) (aref vec2 2))))
(defun almost-equalvec (vec1 vec2)
"Returns T if two 3D vectors are almost equal; this is defined to be
true if all distances along axes are smaller than a certain epsilon.
Epsilon = 1.0d-10."
(declare (optimize (speed 3) (safety 0))
(type (simple-array double-float (3)) vec1 vec2))
(let ((epsilon 1d-10))
(and (< (abs (- (aref vec1 0) (aref vec2 0))) epsilon)
(< (abs (- (aref vec1 1) (aref vec2 1))) epsilon)
(< (abs (- (aref vec1 2) (aref vec2 2))) epsilon))))
(defun zerovec (vec)
"Returns T if the vector is equal to #(0 0 0)."
(declare (optimize (speed 3) (safety 0) #+cmu (ext:inhibit-warnings 3))
(type (simple-array double-float (3)) vec))
(and (zerop (aref vec 0))
(zerop (aref vec 1))
(zerop (aref vec 2))))
(defun vec- (vec1 vec2)
"Returns VEC1 - VEC2."
(declare (optimize (speed 3) (safety 0) #+cmu (ext:inhibit-warnings 3))
(type (simple-array double-float (3)) vec1 vec2))
(let ((vec (make-array 3 :element-type 'double-float)))
(dotimes (i 3 vec)
(setf (aref vec i) (- (aref vec1 i) (aref vec2 i))))))
(defun vec+ (vec1 vec2)
"Returns VEC1 + VEC2."
(declare (optimize (speed 3) (safety 0) #+cmu (ext:inhibit-warnings 3))
(type (simple-array double-float (3)) vec1 vec2))
(let ((vec (make-array 3 :element-type 'double-float)))
(dotimes (i 3 vec)
(setf (aref vec i) (+ (aref vec1 i) (aref vec2 i))))))
(defun dot-product (vec1 vec2)
"Returns the dot product VEC1 * VEC2."
(declare (optimize (speed 3) (safety 0) #+cmu (ext:inhibit-warnings 3))
(type (simple-array double-float (3)) vec1 vec2))
(let ((sum 0.0d0))
(declare (double-float sum))
(dotimes (i 3 sum)
(incf sum (* (aref vec1 i) (aref vec2 i))))))
(defun cross-product (vec1 vec2)
"Returns the cross product VEC1 x VEC2."
(declare (optimize (speed 3) (safety 0) #+cmu (ext:inhibit-warnings 3))
(type (simple-array double-float (3)) vec1 vec2))
(let ((u1 (aref vec1 0))
(u2 (aref vec1 1))
(u3 (aref vec1 2))
(v1 (aref vec2 0))
(v2 (aref vec2 1))
(v3 (aref vec2 2))
(r (make-array 3 :element-type 'double-float)))
(declare (double-float u1 u2 u3 v1 v2 v3)
(type (simple-array double-float (3)) r))
(setf (aref r 0) (- (* u2 v3) (* u3 v2)))
(setf (aref r 1) (- (* u3 v1) (* u1 v3)))
(setf (aref r 2) (- (* u1 v2) (* u2 v1)))
r))
(defun matrix-vector-mult (mat vec)
"Multiply a 3x3 (rotation) matrix with a vector."
(declare (optimize (speed 3) (safety 0) #+cmu (ext:inhibit-warnings 3))
(type (simple-array double-float (3 3)) mat)
(type (simple-array double-float (3)) vec))
(let ((r (make-array 3 :element-type 'double-float
:initial-element 0.0d0)))
(declare (type (simple-array double-float (3)) r))
(dotimes (j 3 r)
(dotimes (i 3)
(incf (aref r j) (* (aref mat j i) (aref vec i)))))))
;; turtle struct; a "moving coordinate system" with some extra parameters
(defstruct (turtle (:copier nil))
(pos (make-array 3 :element-type 'double-float
:initial-contents '#(0.0d0 0.0d0 0.0d0))
:type (simple-array double-float (3)))
(H (make-array 3 :element-type 'double-float
:initial-contents '#(0.0d0 1.0d0 0.0d0))
:type (simple-array double-float (3)))
(L (make-array 3 :element-type 'double-float
:initial-contents '#(-1.0d0 0.0d0 0.0d0))
:type (simple-array double-float (3)))
(U (make-array 3 :element-type 'double-float
:initial-contents '#(0.0d0 0.0d0 -1.0d0))
:type (simple-array double-float (3)))
angle
width
prev-width
color
texture
(scale 1.0d0) ;; unused
(shared-polygon-stack (list nil))
(shared-mesh (list nil))
(produce-spheres t)
)
;; Unlike the other turtle values, the polygon and mesh stuff must be
;; shared between copies. Some accessors to make this easier:
(defun turtle-polygon-stack (turtle)
(car (turtle-shared-polygon-stack turtle)))
(defun (setf turtle-polygon-stack) (val turtle)
(setf (car (turtle-shared-polygon-stack turtle)) val))
(defun turtle-polygon (turtle)
(car (turtle-polygon-stack turtle)))
(defun (setf turtle-polygon) (val turtle)
(setf (car (turtle-polygon-stack turtle)) val))
(defun turtle-mesh (turtle)
(car (turtle-shared-mesh turtle)))
(defun (setf turtle-mesh) (val turtle)
(setf (car (turtle-shared-mesh turtle)) val))
(defun copy-turtle (turtle)
"Deep copy of turtle."
(make-turtle :pos (copy-seq (turtle-pos turtle))
:H (copy-seq (turtle-H turtle))
:L (copy-seq (turtle-L turtle))
:U (copy-seq (turtle-U turtle))
:angle (turtle-angle turtle)
:width (turtle-width turtle)
:prev-width (turtle-prev-width turtle)
:color (turtle-color turtle)
:texture (turtle-texture turtle)
:scale (turtle-scale turtle)
:shared-polygon-stack
(turtle-shared-polygon-stack turtle)
:shared-mesh (turtle-shared-mesh turtle)
:produce-spheres (turtle-produce-spheres turtle)
))
(defun rotate (turtle vec angle)
"Rotate turtle an angle around a unit vector."
;; the algorithm is taken from the comp.graphics.algorithms FAQ:
;; "How do I rotate a 3D point?" (works for vectors, too)
(declare (optimize (speed 3) (safety 0) #+cmu (ext:inhibit-warnings 3))
(type turtle turtle)
(type (simple-array double-float (3)) vec))
(let* ((rad-angle (deg-to-rad angle))
(t-ang (/ rad-angle 2.0d0))
(cost (cos t-ang))
(sint (sin t-ang))
;; [ x y z w ] quaternation
(x (* (aref vec 0) sint))
(y (* (aref vec 1) sint))
(z (* (aref vec 2) sint))
(w cost)
;; multiples of x, y, z, w
(wx (* w x)) (wy (* w y)) (wz (* w z))
(xx (* x x)) (xy (* x y)) (xz (* x z))
(yy (* y y)) (yz (* y z)) (zz (* z z))
;; rotation matrix
(mat (make-array '(3 3) :element-type 'double-float)))
(declare (double-float rad-angle t-ang cost sint x y z w
wx wy wz xx xy xz yy yz zz)
(type (simple-array double-float (3 3)) mat))
;; fill in matrix
(setf (aref mat 0 0) (- 1.0d0 (* 2.0d0 (+ yy zz)))
(aref mat 0 1) (* 2.0d0 (- xy wz))
(aref mat 0 2) (* 2.0d0 (+ xz wy))
(aref mat 1 0) (* 2.0d0 (+ xy wz))
(aref mat 1 1) (- 1.0d0 (* 2.0d0 (+ xx zz)))
(aref mat 1 2) (* 2.0d0 (- yz wx))
(aref mat 2 0) (* 2.0d0 (- xz wy))
(aref mat 2 1) (* 2.0d0 (+ yz wx))
(aref mat 2 2) (- 1.0d0 (* 2.0d0 (+ xx yy))))
;; rotate the three turtle vectors
(setf (turtle-H turtle) (matrix-vector-mult mat (turtle-H turtle))
(turtle-U turtle) (matrix-vector-mult mat (turtle-U turtle))
(turtle-L turtle) (matrix-vector-mult mat (turtle-L turtle)))
nil))
(defun rotate-towards (turtle vec angle)
"Rotate the turtle an angle towards a vector."
;;(declare (optimize (speed 3) (safety 0)))
;;(declare (type (simple-array double-float (3)) vec))
;; Find current angle between vec and turtle heading
(let* ((hvec (turtle-H turtle))
(dot (dot-product hvec vec))
(current-rad-angle (acos (/ dot (vlength vec) (vlength hvec))))
(current-deg-angle (rad-to-deg current-rad-angle))
(rotate-angle (min angle current-deg-angle)))
;;(declare (type (simple-array double-float (3)) hvec))
;;(declare (double-float dot current-rad-angle current-deg-angle))
(when (> rotate-angle 0d0)
(let ((rvec (cross-product hvec vec)))
(when (zerovec rvec)
(let ((newvec (copy-seq vec)))
(incf (aref newvec 0) 1d-10)
(setq rvec (cross-product hvec newvec))))
(rotate turtle (normalize rvec) angle)))))
;; The definitions of turn, pitch and roll has been optimized
;; to avoid slow matrix multiplication.
;; Pencil and paper were used to calculate formulas. :-)
(defun turn (turtle angle)
(declare (optimize (speed 3) (safety 0) #+cmu (ext:inhibit-warnings 3))
(type turtle turtle))
(let* ((rad-angle (deg-to-rad (coerce angle 'double-float)))
(cosa (cos rad-angle))
(sina (sin rad-angle))
(H (turtle-H turtle))
(L (turtle-L turtle)))
(declare (double-float rad-angle cosa sina)
(type (simple-array double-float (3)) H L))
(dotimes (i 3)
(let ((hi (aref H i))
(li (aref L i)))
(declare (double-float hi li))
(setf (aref H i) (- (* hi cosa) (* li sina))
(aref L i) (+ (* hi sina) (* li cosa)))))))
(defun pitch (turtle angle)
(declare (optimize (speed 3) (safety 0) #+cmu (ext:inhibit-warnings 3))
(type turtle turtle))
(let* ((rad-angle (deg-to-rad (coerce angle 'double-float)))
(cosa (cos rad-angle))
(sina (sin rad-angle))
(H (turtle-H turtle))
(U (turtle-U turtle)))
(declare (double-float rad-angle cosa sina)
(type (simple-array double-float (3)) H U))
(dotimes (i 3)
(let ((hi (aref H i))
(ui (aref U i)))
(declare (double-float hi ui))
(setf (aref H i) (+ (* hi cosa) (* ui sina))
(aref U i) (- (* ui cosa) (* hi sina)))))))
(defun roll (turtle angle)
(declare (optimize (speed 3) (safety 0) #+cmu (ext:inhibit-warnings 3))
(type turtle turtle))
(let* ((rad-angle (deg-to-rad (coerce angle 'double-float)))
(cosa (cos rad-angle))
(sina (sin rad-angle))
(L (turtle-L turtle))
(U (turtle-U turtle)))
(declare (double-float rad-angle cosa sina)
(type (simple-array double-float (3)) L U))
(dotimes (i 3)
(let ((li (aref L i))
(ui (aref U i)))
(declare (double-float li ui))
(setf (aref L i) (+ (* li cosa) (* ui sina))
(aref U i) (- (* ui cosa) (* li sina)))))))
(defun move-forward (turtle &optional (distance 1.0d0))
(let ((pos (turtle-pos turtle))
(h (turtle-H turtle)))
(dotimes (i 3 pos)
(incf (aref pos i) (* distance (aref h i))))))
;; line struct, for 3d geometry
;; (line/segment/cylinder depending on context)
(defstruct line
(p1 (make-array 3 :element-type 'double-float
:initial-contents '(0.0d0 0.0d0 0.0d0))
:type (simple-array double-float (3)))
(p2 (make-array 3 :element-type 'double-float
:initial-contents '(0.0d0 0.0d0 0.0d0))
:type (simple-array double-float (3)))
width
prev-width
sphere
color
texture)
;; sphere struct
(defstruct sphere
pos
radius
color
texture)
;; polygon struct
(defstruct polygon
points ;; list of points
normal ;; normal vector
color
texture)
;; triangle mesh
(defstruct mesh
vertices ;; list of unique vertices
triangles ;; list of triangles
(strands (list nil)) ;; nested list of vertices used during contruction
color
texture)
(defstruct vertex
pos ;; 3d position
normal) ;; average of triangles' normal vectors
(defstruct triangle
vertices ;; three of them
normal) ;; normal vector
;; box struct (independent of turtle orientation)
(defstruct box
pos ;; #(x y z) position of near lower left corner
size ;; #(xsize ysize zsize)
color
texture)
(defun mesh-add-vertex (mesh point)
"Add new vertex to mesh and return it, or if one exists at the same
position, return that one."
(let ((vertex nil))
(dolist (obj (mesh-vertices mesh))
(if (almost-equalvec point (vertex-pos obj))
(setf vertex obj)))
(unless vertex
(setf vertex (make-vertex :pos (copy-seq point)
:normal
(make-array 3 :element-type 'double-float
:initial-element 0d0)))
(push vertex (mesh-vertices mesh)))
(let* ((strands (mesh-strands mesh))
(strand (first strands)))
(if (or (null strand)
(not (eql vertex (first strand))))
(push vertex (first strands))))
vertex))
(defun mesh-add-triangle (mesh vertex1 vertex2 vertex3)
"If all vertices are distinct, create a triangle, add it to the mesh
and return it. Otherwise, return NIL."
(if (or (eql vertex1 vertex2)
(eql vertex1 vertex3)
(eql vertex2 vertex3))
nil
(let* ((pos1 (vertex-pos vertex1))
(pos2 (vertex-pos vertex2))
(pos3 (vertex-pos vertex3))
(v1 (vec- pos2 pos1))
(v2 (vec- pos3 pos1))
(normal (normalize (cross-product v1 v2)))
(triangle (make-triangle
:vertices (list vertex1 vertex2 vertex3)
:normal normal)))
;; add normal to vertices
(dolist (vertex (list vertex1 vertex2 vertex3))
(let ((vnormal (vertex-normal vertex)))
(dotimes (i 3)
(incf (aref vnormal i) (aref normal i)))))
;; add it to the mesh
(push triangle (mesh-triangles mesh)))))
;; *** Turtle functions ***
(defparameter *turtle-functions*
(make-hash-table :test 'eq :size 211))
(defmacro def-turtle-function-raw (names parameters &body body)
"This macro is for defining turtle functions. The NAMES is
either a single name or a list of names of the turtle command.
The function is stored in the *TURTLE-FUNCTIONS* hash table.
All non-NIL return values will be added to the geometry vector during
turtle interpretation.
The first parameter is the turtle and the second is the list of
parameters. The elements of this list can be changed, which is unseful
for environmentally sensitive commands.
"
`(let ((func (lambda ,parameters ,@body)))
,@(mapcar (lambda (x)
`(setf (gethash ',x *turtle-functions*) func))
(if (atom names) (list names) names))))
(defmacro def-turtle-function (names parameters &body body)
"This macro is for defining turtle functions. The NAMES is
either a single name or a list of names of the turtle command.
The function is stored in the *TURTLE-FUNCTIONS* hash table.
All non-NIL return values will be added to the geometry vector during
turtle interpretation.
The first parameter is the turtle (and is required), the rest of the
parameters are module parameters, which can be declared &OPTIONAL.
A &REST parameter is added (and declared to be ignored) unless you supply
one explicitly.
(def-turtle-command (:foo s) (turtle &optional (angle 90.0))
(do-something turtle angle)
nil)
"
(let* ((temp-param (gensym))
(junk-param (gensym))
(turtle-param (first parameters))
(has-rest (find '&rest parameters))
(lambda-func (if has-rest
`(lambda (,turtle-param &optional ,temp-param)
(destructuring-bind ,(rest parameters)
,temp-param
,@body))
`(lambda (,turtle-param &optional ,temp-param)
(destructuring-bind (,@(rest parameters)
&rest ,junk-param)
,temp-param
(declare (ignore ,junk-param))
,@body)))))
`(let ((func ,lambda-func))
,@(mapcar (lambda (x)
`(setf (gethash ',x *turtle-functions*) func))
(if (atom names) (list names) names)))))
(defun turtle-function (name)
(gethash name *turtle-functions*))
;;
;; *** Predefined turtle functions ***
;;
(def-turtle-function (:forward F) (turtle &optional (length 1.0))
(let ((oldpos (copy-seq (turtle-pos turtle))))
(move-forward turtle length)
(let ((line (make-line :p1 oldpos
:p2 (copy-seq (turtle-pos turtle))
:color (turtle-color turtle)
:texture (turtle-texture turtle)
:width (turtle-width turtle)
:prev-width (turtle-prev-width turtle)
:sphere (turtle-produce-spheres turtle))))
;; since we moved forward, set prev-width to width
(setf (turtle-prev-width turtle) (turtle-width turtle))
line)))
(def-turtle-function :produce-spheres (turtle produce-spheres)
(setf (turtle-produce-spheres turtle) produce-spheres)
nil)
(def-turtle-function (:forward-no-line \f) (turtle &optional (length 1.0))
(move-forward turtle length)
nil)
(def-turtle-function (:turn-left +)
(turtle &optional (angle (turtle-angle turtle)))
(turn turtle (- angle))
nil)
(def-turtle-function (:turn-right -)
(turtle &optional (angle (turtle-angle turtle)))
(turn turtle angle)
nil)
(def-turtle-function (:pitch-down &)
(turtle &optional (angle (turtle-angle turtle)))
(pitch turtle angle)
nil)
(def-turtle-function (:pitch-up ^)
(turtle &optional (angle (turtle-angle turtle)))
(pitch turtle (- angle))
nil)
(def-turtle-function (:roll-left \\)
(turtle &optional (angle (turtle-angle turtle)))
(roll turtle angle)
nil)
(def-turtle-function (:roll-right /)
(turtle &optional (angle (turtle-angle turtle)))
(roll turtle (- angle))
nil)
(def-turtle-function (:turn-around \|) (turtle)
(let ((H (turtle-H turtle))
(L (turtle-L turtle)))
(dotimes (i 3)
(setf (aref H i) (- (aref H i))
(aref L i) (- (aref L i))))))
(def-turtle-function (:set-width !) (turtle width) ; required parameter
(setf (turtle-prev-width turtle) (turtle-width turtle))
(setf (turtle-width turtle) width)
nil)
(def-turtle-function (:sphere @O)
(turtle &optional (radius (turtle-width turtle)))
(make-sphere :pos (copy-seq (turtle-pos turtle))
:radius (coerce radius 'double-float)
:color (turtle-color turtle)
:texture (turtle-texture turtle)))
(def-turtle-function :box (turtle in-pos in-size)
(let ((pos (map '(simple-array double-float (3))
(lambda (x) (coerce x 'double-float))
in-pos))
(size (map '(simple-array double-float (3))
(lambda (x) (coerce x 'double-float))
in-size)))
(make-box :pos pos :size size
:color (turtle-color turtle)
:texture (turtle-texture turtle))))
;; Polygon functions
(def-turtle-function (:start-polygon {) (turtle)
(push (make-polygon :points (list (copy-seq (turtle-pos turtle)))
:color (turtle-color turtle)
:texture (turtle-texture turtle))
(turtle-polygon-stack turtle))
nil)
(def-turtle-function (:add-vertex \.) (turtle)
(let* ((polygon (turtle-polygon turtle))
(last-vertex (first (polygon-points polygon)))
(pos (turtle-pos turtle)))
(if (not (equalp pos last-vertex))
(push (copy-seq pos)
(polygon-points polygon))))
nil)
(def-turtle-function (:forward-vertex f.) (turtle &optional (length 1.0))
(move-forward turtle length)
(funcall (turtle-function :add-vertex) turtle)
nil)
(def-turtle-function (:end-polygon }) (turtle)
(funcall (turtle-function :add-vertex) turtle)
;; save normal
(let* ((polygon (turtle-polygon turtle))
(points (polygon-points polygon))
(p1 (first points))
(p2 (second points))
(p3 (third points))
(v1 (vec- p2 p1))
(v2 (vec- p3 p1))
(normal (cross-product v1 v2)))
(setf (polygon-normal polygon) (normalize normal)))
;; pop polygon
(pop (turtle-polygon-stack turtle)))
(def-turtle-function :color (turtle in-color)
;; prepare color for OpenGL's glColor or glMaterial (use single-floats)
;; array [ r g b 1.0 ]
(let ((color (make-array 4 :element-type 'single-float)))
(setf (aref color 3) 1.0)
(dotimes (i 3)
(setf (aref color i) (coerce (aref in-color i) 'single-float)))
(setf (turtle-color turtle) color))
nil)
(def-turtle-function :texture (turtle texture)
(setf (turtle-texture turtle) texture)
nil)
;; Mesh functions
(def-turtle-function (:start-mesh m{) (turtle)
(let ((mesh (make-mesh)))
(mesh-add-vertex mesh (turtle-pos turtle))
(setf (turtle-mesh turtle) mesh))
nil)
(def-turtle-function (:mesh-vertex m.) (turtle)
(mesh-add-vertex (turtle-mesh turtle) (turtle-pos turtle))
nil)
(def-turtle-function (:new-strand m/) (turtle)
(let ((mesh (turtle-mesh turtle)))
;; start an empty strand
(push nil (mesh-strands mesh))
;; add current position
(mesh-add-vertex mesh (turtle-pos turtle)))
nil)
(defun strands-to-triangles (mesh strand1 strand2)
(when (and strand1 strand2)
(mapc (lambda (x y z) (mesh-add-triangle mesh x y z))
strand1 strand2 (rest strand2))
(mapc (lambda (x y z) (mesh-add-triangle mesh x y z))
strand1 (rest strand2) (rest strand1))))
(def-turtle-function (:end-mesh m}) (turtle)
(let* ((mesh (turtle-mesh turtle))
(strands (mesh-strands mesh)))
;; create triangles
(if (first strands)
(mapc #'(lambda (x y) (strands-to-triangles mesh x y))
strands (cdr strands)))
;; calculate average normal vectors
(dolist (vertex (mesh-vertices mesh))
(let ((normal (vertex-normal vertex)))
(unless (zerovec normal)
(normalize normal))))
;; set color
(setf (mesh-color mesh) (turtle-color turtle))
;; mesh is finished, delete redundant fields
(setf (mesh-vertices mesh) nil)
(setf (mesh-strands mesh) nil)
;; return mesh
mesh))
(def-turtle-function (:forward-mesh-vertex mf) (turtle &optional (length 1.0))
(move-forward turtle length)
(funcall (turtle-function :mesh-vertex) turtle)
nil)
;; Set position
(def-turtle-function (:set-position @M) (turtle pos)
(setf (turtle-pos turtle)
(map '(simple-array double-float 1)
(lambda (x) (coerce x 'double-float))
pos))
nil)
;; Rotate toward a vector
(def-turtle-function (:rotate-towards @R)
(turtle angle &optional (vec #(0d0 1d0 0d0)))
(let ((d-angle (coerce angle 'double-float))
(d-vec (map '(vector double-float)
(lambda (x) (coerce x 'double-float))
vec)))
(rotate-towards turtle d-vec d-angle)
nil))
;; Create lines independently of turtle position
(def-turtle-function :line (turtle p1 p2
&optional (width (turtle-width turtle)))
(make-line :p1 (map '(simple-array double-float (3))
(lambda (x) (coerce x 'double-float))
p1)
:p2 (map '(simple-array double-float (3))
(lambda (x) (coerce x 'double-float))
p2)
:width width
:color (turtle-color turtle)
:texture (turtle-texture turtle)))
;; Environmentally sensitive functions
(def-turtle-function-raw (:get-position ?P) (turtle params)
(setf (first params) (copy-seq (turtle-pos turtle)))
nil)
(def-turtle-function-raw (:get-heading ?H) (turtle params)
(setf (first params) (copy-seq (turtle-H turtle)))
nil)
(def-turtle-function-raw (:get-up-vector ?U) (turtle params)
(setf (first params) (copy-seq (turtle-U turtle)))
nil)
(def-turtle-function-raw (:get-left-vector ?L) (turtle params)
(setf (first params) (copy-seq (turtle-L turtle)))
nil)
(def-turtle-function-raw (:get-turtle ?T) (turtle params)
(setf (first params) (copy-turtle turtle))
nil)
;; *** Turtle interpretation ***
(defun turtle-interpret (rstring &key (angle-increment 90.0d0))
"Create geometry by turtle-interpreting a rewriting string."
(declare (optimize (speed 3) (safety 0))
(type simple-vector rstring))
(let ((geometry (make-buffer))
(turtle-stack nil)
(turtle (make-turtle :angle angle-increment)))
(push turtle turtle-stack)
(dotimes (pos (length rstring))
(let* ((module (svref rstring pos))
(params (if (listp module) (rest module) nil))
(symbol (if params (first module) module)))
(cond
((eq symbol '\[)
(setq turtle (copy-turtle turtle))
(push turtle turtle-stack))
((eq symbol '\])
(pop turtle-stack)
(setq turtle (car turtle-stack)))
(t
(let ((func (gethash symbol *turtle-functions*)))
(when (functionp func)
(let ((returnval (funcall func turtle params)))
(when returnval
(buffer-push returnval geometry)))))))))
(buffer->vector geometry)))
;; Geometry limits
(defun find-limits (geometry)
"Find the min- and max-values of the geometry coordinates."
(let* ((bg most-positive-double-float)
(sm most-negative-double-float)
(minv (vector bg bg bg))
(maxv (vector sm sm sm)))
(dotimes (pos (length geometry))
(let ((elt (aref geometry pos)))
(case (type-of elt)
(line
(let* ((p1 (line-p1 elt))
(p2 (line-p2 elt)))
(dotimes (i 3)
(setf (aref minv i) (min (aref minv i)
(aref p1 i)
(aref p2 i)))
(setf (aref maxv i) (max (aref maxv i)
(aref p1 i)
(aref p2 i))))))
(polygon
(dolist (p (polygon-points elt))
(dotimes (i 3)
(setf (aref minv i) (min (aref minv i)
(aref p i)))
(setf (aref maxv i) (max (aref maxv i)
(aref p i))))))
(box
(let* ((p1 (box-pos elt))
(p2 (vec+ p1 (box-size elt))))
(dotimes (i 3)
(setf (aref minv i) (min (aref minv i)
(aref p1 i)
(aref p2 i)))
(setf (aref maxv i) (max (aref maxv i)
(aref p1 i)
(aref p2 i))))))
(mesh
(dolist (triangle (mesh-triangles elt))
(dolist (vertex (triangle-vertices triangle))
(let ((pos (vertex-pos vertex)))
(dotimes (i 3)
(setf (aref minv i) (min (aref minv i)
(aref pos i)))
(setf (aref maxv i) (max (aref maxv i)
(aref pos i)))))))))))
(values minv maxv)))
(defun find-simple-limits (geometry &key (border-percent 10.0))
"Find 2d limits (min, max) of 3d geometry, ignoring z coordinate."
(multiple-value-bind (minv maxv) (find-limits geometry)
(let* ((xmin (aref minv 0))
(xmax (aref maxv 0))
(ymin (aref minv 1))
(ymax (aref maxv 1))
(x (- xmax xmin))
(y (- ymax ymin))
(border (* (max x y) border-percent 0.01)))
(decf xmin border)
(decf ymin border)
(incf xmax border)
(incf ymax border)
(values xmin xmax ymin ymax))))
;; *** Outputting Postscript ***
(defun output-simple-eps (geometry filename
&key
(ps-size 100) (ps-width 0.3) (border-percent 10.0)
(sphere-width 0.1))
"Output simplest possible 2d projection (ignoring z coordinate) as EPS."
(with-open-file (file filename :direction :output
:if-exists :supersede)
(multiple-value-bind (xmin xmax ymin ymax)
(find-simple-limits geometry :border-percent border-percent)
(let* ((xsize (- xmax xmin))
(ysize (- ymax ymin))
(line-width 1.0)
(ps-size-x ps-size)
(ps-size-y ps-size))
(if (> xsize ysize)
(setq ps-size-y (floor (* ps-size ysize) xsize))
(setq ps-size-x (floor (* ps-size xsize) ysize)))
(format file "%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 ~A ~A
%%Creator: L-Lisp (L-systems for CL) by Knut Arild Erstad ([email protected])
%%EndComments~%" ps-size-x ps-size-y)
(loop for obj across geometry do
(case (type-of obj)
(line
(let* ((line obj)
(p1 (line-p1 line))
(x1 (/ (- (aref p1 0) xmin) xsize))
(y1 (/ (- (aref p1 1) ymin) ysize))
(p2 (line-p2 line))
(x2 (/ (- (aref p2 0) xmin) xsize))
(y2 (/ (- (aref p2 1) ymin) ysize))
(w (line-width line)))
(when w
(setq line-width w))
(format file "~,9F setlinewidth ~,9F ~,9F moveto~%"
(* line-width ps-width)
(* x1 ps-size-x) (* y1 ps-size-y))
(format file "~,9F ~,9F lineto stroke~%"
(* x2 ps-size-x) (* y2 ps-size-y))))
(polygon
(let* ((polygon obj)
(points (polygon-points polygon))
(fpoint (first points))
(xf (/ (- (aref fpoint 0) xmin) xsize))
(yf (/ (- (aref fpoint 1) ymin) ysize)))
(format file "0.01 setlinewidth~%")
(format file "newpath ~,9F ~,9F moveto~%"
(* xf ps-size-x) (* yf ps-size-y))
(dolist (point (rest points))
(let ((x (/ (- (aref point 0) xmin) xsize))
(y (/ (- (aref point 1) ymin) ysize)))
(format file "~,9F ~,9F lineto~%"
(* x ps-size-x) (* y ps-size-y))))
(format file "closepath fill~%")))
(sphere
(let* ((sphere obj)
(pos (sphere-pos sphere))
(x (/ (- (aref pos 0) xmin) xsize))
(y (/ (- (aref pos 1) ymin) ysize))
(radius (sphere-radius sphere)))
(format file
"newpath ~,9F ~,9F ~,9F 0 360 arc closepath fill~%"
(* x ps-size-x) (* y ps-size-y)
(* radius sphere-width))))
))))))
;; *** Outputting POV code ***
(defmethod povcode (obj stream &rest junk)
(declare (ignore junk stream))
(warn "Unknown type ~A passed to POVCODE." (type-of obj))
nil)
(defun povcode-vector-long (vec stream)
(format stream "<~,15F,~,15F,~,15F>"
(aref vec 0) (aref vec 1) (aref vec 2)))
(defun povcode-vector-short (vec stream)
(format stream "<~,5F,~,5F,~,5F>"
(aref vec 0) (aref vec 1) (aref vec 2)))
(defun povcode-color (colvec stream)
(when colvec
(princ "pigment{ color rgb " stream)
(povcode-vector-short colvec stream)
(princ " }" stream)))
(defmethod povcode ((line line) stream &rest args)
(unless (equalvec (line-p1 line) (line-p2 line))
(let* ((width (or (line-width line) 1.0))
(prev-width (or (line-prev-width line) width))
(width-multiplier (if args (first args) 1.0))
(width-x-mult (* width width-multiplier))
(sphere (line-sphere line)))
(when sphere
(format stream "union { "))
(princ "cone{ " stream)
(povcode-vector-short (line-p1 line) stream)
(format stream ", ~,5F, " (* prev-width width-multiplier))
(povcode-vector-short (line-p2 line) stream)
(format stream ", ~,5F " width-x-mult)
(when sphere
(format stream "} sphere {")
(povcode-vector-short (line-p2 line) stream)
(format stream ", ~,5F} " width-x-mult))
(povcode-color (line-color line) stream)
(write-line "}" stream))))
(defun povcode-points (list stream)
(povcode-vector-long (car list) stream)
(dolist (elt (cdr list))
(princ ", ")
(povcode-vector-long elt stream)))
(defmethod povcode ((sphere sphere) stream &rest args)
(let ((radius (or (sphere-radius sphere) 1.0))
(width-multiplier (if args (first args) 1.0)))
(princ "sphere { " stream)
(povcode-vector-short (sphere-pos sphere) stream)
(format stream ", ~,5F " (* radius width-multiplier))
(povcode-color (sphere-color sphere) stream)
(write-line "}" stream)))
(defmethod povcode ((polygon polygon) stream &rest junk)
(declare (ignore junk))
(let ((points (polygon-points polygon)))
(format stream "polygon{ ~A, " (length points))
(povcode-points points stream)
(princ " " stream)
(povcode-color (polygon-color polygon) stream)
(write-line "}" stream)))
(defun povcode-smooth-triangle (triangle stream)
(let* ((vertices (triangle-vertices triangle))
(v1 (first vertices))
(v2 (second vertices))
(v3 (third vertices)))
(princ "smooth_triangle { " stream)
(povcode-vector-short (vertex-pos v1) stream)
(princ ", " stream)
(povcode-vector-short (vertex-normal v1) stream)
(princ ", " stream)
(povcode-vector-short (vertex-pos v2) stream)
(princ ", " stream)
(povcode-vector-short (vertex-normal v2) stream)
(princ ", " stream)
(povcode-vector-short (vertex-pos v3) stream)
(princ ", " stream)
(povcode-vector-short (vertex-normal v3) stream)
(princ " }" stream)))
(defmethod povcode ((mesh mesh) stream &rest junk)
(declare (ignore junk))
(princ "mesh { " stream)
(dolist (elt (mesh-triangles mesh))
(povcode-smooth-triangle elt stream)
(princ " " stream))
(povcode-color (mesh-color mesh) stream)
(write-line "}" stream))
(defmethod povcode ((box box) stream &rest junk)
(declare (ignore junk))
(princ "box { " stream)
(let* ((pos (box-pos box))
(pos2 (vec+ pos (box-size box))))
(povcode-vector-short pos stream)
(princ ", " stream)
(povcode-vector-short pos2 stream))
(povcode-color (box-color box) stream)
(write-line "}" stream))
(defun output-povray (geometry filename
&key (object-name "Lsystem")
(full-scene t)
(width-multiplier 0.01))
"Output 3d geometry as an object for the POV ray-tracer."
(with-open-file (file filename :direction :output
:if-exists :supersede)
(format file "// ~A object generated by L-Lisp L-system framework
// by Knut Arild Erstad ([email protected])~%" object-name)
(when full-scene
;; Put some "dumb" defaults for camera and light source
(format file "
#include \"colors.inc\"
#include \"woods.inc\"
background { color LightBlue }
camera {
location <0.7, 1, -1>
look_at <0, 0.5, 0>
}
light_source { <5, 50, -20> color White }
plane { <0,1,0>, 0 pigment {color White} finish {ambient .3} }~%"))
(format file "#declare ~A = union {~%" object-name)
(dotimes (i (length geometry))
(povcode (aref geometry i) file width-multiplier))
;;(format file "~A~%" (povcode (aref geometry i) width-multiplier)))
(when full-scene
(multiple-value-bind (minv maxv) (find-limits geometry)
(declare (ignore minv))
(let ((yscale (/ 1.0 (aref maxv 1))))
(format file "scale ~,6F~%" yscale))))
(format file "} // end of ~A object~%" object-name)
(when full-scene
(format file "object { ~A texture {T_Wood1 finish {ambient .5}} }~%"
object-name))))
| 38,385 | Common Lisp | .lisp | 931 | 32.859291 | 78 | 0.580237 | cbaggers/l-lisp | 11 | 2 | 2 | GPL-2.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 8988ebf7fe7b5d505958a7d751bff1e4ab5ca029625f071c147dbc2b89911fe5 | 7,945 | [
-1
] |
7,946 | splineed.lisp | cbaggers_l-lisp/splineed.lisp | ;;; *** splineed.lisp ***
;;;
;;; This file is part of L-Lisp by Knut Arild Erstad.
;;; An OpenGL based spline editor.
(in-package :spline-editor)
(defun tri-solve (a d c b)
"Solve a tridiagonal set of equations.
Input:
A, D, C: the diagonal vectors of the matrix
B: the right-hand vector
Outputs a solution vector X.
The Matrix is on the form:
| d0 c0 : b0 |
| a1 d1 c1 : b1 |
| a2 d2 .. : .. |
| .. .. cN-2 : bN-2 |
| aN-1 dN-1 : bN-1 |
The numbers a0 and cN-1 are ignored.
"
(let ((n (length a)))
;; check sizes; will allow that C has length n-1
(when (or (/= n (length b))
(/= n (length d))
(and (/= n (length c))
(/= n (1+ (length c)))))
(error "wrong vector sizes."))
;; Gauss elimination (eliminating A)
(do ((k 1 (1+ k)))
((>= k n))
;; save multiplicator in A
(setf (svref a k) (/ (svref a k) (svref d (1- k))))
;; update D and B
(decf (svref d k) (* (svref a k) (svref c (1- k))))
(decf (svref b k) (* (svref a k) (svref b (1- k)))))
;; back substitution (eliminating C)
(do ((k (1- n) (1- k)))
((<= k 0))
;; save multiplicator in C
(setf (svref c (1- k)) (/ (svref c (1- k)) (svref d k)))
;; update B
(decf (svref b (1- k)) (* (svref c (1- k)) (svref b k))))
;; final step: b[k] = b[k] / d[k], then return b
(dotimes (k n b)
(setf (svref b k) (/ (svref b k) (svref d k))))))
(defun natural-cubic-spline-coefficients (x y)
"Find the coefficients of a natural cubic spline.
Input:
X, Y: (n+1)-vectors which define the control points
X must be sorted.
Output:
Four n-vectors A, B, C, D which represent the coefficients of the
natural cubic spline interpolating over X, Y, such that
p(x) = a_i * (x-x_i)^3 + b_i * (x-x_i)^2 + c_i * (x-x_i) + d_i
when x_i < x < x_i+1
"
(let ((n (1- (length x))))
(when (/= (length y) (1+ n))
(error "X and Y must be the same size."))
(when (< n 1)
(error "too small vectors."))
(let* ((h (map 'vector #'- (subseq x 1) x))
(sol (tri-solve (subseq h 0 (1- n))
(map 'vector
#'(lambda (h0 h1) (* 2 (+ h0 h1)))
h (subseq h 1))
(subseq h 1)
(map 'vector
#'(lambda (h0 h1 y0 y1 y2)
(* 6 (- (/ (- y2 y1) h1)
(/ (- y1 y0) h0))))
h (subseq h 1) y (subseq y 1) (subseq y 2))))
(s (concatenate 'vector '(0) sol '(0)))
(a (map 'vector
#'(lambda (h0 s0 s1) (/ (- s1 s0) 6 h0))
h s (subseq s 1)))
(b (map 'vector
#'(lambda (s0) (/ s0 2))
(subseq s 0 n)))
(c (map 'vector
#'(lambda (h0 y0 y1 s0 s1)
(- (/ (- y1 y0) h0)
(/ (+ (* 2 h0 s0) (* h0 s1)) 6)))
h y (subseq y 1) s (subseq s 1)))
(d (subseq y 0 n)))
(values a b c d))))
(defstruct spline
x y a b c d function
)
(defun spline-min-x (spline)
(let ((x (spline-x spline)))
(svref x 0)))
(defun spline-max-x (spline)
(let ((x (spline-x spline)))
(svref x (1- (length x)))))
(defun spline-min-y (spline)
(let* ((y (spline-y spline))
(min-y (svref y 0)))
(do ((i 1 (1+ i)))
((>= i (length y)) min-y)
(setq min-y (min min-y (svref y i))))))
(defun spline-max-y (spline)
(let* ((y (spline-y spline))
(max-y (svref y 0)))
(do ((i 1 (1+ i)))
((>= i (length y)) max-y)
(setq max-y (max max-y (svref y i))))))
(defun natural-cubic-spline (x y &key (make-function nil))
(multiple-value-bind
(a b c d) (natural-cubic-spline-coefficients x y)
(let ((spline (make-spline :x x :y y :a a :b b :c c :d d)))
(when make-function
(setf (spline-function spline) (make-spline-function spline)))
spline)))
(defun recalculate-natural-cubic-spline (spline &key (make-function nil))
(multiple-value-bind
(a b c d) (natural-cubic-spline-coefficients
(spline-x spline) (spline-y spline))
(setf (spline-a spline) a
(spline-b spline) b
(spline-c spline) c
(spline-d spline) d
(spline-function spline)
(if make-function (make-spline-function spline) nil))
spline))
(defun spline-value (spline x-value)
(let* ((i 0)
(x (spline-x spline))
(n (length x)))
(loop (when (or (>= i (1- n)) (>= (svref x (1+ i)) x-value))
(return))
(incf i))
(let* ((h (- x-value (svref x i)))
(hh (* h h))
(hhh (* h hh))
(a (svref (spline-a spline) i))
(b (svref (spline-b spline) i))
(c (svref (spline-c spline) i))
(d (svref (spline-d spline) i)))
(+ (* a hhh) (* b hh) (* c h) d))))
(defun spline-values (spline &key
(start (spline-min-x spline))
(end (spline-max-x spline))
(steps 100))
(let* ((r (make-array steps))
(x-step (/ (- end start) (1- steps)))
(x (spline-x spline))
(i 0)
(n (1- (length x)))
(xi (svref x 0))
(xi+1 (svref x 1))
(a (spline-a spline))
(b (spline-b spline))
(c (spline-c spline))
(d (spline-d spline))
(ai (svref a 0))
(bi (svref b 0))
(ci (svref c 0))
(di (svref d 0)))
(dotimes (j steps r)
(let ((xpos (+ start (* x-step j))))
;; make sure we're in the right interval
(loop (if (and (> xpos xi+1) (< i (1- n)))
(progn (incf i)
(setq xi xi+1)
(setq xi+1 (svref x (1+ i)))
(setq ai (svref a i))
(setq bi (svref b i))
(setq ci (svref c i))
(setq di (svref d i)))
(return)))
;; calculate spline value
(let* ((h (- xpos xi))
(hh (* h h))
(hhh (* hh h)))
(setf (svref r j) (+ (* ai hhh) (* bi hh) (* ci h) di)))))))
;; Old version of MAKE-SPLINE-FUNCTION: produces a small but slow function
#+nil
(defun make-spline-function (spline)
#'(lambda (x)
(spline-value spline x)))
;; New version of MAKE-SPLINE-FUNCTION: this should be pretty fast for
;; most purposes. For really big splines (with many control points)
;; binary search might be worthwhile.
;; It is also my first real attempt at on-the-fly code generation
;; and compilation. Ain't Lisp cool? ;)
(defun make-spline-function (spline &key (number-type 'double-float))
(let ((*compile-print* nil)
(lambda-expr
`(lambda (x-in)
(let ((x (coerce x-in ',number-type)))
(declare (optimize (speed 3) (safety 0)
#+cmu (ext:inhibit-warnings 3))
(,number-type x))
(cond ,@(map 'list
#'(lambda (xi xi+1 ai bi ci di)
`((< x ,xi+1)
(let* ((h (- x ,xi))
(hh (* h h))
(hhh (* hh h)))
(declare (,number-type h hh hhh))
(+ (* ,ai hhh) (* ,bi hh) (* ,ci h) ,di))))
(spline-x spline)
(subseq (spline-x spline)
1 (1- (length (spline-x spline))))
(spline-a spline) (spline-b spline)
(spline-c spline) (spline-d spline))
,(let* ((x (spline-x spline))
(a (spline-a spline))
(b (spline-b spline))
(c (spline-c spline))
(d (spline-d spline))
(i (1- (length a))))
`(t (let* ((h (- x ,(svref x i)))
(hh (* h h))
(hhh (* hh h)))
(declare (,number-type h hh hhh))
(+ (* ,(svref a i) hhh) (* ,(svref b i) hh)
(* ,(svref c i) h) ,(svref d i))))))))))
(values (compile nil lambda-expr) lambda-expr)))
(defun output-spline (spline filename)
(let ((*print-readably* t)
(func (spline-function spline)))
(setf (spline-function spline) nil)
(with-open-file (stream filename
:direction :output :if-exists :supersede)
(prin1 spline stream))
(setf (spline-function spline) func)
nil))
(defun input-spline (filename &key (make-function nil))
(let (spline)
(with-open-file (stream filename)
(setq spline (read stream)))
(unless (typep spline 'spline)
(error "Could not read SPLINE object."))
(when make-function
(setf (spline-function spline) (make-spline-function spline)))
spline))
;; Ouput EPS:
(defun output-spline-to-eps (spline filename &key (steps 100) (border 0.1))
(let* ((xmin (spline-min-x spline))
(xmax (spline-max-x spline))
(xsize (- xmax xmin))
(xinc (* xsize border))
(new-xmin (- xmin xinc))
(new-xmax (+ xmax xinc))
(new-xsize (- new-xmax new-xmin))
(ymin (min (spline-min-y spline) 0.0))
(ymax (max (spline-max-y spline) 0.0))
(ysize (- ymax ymin))
(yinc (* ysize border))
(new-ymin (- ymin yinc))
(new-ymax (+ ymax yinc))
(new-ysize (- new-ymax new-ymin))
(ps-xsize 300)
(ps-ysize (round (* ps-xsize (/ new-ysize new-xsize))))
;;(vals (spline-values spline :steps steps))
)
(with-open-file (file filename :direction :output
:if-exists :supersede)
;; header
(format file "%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 ~A ~A
%%Creator: L-Lisp's spline editor by Knut Arild Erstad ([email protected])
%%EndComments~%" ps-xsize ps-ysize)
;; spline
(loop for x from xmin to xmax by (/ xsize steps) do
(let* ((y (spline-value spline x))
(xrel (/ (- x new-xmin) new-xsize))
(yrel (/ (- y new-ymin) new-ysize)))
(format file "~,9F ~,9F ~A~%"
(* xrel ps-xsize) (* yrel ps-ysize)
(if (= x xmin) "moveto" "lineto"))))
(format file "stroke~%")
;; x axis
(let* ((yrel-zero (/ (- new-ymin) new-ysize))
(ps-yzero (* yrel-zero ps-ysize)))
(format file "[1 2] 0 setdash
~,9F ~,9F moveto ~,9F ~,9F lineto stroke~%"
0 ps-yzero ps-xsize ps-yzero))
;; y axis
(let* ((xrel-zero (/ (- new-xmin) new-xsize))
(ps-xzero (* xrel-zero ps-xsize)))
(format file "~,9F ~,9F moveto ~,9F ~,9F lineto stroke~%"
ps-xzero 0 ps-xzero ps-ysize))
)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; opengl/xlib stuff below
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#+allegro
(eval-when (:compile-toplevel :load-toplevel)
(require :gl)
(require :xlib))
(defvar *display* nil)
(defvar *window*)
(defstruct (spline-window (:conc-name sw-))
;; slots that should be initialized by EDIT-SPLINE
spline
window
steps
grid
strong-grid
draw-points
draw-axes
;; slots that don't need initialization
(marked-point nil)
(save-when-quit t)
;; slots that should be initialized by SPLINE-RESHAPE
top
bottom
left
right
height
width
)
(defun create-gl-window (display width height name)
;; Create a double buffered, RGBA window
(let* ((screen (xlib-gl:XDefaultScreen display))
(root (xlib-gl:XRootWindow display screen))
;; array of integers, terminated by "None"
(attrib (make-array 9
:element-type
#+cmu '(signed-byte 32) #-cmu 'fixnum
:initial-contents
(list gl:GLX_RGBA gl:GLX_RED_SIZE 1
gl:GLX_GREEN_SIZE 1 gl:GLX_BLUE_SIZE 1
gl:GLX_DOUBLEBUFFER xlib-gl:None)))
(visinfo (gl:glXChooseVisual display screen attrib)))
(when (zerop visinfo)
(error
"CREATE-GL-WINDOW: Could not get an RGBA, double-buffered visual."))
(let ((attr (xlib-gl:make-xsetwindowattributes)))
(xlib-gl:set-xsetwindowattributes-background_pixel! attr 0)
(xlib-gl:set-xsetwindowattributes-border_pixel! attr 0)
(xlib-gl:set-xsetwindowattributes-colormap!
attr (xlib-gl:XCreateColormap display root
(xlib-gl:XVisualInfo-visual visinfo)
xlib-gl:AllocNone))
(xlib-gl:set-xsetwindowattributes-event_mask!
attr (+ xlib-gl:StructureNotifyMask xlib-gl:ExposureMask
xlib-gl:ButtonPressMask xlib-gl:ButtonReleaseMask
xlib-gl:Button1MotionMask xlib-gl:Button2MotionMask
xlib-gl:KeyPressMask))
(let* ((mask (+ xlib-gl:CWBackPixel xlib-gl:CWBorderPixel
xlib-gl:CWColormap xlib-gl:CWEventMask))
(window (xlib-gl:XCreateWindow display root 0 0 width height
0
(xlib-gl:XVisualInfo-depth visinfo)
xlib-gl:InputOutput
(xlib-gl:XVisualInfo-visual visinfo)
mask attr))
(context (gl:glXCreateContext display visinfo NULL 1)))
(gl:glXMakeCurrent display window context)
(xlib-gl:XStoreName display window name)
(xlib-gl:XMapWindow display window)
window))))
(defun window-coordinates (spline-window x y)
(let* ((left (sw-left spline-window))
(right (sw-right spline-window))
(top (sw-top spline-window))
(bottom (sw-bottom spline-window))
(window-width (sw-width spline-window))
(window-height (sw-height spline-window))
(x-size (- right left))
(y-size (- top bottom))
(relative-x (/ (- x left) x-size))
(relative-y (/ (- y bottom) y-size))
(window-x (* relative-x window-width))
(window-y (- window-height (* relative-y window-height))))
(values window-x window-y)))
(defun real-coordinates (spline-window x y)
(let* ((left (sw-left spline-window))
(right (sw-right spline-window))
(top (sw-top spline-window))
(bottom (sw-bottom spline-window))
(window-width (sw-width spline-window))
(window-height (sw-height spline-window))
(x-size (- right left))
(y-size (- top bottom))
(relative-x (/ x window-width))
(relative-y (/ (- window-height y) window-height))
(real-x (+ left (* relative-x x-size)))
(real-y (+ bottom (* relative-y y-size))))
(values real-x real-y)))
(defun spline-reshape (spline-window width height)
(let* ((spline (sw-spline spline-window))
(xmin (spline-min-x spline))
(xmax (spline-max-x spline))
(base-xsize (- xmax xmin -0.01))
;;(left (1- (spline-min-x spline)))
;;(right (1+ (spline-max-x spline)))
(left (- xmin (* 0.1 base-xsize)))
(right (+ xmax (* 0.1 base-xsize)))
(aspect (/ width height))
(xsize (- right left))
(ysize (/ xsize aspect))
;;(bottom (- (/ ysize 2)))
;;(bottom (1- (spline-min-y spline)))
(ycenter (/ (+ (spline-min-y spline) (spline-max-y spline)) 2))
(bottom (- ycenter (/ ysize 2)))
(top (+ bottom ysize)))
(setf (sw-left spline-window) left
(sw-right spline-window) right
(sw-bottom spline-window) bottom
(sw-top spline-window) top
(sw-width spline-window) width
(sw-height spline-window) height)
(gl:glViewport 0 0 width height)
(gl:glMatrixMode gl:GL_PROJECTION)
(gl:glLoadIdentity)
;;(gl:gluOrtho2D -1d0 5d0 -1d0 5d0)
(gl:gluOrtho2D (coerce left 'double-float)
(coerce right 'double-float)
(coerce bottom 'double-float)
(coerce top 'double-float))
(gl:glMatrixMode gl:GL_MODELVIEW)
(gl:glLoadIdentity)))
(defmacro convert-to (type &body places)
`(progn
,@(mapcar #'(lambda (x) `(setf ,x (coerce ,x ',type)))
places)))
(defun draw-grid (spline-window grid r g b)
(let ((left (sw-left spline-window))
(right (sw-right spline-window))
(top (sw-top spline-window))
(bottom (sw-bottom spline-window)))
(convert-to single-float left right top bottom grid r g b)
(gl:glColor3f r g b)
(gl:glBegin gl:GL_LINES)
(do ((x-val 0.0 (+ x-val grid)))
((> x-val right))
(gl:glVertex2f x-val top)
(gl:glVertex2f x-val bottom))
(do ((x-val (- grid) (- x-val grid)))
((< x-val left))
(gl:glVertex2f x-val top)
(gl:glVertex2f x-val bottom))
(do ((y-val 0.0 (+ y-val grid)))
((> y-val top))
(gl:glVertex2f left y-val)
(gl:glVertex2f right y-val))
(do ((y-val (- grid) (- y-val grid)))
((< y-val bottom))
(gl:glVertex2f left y-val)
(gl:glVertex2f right y-val))
(gl:glEnd)))
(defun spline-draw (spline-window)
(gl:glClearColor 1.0 1.0 1.0 1.0)
(gl:glClear gl:GL_COLOR_BUFFER_BIT)
;; Grid
(let ((grid (sw-grid spline-window))
(strong-grid (sw-strong-grid spline-window)))
(when grid
(draw-grid spline-window grid 0.85 0.85 0.85))
(when strong-grid
(draw-grid spline-window strong-grid 0.6 0.6 0.6)))
;; Axes
(when (sw-draw-axes spline-window)
(gl:glColor3f 0.0 0.0 0.0)
(gl:glBegin gl:GL_LINES)
(gl:glVertex2f (coerce (sw-left spline-window) 'single-float) 0.0)
(gl:glVertex2f (coerce (sw-right spline-window) 'single-float) 0.0)
(gl:glVertex2f 0.0 (coerce (sw-top spline-window) 'single-float))
(gl:glVertex2f 0.0 (coerce (sw-bottom spline-window) 'single-float))
(let* ((left (sw-left spline-window))
(right (sw-right spline-window))
(top (sw-top spline-window))
;;(bottom (sw-bottom spline-window))
(pixel-size (/ (- right left) (sw-width spline-window)))
(arrow-size (* pixel-size 5)))
(convert-to single-float right top arrow-size)
;; arrows
(gl:glVertex2f right 0.0)
(gl:glVertex2f (- right arrow-size) arrow-size)
(gl:glVertex2f right 0.0)
(gl:glVertex2f (- right arrow-size) (- arrow-size))
(gl:glVertex2f 0.0 top)
(gl:glVertex2f arrow-size (- top arrow-size))
(gl:glVertex2f 0.0 top)
(gl:glVertex2f (- arrow-size) (- top arrow-size))
)
(gl:glEnd))
;; Spline
(gl:glColor3f 0.0 0.0 1.0)
(gl:glLineWidth 1.0)
(let* ((spline (sw-spline spline-window))
(steps (sw-steps spline-window))
(start (spline-min-x spline))
(end (spline-max-x spline))
(x (spline-x spline))
(x-step (/ (- end start) (1- steps)))
(y-values (spline-values spline
:start start :end end :steps steps)))
(gl:glBegin gl:GL_LINE_STRIP)
(dotimes (i steps)
(let ((xpos (+ start (* i x-step)))
(ypos (svref y-values i)))
(gl:glVertex2f (coerce xpos 'single-float)
(coerce ypos 'single-float))))
(gl:glEnd)
(when (sw-draw-points spline-window)
(gl:glPointSize 5.0)
(gl:glBegin gl:GL_POINTS)
(let ((y (spline-y spline))
(marked-point (sw-marked-point spline-window)))
(dotimes (i (length x))
(if (and marked-point (= marked-point i))
(gl:glColor3f 0.0 1.0 0.0)
(gl:glColor3f 0.0 0.0 0.0))
(gl:glVertex2f (coerce (svref x i) 'single-float)
(coerce (svref y i) 'single-float))))
(gl:glEnd)))
;; swap buffers
(gl:glXSwapBuffers *display* (sw-window spline-window)))
(defun spline-button1motion (spline-window xpos ypos)
(let ((marked-point (sw-marked-point spline-window)))
(when marked-point
(multiple-value-bind (real-x real-y)
(real-coordinates spline-window xpos ypos)
(let* ((spline (sw-spline spline-window))
(x (spline-x spline))
(y (spline-y spline))
(n (length x)))
;; make sure a point doesn't get dragged past its neighbours
(when (and (> marked-point 0)
(<= real-x (svref x (1- marked-point))))
(setf real-x (+ (svref x (1- marked-point)) 0.01)))
(when (and (< marked-point (1- n))
(>= real-x (svref x (1+ marked-point))))
(setf real-x (- (svref x (1+ marked-point)) 0.01)))
;; update and draw spline
(setf (svref x marked-point) real-x
(svref y marked-point) real-y)
(recalculate-natural-cubic-spline (sw-spline spline-window))
(spline-draw spline-window))))))
(defun spline-button2click (spline-window xpos ypos)
(multiple-value-bind (real-x real-y)
(real-coordinates spline-window xpos ypos)
(let* ((spline (sw-spline spline-window))
(x (spline-x spline))
(y (spline-y spline))
(n (length x))
(pos (position-if #'(lambda (xi) (<= real-x xi)) x)))
(if (and pos (= (svref x pos) real-x))
;; attempt to insert two points at the same x-value, move old point
(setf (svref x pos) real-x
(svref y pos) real-y)
;; new point, change vectors
(progn
(if (null pos) (setq pos n))
(setf (spline-x spline)
(concatenate
'vector (subseq x 0 pos) (vector real-x) (subseq x pos)))
(setf (spline-y spline)
(concatenate
'vector (subseq y 0 pos) (vector real-y) (subseq y pos)))))
(recalculate-natural-cubic-spline spline)
(setf (sw-marked-point spline-window) pos)
(spline-draw spline-window))))
(defun spline-button1click (spline-window xpos ypos)
(let* ((spline (sw-spline spline-window))
(x (spline-x spline))
(y (spline-y spline))
(pixel-distance 5))
(setf (sw-marked-point spline-window) nil)
(dotimes (i (length x))
(multiple-value-bind (win-xpos win-ypos)
(window-coordinates spline-window (svref x i) (svref y i))
(when (and (<= (abs (- win-xpos xpos))
pixel-distance)
(<= (abs (- win-ypos ypos))
pixel-distance))
(setf (sw-marked-point spline-window) i)
(return))))
(spline-draw spline-window)))
(defun spline-delete-point (spline-window)
;; remove marked point
(let ((i (sw-marked-point spline-window)))
(when i
(let* ((spline (sw-spline spline-window))
(x (spline-x spline))
(y (spline-y spline))
(n (length x)))
(if (<= n 2)
(warn "Cannot delete; there must be at least two points.")
(progn
(setf (spline-x spline) (concatenate 'vector
(subseq x 0 i)
(subseq x (1+ i) n))
(spline-y spline) (concatenate 'vector
(subseq y 0 i)
(subseq y (1+ i) n)))
(recalculate-natural-cubic-spline spline)
(setf (sw-marked-point spline-window) nil)
(spline-draw spline-window)))))))
(defun spline-keypress (spline-window keysym char)
(cond ((= keysym xlib-gl:XK_Escape)
(setf (sw-save-when-quit spline-window) nil)
:quit)
((= keysym xlib-gl:XK_Delete)
(spline-delete-point spline-window))
(t
(case char
(#\q
:quit)
(#\d
(spline-delete-point spline-window))
(#\p
(setf (sw-draw-points spline-window)
(not (sw-draw-points spline-window)))
(spline-draw spline-window))))))
(defun spline-event-loop (display spline-window)
(let ((event (xlib-gl:make-xevent))
(debug nil))
(loop
(when debug (format t "Waiting for event...~%"))
(xlib-gl:xnextevent display event)
(let ((event-type (xlib-gl:xanyevent-type event)))
(when debug (format t "Event: ~A~%" event-type))
(cond ((eq event-type xlib-gl:expose)
;; gobble other expose events
(loop (when (zerop (xlib-gl:xpending display))
(return))
(xlib-gl:xnextevent display event)
(unless (eq (xlib-gl:xanyevent-type event)
xlib-gl:expose)
(xlib-gl:xputbackevent display event)
(return)))
;; draw
(spline-draw spline-window))
((eq event-type xlib-gl:configurenotify)
;; reshape
(spline-reshape spline-window
(xlib-gl:xconfigureevent-width event)
(xlib-gl:xconfigureevent-height event)))
((eq event-type xlib-gl:buttonpress)
(let ((button (xlib-gl:xbuttonevent-button event)))
(when debug (format t "Button: ~A~%" button))
(let ((xpos (xlib-gl:xbuttonevent-x event))
(ypos (xlib-gl:xbuttonevent-y event)))
(cond ((eq button xlib-gl:button1)
;; Mark/unmark point
(spline-button1click spline-window xpos ypos))
((eq button xlib-gl:button2)
;; add new point
(spline-button2click spline-window xpos ypos))
((eq button xlib-gl:button3)
;; quit
(return))))))
((eq event-type xlib-gl:motionnotify)
;; mouse motion
(let ((state (xlib-gl:xmotionevent-state event)))
;; gobble motion events with same state
(loop (when (zerop (xlib-gl:xpending display))
(return))
(xlib-gl:xnextevent display event)
(let ((event-type (xlib-gl:xanyevent-type event)))
(unless (and (eq event-type xlib-gl:motionnotify)
(= (xlib-gl:xmotionevent-state event)
state))
(xlib-gl:xputbackevent display event)
(return))))
(let ((xpos (xlib-gl:xmotionevent-x event))
(ypos (xlib-gl:xmotionevent-y event)))
(when debug
(format t "Motion with state ~A and pos ~A ~A~%"
xpos ypos))
(unless (zerop (boole boole-and state xlib-gl:Button1Mask))
(spline-button1motion spline-window xpos ypos)))))
((eq event-type xlib-gl:keypress)
;; keypress
(let* ((keysym (xlib-gl:xlookupkeysym event 0))
(char (if (< keysym 256) (code-char keysym) nil))
(answer (spline-keypress spline-window keysym char)))
(when (eq answer :quit) (return))))
)))
(xlib-gl:free-xevent event)))
(defun edit-spline (&key (spline nil) (filename nil) (eps-filename nil)
(steps 100) (grid 0.1) (strong-grid 1.0)
(draw-points t) (draw-axes t))
;; open display (if not already open), and create window
(unless *display*
(setq *display* (xlib-gl:xopendisplay "")))
(setq *window* (create-gl-window *display* 500 300
"L-Lisp Spline editor"))
(unless spline
;; read from file if filename is given, otherwise create a default one
(setq spline
(if (and filename (probe-file filename))
(progn (format t "Reading from file '~A'~%" filename)
(input-spline filename))
(progn (when filename (format t "New file '~A'~%" filename))
(natural-cubic-spline '#(0.0 1.0) '#(0.0 0.0))))))
(let ((spline-window (make-spline-window
:spline spline
:window *window*
:steps steps
:grid grid
:strong-grid strong-grid
:draw-points draw-points
:draw-axes draw-axes)))
(spline-event-loop *display* spline-window)
;; cleanup
(xlib-gl:xdestroywindow *display* *window*)
(let ((event (xlib-gl:make-xevent)))
(loop (when (zerop (xlib-gl:xpending *display*)) (return))
(xlib-gl:xnextevent *display* event))
(xlib-gl:free-xevent event))
;; maybe ouput to file
(when filename
(if (sw-save-when-quit spline-window)
(progn (format t "Writing to file '~A'~%" filename)
(output-spline spline filename))
(format t "Quitting without saving.~%")))
;; maybe output EPS file
(when eps-filename
(if (sw-save-when-quit spline-window)
(progn (format t "Writing EPS file '~A'~%" eps-filename)
(output-spline-to-eps spline eps-filename))
(format t "Not writing EPS file.~%")))
spline))
(defun cleanup ()
(xlib-gl:xdestroywindow *display* *window*)
(let ((event (xlib-gl:make-xevent)))
(loop (when (zerop (xlib-gl:xpending *display*)) (return))
(xlib-gl:xnextevent *display* event))
(xlib-gl:free-xevent event))
)
| 30,618 | Common Lisp | .lisp | 727 | 30.437414 | 80 | 0.511373 | cbaggers/l-lisp | 11 | 2 | 2 | GPL-2.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 3a2095a40c8e535776a0fcbe17287e3ac1bcd7056c94da06352090e33b0e9a7d | 7,946 | [
-1
] |
7,947 | examples.lisp | cbaggers_l-lisp/examples.lisp | ;;; *** examples.lisp ***
;;;
;;; This file is part of L-Lisp by Knut Arild Erstad.
;;; Examples of L-systems in L-Lisp
(in-package :l-system-examples)
;; Fibonacci l-system
(defclass fibonacci (l-system)
((axiom :initform '(a))
(depth :initform 4)))
(defmethod l-productions ((ls fibonacci))
(choose-production ls
(a (--> b))
(b (--> a b))))
;; Snowflake curve
(defclass snowflake (l-system)
((axiom :initform '((+ 90) F - - F - - F))
(depth :initform 1)
(angle-increment :initform 60.0)))
(defmethod l-productions ((ls snowflake))
(choose-production ls
(F (--> F + F - - F + F))))
;; Parametric version of the snowflake curve
(defclass snowflake-param (l-system)
((axiom :initform '((F 1) (- 120) (F 1) (- 120) (F 1)))
(depth :initform 0)))
(defmethod l-productions ((ls snowflake-param))
(choose-production ls
((F x)
(let ((newx (/ x 3)))
(--> (F newx) (+ 60) (F newx) (- 120) (F newx) (+ 60) (F newx))))))
;; Occult L-system ;->
(defclass occult (l-system)
((axiom :initform '((- 90) F + F + F + F + F))
(depth :initform 3)
(angle-increment :initform 72)))
(defmethod l-productions ((ls occult))
(choose-production ls
(F (--> F F + F + F + F + F + F F))))
(defmethod l-productions ((ls occult))
(choose-production ls
(F (--> F F [ + F + F + F + F ] F))))
;; Tree structure
(defclass tree1 (l-system)
((axiom :initform '(F))
(depth :initform 3)
(angle-increment :initform 20.0)))
(defmethod l-productions ((ls tree1))
(choose-production ls
(F (--> F - [ - F + F + F ] + [ + F - F - F ] F))))
;; 3D tree
(defclass tree3d (l-system)
((axiom :initform '((! 1.0) (F 1.0)))
(depth :initform 4)))
(defmethod l-productions ((ls tree3d))
(choose-production ls
((F s) (--> (F s)
[ (/ 35) (& 35) (! 1.0) (F (* s 0.8)) ]
[ (/ 215) (& 35) (! 1.0) (F (* s 0.75)) ]))
((! x) (--> (! (1+ x))))))
;; Parametric 3d tree
(defclass partree1 (l-system)
((axiom :initform '((! 1.0) (F 1.0) (A 1.0)))
(depth :initform 6)))
(defmethod l-productions ((ls partree1))
(choose-production ls
((! x) (--> (! (1+ x))))
((A s) (let ((s1 (* s 0.85))
(s2 (* s 0.75)))
(--> [ (/ 137) (& 25) (! 1.0) (F s1) (A s1) ]
[ (\\ 43) (& 25) (! 1.0) (F s2) (A s2) ])))))
(defclass partree2 (l-system)
((axiom :initform '((:set-width 1.0) (:forward 1.0) (apex 1.0)))
(depth :initform 6)))
(defmethod l-productions ((ls partree2))
(choose-production ls
((:set-width x) (--> (:set-width (1+ x))))
((apex s) (let ((s1 (* s 0.85))
(s2 (* s 0.75)))
(--> [ (:roll-right 137) (:pitch-down 25)
(:set-width 1.0) (:forward s1) (apex s1) ]
[ (:roll-left 43) (:pitch-down 25)
(:set-width 1.0) (:forward s2) (apex s2) ])))))
;; Tree with randomness
(defclass rtree (l-system)
((axiom :initform '((! 10.0) (F 1.0) (A 10.0 1.0)))
(depth :initform 100)))
(defmethod l-productions ((ls rtree))
(choose-production ls
((A width length)
(stochastic-choice
(30 (--> (/ (random 10.0))
(& (- (random 10.0) 5.0))
(! (* width 0.99))
(F length)
(A (* width 0.99) length)))
(1 (--> [ (- 25) (F length) (A width (* length 0.6)) ]
[ (+ 25) (F length) (A width (* length 0.6)) ]))))))
;; Example 4.2.3, "Exploration of parameter space"
;; from "Visual models of plant development"
(defclass partree (l-system)
((axiom :initform '(S))
(depth :initform 11 :initarg :depth)
(r1 :initarg :r1 :initform 0.75)
(r2 :initarg :r2 :initform 0.77)
(a1 :initarg :a1 :initform 35)
(a2 :initarg :a2 :initform -35)
(d1 :initarg :d1 :initform 0)
(d2 :initarg :d2 :initform 0)
(w0 :initarg :w0 :initform 30)
(q :initarg :q :initform 0.50)
(e :initarg :e :initform 0.40)
(min :initarg :min :initform 0.0)))
(defmethod l-productions ((ls partree))
(with-slots (r1 r2 a1 a2 d1 d2 w0 q e min n) ls
(choose-production ls
(S (--> (A 100 w0)))
((A s w)
(if (>= s min)
(--> (! w) (F s)
[ (+ a1) (/ d1) (A (* s r1) (* w (expt q e))) ]
[ (+ a2) (/ d2) (A (* s r2) (* w (expt (- 1 q) e))) ]))))))
;; Simple stochastic tree
(defclass stree (l-system)
((axiom :initform '((! 1) F A))
(depth :initform 10)
(cylinder-width :initform 0.02)))
(defmethod l-productions ((ls stree))
(choose-production ls
((! n) (--> (! (1+ n))))
(A (stochastic-choice
(1 (--> (/ 137)
[ (+ 20) (! 1) F A ]
(- 20) (! 1) F A))
(1 (--> (/ 137)
(- 20) (! 1) F A))))))
;; Stochastic tree model from VMoPD (modified)
(defclass stochastic-tree (l-system)
((axiom :initform '((S 0) (A 1)))
(depth :initform 12)
(homomorphism-depth :initform 10)))
(defmethod l-productions ((ls stochastic-tree))
(let ((turn-ang1 10.0)
(turn-ang2 20.0)
(roll-ang 137.0))
(choose-production ls
((A k)
(let ((p (min 1.0 (/ (1+ (* 2.0 k)) (* k k)))))
(stochastic-choice
(p
(--> (/ roll-ang)
[ (+ turn-ang1) (S 1) (A (1+ k)) ]
(- turn-ang2) (S 1) (A (1+ k))))
((- 1 p)
(--> (/ roll-ang)
(- turn-ang2) (S 1) (A (1+ k)))))))
((S n) (--> (S (1+ n)))))))
(defmethod homomorphism ((ls stochastic-tree))
(choose-production ls
((S n) (--> (! n) F))))
;; Signal test
(defclass signal-test (l-system)
((axiom :initform '(b a a a a a a a a))
(depth :initform 0)))
(defmethod l-productions ((ls signal-test))
(choose-production ls
(a (with-left-context (b) (--> b)))
(b (--> a))))
;; Context-sensitive L-systems from ABoP p. 34--35
(defclass context-a (l-system)
((axiom :initform '(F 1 F 1 F 1))
(depth :initform 30)
(angle-increment :initform 22.5)
(ignore-list :initform '(+ - F))))
(defmethod l-productions ((ls context-a))
(choose-production ls
(0 (with-lc (0)
(with-rc (0) (--> 0))
(with-rc (1) (--> 1 [ + F 1 F 1 ])))
(with-lc (1)
(with-rc (0) (--> 0))
(with-rc (1) (--> 1 F 1))))
(1 (with-lc (0)
(--> 1))
(with-lc (1)
(with-rc (0) (--> 0))
(with-rc (1) (--> 0))))
(+ (--> -))
(- (--> +))))
(defclass context-b (l-system)
((axiom :initform '(F 1 F 1 F 1))
(depth :initform 30)
(angle-increment :initform 22.5)
(consider-list :initform '(0 1))))
(defmethod l-productions ((ls context-b))
(choose-production ls
(0 (with-lc (0)
(with-rc (0) (--> 1))
(with-rc (1) (--> 1 [ - F 1 F 1 ])))
(with-lc (1)
(with-rc (0) (--> 0))
(with-rc (1) (--> 1 F 1))))
(1 (with-lc (0)
(--> 1))
(with-lc (1)
(with-rc (0) (--> 1))
(with-rc (1) (--> 0))))
(+ (--> -))
(- (--> +))))
;; Mycelis muralis (from ABoP, p. 87--90)
(defclass mycelis (l-system)
((axiom :initform '((I 20) Fa (A 0)))
(ignore-list :initform '(+ /))
(homomorphism-depth :initform 10)
(frame-delay :initform 0.5)
(frame-list :initform '((0 100)))
(limits :initform '((-2 -1 -1) (2 14 1)))))
(defmethod l-productions ((ls mycelis))
(choose-production ls
;; Growing apex
((A x)
(with-lc (S) (--> (T 0)))
(if (> x 0)
(--> (A (1- x)))
(--> [ (+ 30) Fb ] Fa (/ 180) (A 2))))
;; Stem segment: propagates signals
(Fa
(with-lc (S) (--> Fa S))
(with-rc ((T c)) (--> (T (1+ c)) Fa)))
;; Undeveloped branch segment
(Fb
(with-lc ((T c) Fa) (--> (I (1- c)) Fa (A 3))))
;; Delayed signal
((I c)
(if (zerop c)
(--> S)
(--> (I (1- c)))))
;; Signals disappers
(S (--> nil))
((T c) (--> nil))))
(defmethod homomorphism ((ls mycelis))
(choose-production ls
(Fa (--> (:color #(0.5 0.2 0.0)) F))
(Fb (--> (:color #(0.0 0.5 0.0)) F))))
;; Polygon test
(defclass polytest (l-system)
((axiom :initform '((:color #(0.6 0.3 0.1)) (! 1) A))
(depth :initform 7)
(angle-increment :initform 22.5)
(line-style :initform :cylinders)
(cylinder-width :initform 0.015)))
(defmethod l-productions ((ls polytest))
(let ((green '#(0.3 1.0 0.3)))
(choose-production ls
(A (--> [ & F L (! 1) A ]
/ / / / /
[ & F L (! 1) A ]
/ / / / / / /
[ & F L (! 1) A ]))
(F (--> S / / / / / F))
(S (--> F L))
((! x) (--> (! (* 1.7 x))))
(L (--> [ (:color green) ^ ^
{ - f. + f. + f. - \| - f. + f. + f. } ])))))
;; Cordate leaf
(defclass leaf (l-system)
((axiom :initform '((F 5) [ A ] [ B ]))
(depth :initform 20)
(angle-increment :initform 10)))
(defmethod l-productions ((ls leaf))
(choose-production ls
(A (--> [ + A { ] \. C }))
(B (--> [ - B { ] \. C }))
(C (--> \f C))))
;; Mesh test
(defclass mesh-test (l-system)
((axiom :initform '(F (:color #(0.5 1.0 0.5))
(:roll-left 180) (:pitch-down 45)
m{
[ (:roll-left 60) (:pitch-up 45) (bow 1 10 10) ]
[ m/ (:roll-right 60) (:pitch-up 45) (bow 1 10 10) ]
m}))
(depth :initform 0)
(angle-increment :initform 45)
(homomorphism-depth :initform 100)))
(defmethod homomorphism ((ls mesh-test))
(choose-production ls
((bow length angle num)
(if (> num 0)
(--> (mf length)
(:pitch-down angle)
(bow length angle (1- num)))))))
;; Mesh test 2
(defclass mesh-test-2 (l-system)
((axiom :initform '((:color #(0.6 0.3 0.15)) (! 1) A))
(depth :initform 7)
(angle-increment :initform 22.5)
(homomorphism-depth :initform 100)
(line-style :initform :cylinders)
(cylinder-width :initform 0.015)))
(defmethod l-productions ((ls mesh-test-2))
(let ((green '#(0.3 1.0 0.3)))
(choose-production ls
(A (--> [ & F L (! 1) A ]
/ / / / /
[ & F L (! 1) A ]
/ / / / / / /
[ & F L (! 1) A ]))
(F (--> S / / / / / F))
(S (--> F L))
((! x) (--> (! (* 1.7 x))))
(L (--> [ (:color green) ^ ^ leaf ])))))
(defmethod homomorphism ((ls mesh-test-2))
(choose-production ls
(leaf (--> (:roll-left 180)
m{
[ (:roll-left 50) (:pitch-up 50) (bow 0.4 20 6) ]
[ m/ (:roll-right 50) (:pitch-up 50) (bow 0.4 20 6) ]
m} ))
((bow length angle num)
(if (> num 0)
(--> (mf length)
(:pitch-down angle)
(bow length angle (1- num)))))))
;; 2d pruning
(defclass prune1 (l-system)
((axiom :initform '([ (! 2)
(- 90) (F 4) (+ 90) (F 8) (+ 90) (F 8)
(+ 90) (F 8) (+ 90) (F 4) ]
F (?P nil)))
(depth :initform 10)
(angle-increment :initform 20)
(sensitive :initform t)))
(defun prune (vec)
(let ((x (aref vec 0))
(y (aref vec 1)))
(or (< x -4) (> x 4) (> y 8) (< y 0))))
(defmethod l-productions ((ls prune1))
(choose-production ls
((?P pos) (if (not (prune pos))
(--> [ + F (?P nil) ] [ - F (?P pos) ])))))
;; Two-face pruning
(defclass prune2face (l-system)
((axiom :initform '([ (! 2) (- 90) (F 4) (+ 90) (F 8) (+ 90) (F 8)
(+ 90) (F 8) (+ 90) (F 4) ]
F (?P nil)))
(mode :accessor mode :initform :grow)
(depth :initform 10)
(angle-increment :initform 20)
(sensitive :initform t)))
(defmethod rewrite :before ((ls prune2face) &optional depth)
(declare (ignore depth))
(setf (mode ls) :grow))
(defmethod rewrite1 :before ((ls prune2face))
(setf (mode ls)
(if (eq (mode ls) :grow)
:cut
:grow)))
(defmethod l-productions ((ls prune2face))
(choose-production ls
((?P pos)
(when (eq (mode ls) :grow)
(--> [ + F (?P nil) ]
[ - F (?P nil) ])))
(F
(when (eq (mode ls) :cut)
(with-rc ((?P pos))
(when (prune pos)
(--> %)))))))
;; Example: 3d pruning
(defun prune-cylinder (pos height radius)
;; prune to a cylinder
(let ((x (aref pos 0))
(y (aref pos 1))
(z (aref pos 2)))
(or (< y 0) (> y height)
(> (+ (* x x) (* z z)) (* radius radius)))))
(defun prune-cylinder-sphere (pos height radius)
;; prune to a cylinder and a (half-)sphere
(let* ((x (aref pos 0))
(y (aref pos 1))
(z (aref pos 2))
(y2 (- y height)))
;; prune if y < 0 or (x y z) is outside both cylinder and sphere
(or (< y 0)
(and (or (> y height) (> (+ (* x x) (* z z)) (* radius radius)))
(> (+ (* x x) (* y2 y2) (* z z)) (* radius radius))))))
(defun prune-sphere (pos radius)
(let* ((x (aref pos 0))
(y (aref pos 1))
(z (aref pos 2))
(y2 (- y radius)))
(> (+ (* x x) (* y2 y2) (* z z)) (* radius radius))))
(defun prune-cube (pos size)
;; prune to a cube
(declare (optimize (speed 3) #+cmu (ext:inhibit-warnings 3))
(type (simple-array double-float (3)) pos))
(let* ((x (aref pos 0))
(y (aref pos 1))
(z (aref pos 2))
(s (coerce size 'double-float))
(size2 (/ s 2d0))
(-size2 (- size2)))
(declare (double-float x y z s size2 -size2))
(or (< y 0) (> y s)
(< x -size2) (> x size2)
(< z -size2) (> z size2))))
(defun prune-cone (pos height radius)
(let ((x (aref pos 0))
(y (aref pos 1))
(z (aref pos 2)))
(or (< y 0) (> y height)
(let ((distance-from-y-axis (sqrt (+ (* x x) (* z z)))))
(> (* height distance-from-y-axis)
(* (- height y) radius))))))
(defun prune-square-hedge (pos height inner-size outer-size)
(declare (optimize (speed 3) #+cmu (ext:inhibit-warnings 3))
(type (simple-array double-float (3)) pos))
(let* ((x (aref pos 0))
(y (aref pos 1))
(z (aref pos 2))
(h (coerce height 'double-float))
(isize (coerce inner-size 'double-float))
(osize (coerce outer-size 'double-float))
(-isize (- isize))
(-osize (- osize)))
(declare (double-float x y z h isize osize -isize -osize))
(or (< y 0d0) (> y h)
(> x osize) (< x -osize)
(> z osize) (< z -osize)
(and (< -isize x isize)
(< -isize z isize)))))
(defclass prune2 (l-system)
((axiom :initform '((! 1) F (?P nil)))
(depth :initform 15)
(homomorphism-depth :initform 100)
(sensitive :initform t)))
(defmethod l-productions ((ls prune2))
(choose-production ls
((! n) (--> (! (1+ n))))
((?P pos) (when (not (prune-cylinder pos 10 6))
(stochastic-choice
(9 (--> (/ 137)
[ (+ 40) (! 1) F (?P pos) leaf ]
(- 35) (! 1) F (?P pos) leaf ))
(1 (--> (/ 137)
(- 35) (! 1) F (?P pos) leaf)))
(--> permanent-leaf)))
(leaf (--> nil))))
(defmethod homomorphism ((ls prune2))
(choose-production ls
(permanent-leaf (--> leaf))
(leaf (let* ((n 4)
(start-ang 40)
(ang (/ (* start-ang 2.0) (1- n)))
(distance 1.0)
(dist (/ distance n)))
(--> (:pitch-down 65) (:color '#(0.3 1.0 0.3))
m{
[ (:roll-left 40) (:pitch-up start-ang) (bow ang n dist) ]
[ m/ (:roll-right 40) (:pitch-up start-ang) (bow ang n dist) ]
m})))
((bow ang n dist) (if (> n 0)
(--> (mf dist) (:pitch-down ang)
(bow ang (1- n) dist))))))
;; Improved pruning
(defclass prune3 (l-system)
((axiom :initform '((:color #(0.8 0.4 0.2)) (?T nil)))
(depth :initform 18)
(homomorphism-depth :initform 10)
(sensitive :initform t)
(prune-func :accessor prune-func
:initform #'(lambda (pos) (prune-cylinder pos 15 6)))
(limits :initform '((-7 -1 -7) (7 15 7)))
(cylinder-width :initform 0.02)))
(defmethod l-productions ((ls prune3))
(choose-production ls
((?T turtle)
(let ((prune-func (prune-func ls)))
;; try moving one unit forward and see if we need to prune
(move-forward turtle 1d0)
(if (funcall prune-func (turtle-pos turtle))
;; pruning: use interval halving to find out by how much
(let ((length nil))
(move-forward turtle -1d0)
(do* ((lower 0d0)
(upper 1d0)
(middle (/ (- upper lower) 2) (/ (- upper lower) 2))
(original-pos (copy-seq (turtle-pos turtle)))
(n 0 (1+ n)))
((= n 5) (setq length middle))
(setf (turtle-pos turtle) (copy-seq original-pos))
(move-forward turtle middle)
(if (funcall prune-func (turtle-pos turtle))
(setq upper middle)
(setq lower middle)))
;; return a segment that will not grow any more
(--> (! 1) (F length) permanent-leaf))
;; no pruning, normal growth
(if (< (current-depth ls) 4)
(--> (! 1) (F 1) leaf (/ 137)
[ (- 35) (?T nil) ] (+ 40) (?T nil))
(stochastic-choice
(9 (--> (! 1) (F 1) leaf (/ 137)
[ (- 35) (?T nil) ] (+ 40) (?T nil)))
(1 (--> (! 1) (F 1) leaf (/ 137) (+ 40) (?T nil))))))))
;; leaves move by disappearing and getting recreated...
(leaf (--> nil))
;; branch width
((! x) (when (< x 4) (--> (! (+ x 0.5)))))))
(defmethod homomorphism ((ls prune3))
(choose-production ls
(permanent-leaf (--> leaf))
(leaf (let* ((n 4)
(start-ang 40)
(ang (/ (* start-ang 2.0) (1- n)))
(distance 1.0)
(dist (/ distance n)))
(--> (:pitch-down 65) (:color '#(0.3 1.0 0.3))
m{
[ (:roll-left 40) (:pitch-up start-ang) (bow ang n dist) ]
[ m/ (:roll-right 40) (:pitch-up start-ang) (bow ang n dist) ]
m})))
((bow ang n dist) (if (> n 0)
(--> (mf dist) (:pitch-down ang)
(bow ang (1- n) dist))))))
;; L-system inherited from PRUNE3:
(defclass prune3-1 (prune3)
((axiom :initform '((:color #(0.8 0.4 0.2))
[ (@M #(15 0 15)) (?T nil) ]
[ (@M #(-15 0 -15)) (?T nil) ]
[ (@M #(-15 0 15)) (?T nil) ]
[ (@M #(15 0 -15)) (?T nil) ]
[ (@M #(0 0 0)) (?T nil) ]))
(prune-func :initform #'(lambda (pos)
(and (prune-square-hedge pos 8 12 18)
(prune-cylinder-sphere pos 10 5))))))
;; Climbing plant
(defun crash-box (box point)
(let* ((minv (box-pos box))
(maxv (vec+ minv (box-size box))))
(and (< (aref minv 0) (aref point 0) (aref maxv 0))
(< (aref minv 1) (aref point 1) (aref maxv 1))
(< (aref minv 2) (aref point 2) (aref maxv 2)))))
(defun crash-boxes (boxes point)
(dotimes (i (length boxes))
(when (crash-box (svref boxes i) point)
(return t))))
(defun crash-cylinder-axis (x1 y1 z1 x2 y2 z2 x y z width)
(assert (and (= y1 y2) (= z1 z2)))
;; (format t "cyl (~A ~A ~A) (~A ~A ~A) ~A, point (~A ~A ~A)~%"
;; x1 y1 z1 x2 y2 z2 width x y z)
(labels ((** (n) (* n n)))
(let ((xmin (min x1 x2))
(xmax (max x1 x2)))
(and (< xmin x xmax)
(< (+ (** (- y y1))
(** (- z z1)))
(** width))))))
(defun crash-cylinder (line point)
(let* ((p1 (line-p1 line))
(p2 (line-p2 line))
(x1 (aref p1 0))
(y1 (aref p1 1))
(z1 (aref p1 2))
(x2 (aref p2 0))
(y2 (aref p2 1))
(z2 (aref p2 2))
(width (line-width line))
(x (aref point 0))
(y (aref point 1))
(z (aref point 2)))
(cond ((and (= y1 y2) (= z1 z2))
(crash-cylinder-axis x1 y1 z1 x2 y2 z2 x y z width))
((and (= x1 x2) (= z1 z2))
(warn "fy")
(crash-cylinder-axis y1 x1 z1 y2 x2 z2 y x z width))
((and (= x1 x2) (= y1 y2))
(warn "fz")
(crash-cylinder-axis z1 x1 y1 z2 x2 y2 z x y width))
(t
(error "Only works with cylinders parallel to an axis.")))))
(defun crash-cylinders (lines point)
(dotimes (i (length lines))
(when (crash-cylinder (svref lines i) point)
(return t))))
(defparameter *init-boxes* '#((:box #(-50 0 -10) #(100 50 10))))
(defparameter *init-cylinders* '#((:line #(-50 50 -5) #(50 50 -5) 5)))
(defclass climbing1 (l-system)
((axiom :initform (concatenate
'list
'(\[ (:color #(1.0 0.6 0.6))
(:produce-spheres nil))
*init-boxes*
*init-cylinders*
'(\]
(:color #(0.4 1.0 0.4)) (! 0.15)
[ (@M #(-30 0 0))
(searching-apex 0 22.5 20) (?P nil) ]
[ (@M #(30 0 0))
(searching-apex 0 22.5 20) (?P nil) ])))
(boxes :accessor boxes
:initform (turtle-interpret *init-boxes*))
(cylinders :accessor cylinders
:initform (turtle-interpret *init-cylinders*))
(line-style :initform :cylinders)
(frame-list :initform '((0 1000)))
(frame-delay :initform 0.0)
(depth :initform 100)
(sensitive :initform t)
(homomorphism-depth :initform 100)))
(defmethod l-productions ((ls climbing1))
(flet ((crash (pos)
(or (< (aref pos 1) 0)
(crash-boxes (boxes ls) pos)
(crash-cylinders (cylinders ls) pos))))
(let ((rstep 5d0)
(maxr 95d0)
(bstep -2d0)
(branch-distance 20)
(leaf-distance 10)
(branch-angle 60d0)
(random-turn 5d0))
(choose-production ls
((searching-apex roll pitch n)
(with-rc ((?P pos))
(if (crash pos)
(progn
#+nil(if (>= (aref pos 1) 55)
(format t "crash ~A???~%" pos)
(format t "crash with y=~A~%" (aref pos 1)))
(--> (backtracking-apex roll pitch n)))
(let ((npitch (+ pitch rstep)))
(if (< npitch maxr)
(--> (searching-apex roll npitch n))
(--> (searching-apex (+ roll 45) 0d0 n)))))))
((backtracking-apex roll pitch n)
(with-rc ((?P pos))
(if (crash pos)
(--> (backtracking-apex roll (+ pitch bstep) n))
(cond ((zerop n)
(--> (segment roll pitch)
[ (:turn-left (stochastic-choice
(1 branch-angle)
(1 (- branch-angle))))
(searching-apex 0d0 0d0 branch-distance)
(?P nil) ]
(searching-apex 0d0 0d0 branch-distance)))
((zerop (mod (+ n (floor leaf-distance 2))
leaf-distance))
(--> (segment roll pitch)
(leaf 6 (+ 35d0 (random 10d0)) 0.1d0)
(:turn-right (nrandom 0d0 random-turn))
(searching-apex 0d0 0d0 (- n 1))))
(t
(--> (segment roll pitch)
(:turn-right (nrandom 0d0 random-turn))
(searching-apex 0d0 0d0 (- n 1))))))))
((leaf n start-ang size)
(--> (leaf n start-ang (min 5d0 (+ size 0.1)))))))))
(defmethod homomorphism ((ls climbing1))
(choose-production ls
((searching-apex r p n) (--> (segment r p)))
((backtracking-apex r p n) (--> (segment r p)))
((segment roll pitch) (--> (:roll-left roll) (:pitch-down pitch)
:forward))
((leaf n start-ang size)
(let ((ang (/ (* start-ang 2.0) (1- n)))
(dist (/ size n)))
(--> [ (:pitch-up 170) (:roll-left 180)
m{
[ (:roll-left 60) (:pitch-up start-ang) (bow ang n dist) ]
[ m/ (:roll-right 60) (:pitch-up start-ang) (bow ang n dist) ]
m} ])))
((bow ang n dist) (if (> n 0)
(--> (mf dist) (:pitch-down ang)
(bow ang (1- n) dist))))))
;; Simple tropism
(defclass tropism1 (l-system)
((axiom :initform '((A 100 12)))
(depth :initform 11)
(homomorphism-depth :initform 10)
(tropism-vector :accessor tropism-vector
:initarg :tropism-vector
:initform '#(0d0 -1d0 0d0))
(tropism-angle :accessor tropism-angle
:initarg :tropism-angle
:initform 1.0)))
(defmethod l-productions ((ls tropism1))
(choose-production ls
((A s w) (--> (S s w)
[ (+ 30) (/ 137) (A (* s 0.8) (* w 0.8)) ]
[ (- 10) (/ -90) (A (* s 0.9) (* w 0.8)) ]))))
(defmethod homomorphism ((ls tropism1))
(choose-production ls
((S s w) (--> (:rotate-towards (tropism-angle ls) (tropism-vector ls))
(! w) (F s)))))
;; Tropism with hvec
(defclass tropism2 (l-system)
((axiom :initform '((A 100 12) (?H nil)))
(depth :initform 11)
(homomorphism-depth :initform 10)
(tropism-vector :accessor tropism-vector
:initarg :tropism-vector
:initform '#(0d0 -1d0 0d0))
(elasticity-const :accessor elasticity-const
:initarg :elasticity-const
:initform 15)))
(defmethod l-productions ((ls tropism2))
(choose-production ls
((A s w) (with-rc ((?H hvec))
(--> (S s w hvec)
[ (+ 30) (/ 137) (A (* s 0.8) (* w 0.8)) (?H nil) ]
[ (- 10) (/ -90) (A (* s 0.9) (* w 0.8)) (?H nil) ])))
((?H hvec) (--> nil))))
(defmethod elasticity ((ls tropism2) s w)
(declare (ignorable s w))
(elasticity-const ls))
(defmethod homomorphism ((ls tropism2))
(choose-production ls
((S s w hvec)
(let* ((elasticity (elasticity ls s w))
(tvec (map '(simple-array double-float)
#'identity
(tropism-vector ls)))
(HxT (cross-product hvec tvec))
(angle (* elasticity (vlength HxT))))
(--> (:set-width w)
(:rotate-towards angle (tropism-vector ls))
(:forward s))))))
;; Different elasticiy function: smaller widths -> larger elasticity
(defclass tropism3 (tropism2)
((elasticity-const :initform 50)))
(defmethod elasticity ((ls tropism3) s w)
(declare (ignorable s w))
(/ (elasticity-const ls) w))
;; Yet another elasticiy function
(defclass tropism4 (tropism2)
((elasticity-const :initform 5)
(param1 :initarg :param1
:accessor param1
:initform 20)
(tropism-vector :initform #(1d0 0d0 0d0))))
(defmethod elasticity ((ls tropism4) s w)
(declare (ignorable s w))
(+ (elasticity-const ls)
(/ (param1 ls) w)))
;; Good-looking tropism tree
(defclass gtropism (l-system)
((axiom :initform '((:color #(0.8 0.4 0.2))
(A 100 12) (?H nil)))
(depth :initform 12)
(homomorphism-depth :initform 10)))
(defmethod l-productions ((ls gtropism))
(choose-production ls
((A s w) (with-rc ((?H hvec))
(let ((x (if (<= (current-depth ls) 2)
0
1)))
(stochastic-choice
(x (--> (S s w hvec)
(/ 137) (A (* s 0.8) (* w 0.8)) (?H nil)))
(9 (--> (S s w hvec)
[ (+ 30) (/ 137) (A (* s 0.8) (* w 0.8)) (?H nil) ]
[ (- 10) (/ -90) (A (* s 0.9) (* w 0.8)) (?H nil) ]))))))
((?H hvec) (--> nil))))
(defmethod homomorphism ((ls gtropism))
(choose-production ls
((S s w hvec)
(if (> s 10)
(let ((s/2 (/ s 2)))
(--> (S s/2 w hvec) (S s/2 w hvec)))
(let* ((elasticity (* s (/ 1.5 w)))
(tvec (vec3 0d0 -1d0 0d0))
(HxT (cross-product hvec tvec))
(angle (* elasticity (vlength HxT))))
(--> (:set-width w)
(:rotate-towards angle tvec)
(:forward s)))))))
;; Using homomorphism to create bent branch segments
(defclass bent (l-system)
((axiom :initform '((:color #(0.8 0.4 0.2))
(bent-branch 0 0 1 8 8 1) (apex 1.0)))
(depth :initform 6)
(homomorphism-depth :initform 100)))
(defmethod l-productions ((ls bent))
(choose-production ls
((apex s) (let ((s1 (* s 0.95))
(s2 (* s 0.85))
(n 8))
(--> [ (bent-branch 137 25 s1 n n 1.0) (apex s1) ]
[ (bent-branch -43 25 s2 n n 1.0) (apex s2) ])))
((bent-branch roll pitch length n m width)
(--> (bent-branch roll pitch length n m (1+ width))))))
(defmethod homomorphism ((ls bent))
(choose-production ls
((bent-branch roll pitch length n m width)
(if (<= n 0)
(--> nil)
(let ((rollf (/ roll n))
(pitchf (/ pitch n))
(lengthf (/ length n)))
(--> (:set-width (+ width (/ n m)))
(:roll-right rollf)
(:pitch-down pitchf)
(:forward lengthf)
(bent-branch (- roll rollf) (- pitch pitchf)
(- length lengthf) (1- n) m width)))))))
;; Cut symbol test
(defclass cut-test (l-system)
((axiom :initform '([ + (F 7 0) - (F 10 0) - (F 14 0)
- (F 10 0) - (F 7 0) ]
(! 1) A))
(depth :initform 7)
(frame-list :initform '((1 7)))
(frame-delay :initform 1)))
(defmethod l-productions ((ls cut-test))
(choose-production ls
((! n) (--> (! (1+ n))))
((F x) (--> (F (* x 1.1))))
(A (--> (F 1)
[ (+ 25) (! 1) X A ]
[ (- 25) (! 1) X A ]))
(X (stochastic-choice
(19 (--> X))
(0 (--> A :cut-symbol))))))
;; Sphere test
(defclass sphere-test (l-system)
((axiom :initform '(F (:sphere 3) F
(:color #(0 0.5 1.0))
(:sphere 3) F))))
;; Constant curvature (growing arc)
(defclass const-curvature (l-system)
((axiom :initform '((A 1.5) (A 0.0)))
(decomposition-depth :initform 10)
(homomorphism-depth :initform 10)
;; Animation parameters
(frame-delay :initform 0.05)
(frame-list :initform '((0 500)))
(limits :initform '((-1 -3 -1) (6 3 1)))))
(defmethod l-productions ((ls const-curvature))
(choose-production ls
((A x) (--> (A (* x 1.01))))))
(defmethod decomposition ((ls const-curvature))
(choose-production ls
((A x) (when (> x 1.5)
;; Use "golden ratio" to split segment;
;; the number of segments will then always be
;; a Fibonacci number.
(let* (;;(factor 0.61803398875)
(factor 0.4)
(x1 (* x factor))
(x2 (* x (- 1 factor))))
(--> (A x1) (A x2)))))))
(defmethod homomorphism ((ls const-curvature))
(let ((curvature 10))
(choose-production ls
((A x) (let ((angle (* curvature x)))
(--> (+ angle) (:sphere 4)
(F x) (+ angle)))))))
;; Contact points
(defclass contact-points (l-system)
((axiom :initform '([ (! 0.01) (+ 90) (\f 1)
(+ 90) (F 0.5) (+ 90) (F 22) (+ 90) (F 1)
(+ 90) (F 22) (+ 90) (F 1) ]
(- 90) (A 1 0 -1) X))
(depth :initform 10)
(decomposition-depth :initform 10)
(homomorphism-depth :initform 10)
(growth-rate :accessor growth-rate :initform 1.01)
(cp-interval :accessor cp-interval :initform 5.0)
(stem-pos :accessor stem-pos)
(next-rotation-point :accessor next-rotation-point)
(max-length :accessor max-length :initform 1.0)
(frame-list :initform '((1 290)))
(frame-delay :initform 0.02)))
(defmethod rewrite :before ((ls contact-points) &optional (depth (depth ls)))
(declare (ignorable depth))
(setf (next-rotation-point ls) (cp-interval ls)))
(defmethod rewrite1 :before ((ls contact-points))
(setf (stem-pos ls) 0.0))
(defmethod l-productions ((ls contact-points))
(choose-production ls
((A s p c)
(with-slots (growth-rate cp-interval stem-pos next-rotation-point) ls
(let ((new-s (* s growth-rate))
(this-pos stem-pos))
(incf stem-pos new-s)
;; contact point exists and remains
(when (>= c this-pos)
(--> (A new-s this-pos c)))
;; CP disappears to the left
(when (< 0 c this-pos)
(--> (A new-s this-pos -1)))
;; new CP from the right
(with-rc ((A sr pr cr))
(when (< cr stem-pos)
(--> (A new-s this-pos cr))))
;; create new CP at the apex
(with-rc (X)
(when (> stem-pos next-rotation-point)
(let ((new-c next-rotation-point))
(incf next-rotation-point cp-interval)
(--> (A new-s this-pos new-c)))))
;; no CP
(--> (A new-s this-pos c)))))))
(defmethod decomposition ((ls contact-points))
(choose-production ls
((A s p c)
(when (> s (max-length ls))
(let ((s/2 (/ s 2.0))
(c1 -1)
(c2 -1))
(when (>= c 0)
(if (< c (+ p s/2))
(setq c1 c)
(setq c2 c)))
(--> (A s/2 p c1) (A s/2 (+ p s/2) c2)))))))
(defmethod homomorphism ((ls contact-points))
(choose-production ls
((A s p c)
(if (< c 0)
(--> (@O 3) (F s))
(let* ((s1 (- c p))
(s2 (- s s1)))
(--> (@O 3) (F s1) (@O 6) (F s2)))))))
;; Good looking tree (combines randomness, bent branches and mesh leaves)
(defclass gtree (l-system)
((axiom :initform '((:color #(0.8 0.4 0.3)) (:tropism 1.2)
(S 1 0 0 2) A))
(depth :initform 10)
(homomorphism-depth :initform 20)
(line-style :initform :cylinders)
(cylinder-width :initform 1.0)
(sensitive :initform nil)))
(defmethod l-productions ((ls gtree))
(choose-production ls
((S width roll turn length) (--> (S (1+ width) roll turn
(* length 1.15))))
(A (stochastic-choice
(3
(--> [ (S 1 137 (nrandom 30 10) (nrandom 1.5 0.5)) A ]
(:turn-right 20)
(S 1 137 (nrandom -30 10) (nrandom 1.5 0.5)) A))
((if (< (current-depth ls) 3) 0 1)
(--> [ (:turn-left 20) L ] ;;(- 20)
(S 1 137 (nrandom 10 10) (nrandom 1.5 0.5)) A))))))
(defmethod homomorphism ((ls gtree))
(let ((steps 4)
(leaf-steps 4))
(choose-production ls
((S width roll turn length)
;;(format t "~A~%" (current-module ls))
(--> (bent-branch (1+ width) (/ roll steps) (/ turn steps)
(/ length steps) 0)))
((bent-branch width roll turn length n)
(when (< n steps)
(--> (wid width) (:roll-left roll) (:turn-left turn)
(:forward length)
(bent-branch (- width (/ 0.1 steps)) roll turn length (1+ n)))))
(L (stochastic-choice
(1 (--> A))
(1 (--> (berry 0.8)))))
((berry size)
(--> [ (:turn-left (nrandom 45 10)) (:forward size)
(:color #(1.0 0.2 0.2)) (:sphere size) ]))
(A (--> (:color #(0.2 0.7 0.2))
(:roll-left (random 360))
(leaf (nrandom 55 10) 60 (nrandom 4 0.2))))
((leaf start-roll start-angle size)
(let ((pitch-step (/ start-angle (1+ leaf-steps) 0.5))
(size-step (/ size leaf-steps)))
;;(format t "~A~%" (current-module ls))
(--> (wid 0.7) (:forward 0.1)
(:tropism nil) (:pitch-down 25d0)
:start-mesh
[ (:roll-left start-roll) (:pitch-up start-angle)
:new-strand (bent-leaf pitch-step size-step 0) ]
[ (:roll-right start-roll) (:pitch-up start-angle)
:new-strand (bent-leaf pitch-step size-step 0) ]
:end-mesh)))
((bent-leaf pitch-step size-step n)
(when (< n leaf-steps)
(--> (:pitch-down pitch-step) (mf size-step)
(bent-leaf pitch-step size-step (1+ n)))))
((wid x)
(--> (:set-width (* 0.045 x)))))))
| 37,549 | Common Lisp | .lisp | 986 | 28.590264 | 91 | 0.473501 | cbaggers/l-lisp | 11 | 2 | 2 | GPL-2.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 4dc1a23af02bf5db4e526cc7574efad21506b81d904d2566f2c998f003198bc8 | 7,947 | [
-1
] |
7,948 | packages.lisp | cbaggers_l-lisp/packages.lisp | (in-package :cl-user)
(uiop:define-package :l-systems
(:nicknames :lsystem :lsys :ls)
(:use :cl)
(:export
;; trigonometry
:deg-to-rad :rad-to-deg :cosd :sind :tand
;; 3D vectors
:v3 :vec3 :vlength :normalize :equalvec :almost-equalvec :zerovec :vec- :vec+
:dot-product :cross-product
;; turtle
:turtle :turtle-pos :turtle-H :turtle-L :turtle-U :turtle-angle :turtle-width
:turtle-prev-width :turtle-color :turtle-texture :copy-turtle :rotate
:rotate-towards :turn :pitch :roll :move-forward :turtle-interpret
:def-turtle-function-raw :def-turtle-function :turtle-function
;; geometric shapes
:line :line-p1 :line-p2 :line-width
:box :box-pos :box-size
;; short names of turtle functions
:F :\f :+ :- :\& :\^ :\\ :/ :\| :! :@O :\{ :\. :f. :\} :m{ :m. :m/ :m} :mf :@M :@R
:?P :?H :?U :?L :?T :\[ :\] :\%
;; creating images
:output-simple-eps :output-povray
;; l-system class
:l-system :axiom :depth :angle-increment :ignore-list :consider-list
:homomorphism-depth :decomposition-depth :sensitive
:rstring :hstring :geometry :current-depth :current-module
:line-style :cylinder-width :limits :frame-delay :frame-list
;; rewriting
:l-productions :homomorphism :decomposition
:rewrite :rewrite1 :homomorphism-rewrite :decomposition-rewrite
;; geometry methods
:create-geometry :rewrite-and-preview :rewrite-and-raytrace
:timed-raytrace :timed-preview :lsys2eps :lsys2pov
:eps-animation :povray-animation
:top-of-framelist :next-framelist :extract-framelist
;; l-system macros
:choose-production :--> :stochastic-choice
:with-left-context :with-right-context :with-lc :with-rc
:while-ignoring :while-considering
;; OpenGL stuff
:gl-preview :gl-animation
;; Random number generation
:nrandom))
(uiop:define-package :spline-editor
(:nicknames :splineed :spline)
(:use :cl)
(:export
:spline :spline-x :spline-y :spline-a :spline-b :spline-b :spline-c :spline-d
:spline-function :natural-cubic-spline :spline-value :spline-values
:make-spline-function :output-spline :input-spline :output-spline-to-eps
:edit-spline))
(uiop:define-package :l-system-examples
(:nicknames :lsx)
(:use :common-lisp :l-systems :spline-editor))
| 2,261 | Common Lisp | .lisp | 55 | 37.418182 | 85 | 0.697685 | cbaggers/l-lisp | 11 | 2 | 2 | GPL-2.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 193f9f8f01a6a12889d1fe5f20b4f18eae2ca2ee2623c0dabfd7ae14a0345be4 | 7,948 | [
-1
] |
7,961 | Makefile | cbaggers_l-lisp/Makefile |
CMULISP = lisp
all: compile
compile:
$(CMULISP) -eval '(progn (mk:compile-system :l-lisp) (ext:quit))'
clean:
rm -f *.x86f *.err *~
| 138 | Common Lisp | .l | 6 | 21 | 66 | 0.671875 | cbaggers/l-lisp | 11 | 2 | 2 | GPL-2.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 2b3d00d44417365faf74adcce790548690bcab3512d32aa98b45cf92f873abdb | 7,961 | [
-1
] |
7,978 | parsing-macro-2.lisp | mabragor_cl-yaclyaml/parsing-macro-2.lisp | (in-package #:cl-yaclyaml)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defmacro define-alias-rule (alias rule)
`(define-yaclyaml-rule ,alias ()
(progn ,(maybe-wrap-in-descent rule)
nil))))
(eval-when (:compile-toplevel :load-toplevel :execute)
(defmacro define-context-forcing-rule (context-name forsee-name &optional (expression forsee-name))
`(define-yaclyaml-rule ,(symbolicate context-name "-" forsee-name) ()
(let ((context ,(make-keyword context-name)))
,(maybe-wrap-in-descent expression)))))
;; KLUDGE: better to learn how to define alias names for ESRAP contexts
(eval-when (:compile-toplevel :load-toplevel :execute)
(defmacro define-yy-rule (symbol args &body body)
`(define-yaclyaml-rule ,symbol ,args ,@body))
(defmacro yy-parse (expression text &key (start nil start-p)
(end nil end-p)
(junk-allowed nil junk-allowed-p))
`(yaclyaml-parse ,expression ,text
,@(if start-p `(:start ,start))
,@(if end-p `(:end ,end))
,@(if junk-allowed-p
`(:junk-allowed ,junk-allowed)))))
| 1,082 | Common Lisp | .lisp | 23 | 42.347826 | 101 | 0.683712 | mabragor/cl-yaclyaml | 14 | 3 | 8 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 3f7a974b5354a7d3376d76766b61722e6f7dde153c4aaf151f5c6f4fce6633b9 | 7,978 | [
-1
] |
7,979 | schema.lisp | mabragor_cl-yaclyaml/schema.lisp | ;;;; This file is one of components of CL-YACLYAML system, licenced under GPL, see COPYING for details
(in-package :cl-yaclyaml)
(defclass yaml-schema () ()
(:documentation "Base class for yaml schemas."))
(defgeneric install-converters (schema)
(:method-combination progn :most-specific-last)
(:documentation "Install converters for a schema before parsing."))
(defclass yaml-schema-unspecific-mixin (yaml-schema) ()
(:documentation "Mixin to add a scalar-converter for :non-specific that
calls CONVERT-NON-SPECIFIC-SCALAR with the schema and the content."))
(defgeneric convert-non-specific-scalar (schema content)
(:documentation "Convert the content of a non-specific scalar node based
on the schema. Default implementation just calls CONVERT-SCALAR with the str tag.
Implementations should call CALL-NEXT-METHOD for contents it doesn't know how to process.")
(:method (schema content)
(declare (ignore schema))
(convert-scalar content "tag:yaml.org,2002:str")))
(defmethod install-converters progn ((schema yaml-schema-unspecific-mixin))
(install-scalar-converter :non-specific
(lambda (content)
(convert-non-specific-scalar schema content))))
(defmacro with-schema (schema &body body)
"Execute BODY in a context where SCALAR-CONVERTERS, SEQUENCE-CONVERTERS, and
MAPPING-CONVERTERS have been bound to new hash tables with converters
installed by the schema."
`(let ((scalar-converters (make-hash-table :test #'equal))
(sequence-converters (make-hash-table :test #'equal))
(mapping-converters (make-hash-table :test #'equal)))
(install-converters ,schema)
,@body))
(defclass failsafe-schema (yaml-schema) ()
(:documentation "Implementation of the failsafe schema for yaml."))
(defmethod install-converters progn ((schema failsafe-schema))
(install-scalar-converter "tag:yaml.org,2002:str" #'trivial-scalar-converter)
(install-sequence-converter "tag:yaml.org,2002:seq" #'convert-sequence-to-list)
(install-mapping-converter "tag:yaml.org,2002:map" #'convert-mapping-to-hashtable))
(defclass json-schema (failsafe-schema yaml-schema-unspecific-mixin) ()
(:documentation "Implementation of the json schema for ymal."))
(defmethod install-converters progn ((schema json-schema))
(install-scalar-converter "tag:yaml.org,2002:null" (lambda (content)
(declare (ignore content))))
(install-scalar-converter "tag:yaml.org,2002:bool"
(lambda (content)
(if (equal content "true")
t
(if (equal content "false")
nil
(error "Expected 'true' or 'false' but got ~a." content)))))
(install-scalar-converter "tag:yaml.org,2002:int"
(lambda (content)
(parse-integer content)))
(install-scalar-converter "tag:yaml.org,2002:float"
(lambda (content)
(parse-real-number content)))
(install-sequence-converter :non-specific
(lambda (content)
(convert-sequence content "tag:yaml.org,2002:seq")))
(install-mapping-converter :non-specific
(lambda (content)
(convert-mapping content "tag:yaml.org,2002:map"))))
(defmethod convert-non-specific-scalar ((schema json-schema) content)
(cond ((or (equal content :empty)
(all-matches "^null$" content))
(convert-scalar content "tag:yaml.org,2002:null"))
((all-matches "^(true|false)$" content) (convert-scalar content
"tag:yaml.org,2002:bool"))
((all-matches "^-?(0|[1-9][0-9]*)$" content) (convert-scalar content
"tag:yaml.org,2002:int"))
((all-matches "^-?(0|[1-9][0-9]*)(\\.[0-9]*)?([eE][-+]?[0-9]+)?$" content)
(convert-scalar content "tag:yaml.org,2002:float"))
(t (error "Could not resolve scalar: ~a" content))))
(defclass core-schema (json-schema yaml-schema-unspecific-mixin) ()
(:documentation "Implementation of the core schema for yaml."))
(defmethod convert-non-specific-scalar ((schema core-schema) content)
(cond ((or (equal content :empty)
(all-matches "^(null|Null|NULL|~)$" content))
(convert-scalar content "tag:yaml.org,2002:null"))
((all-matches "^(true|True|TRUE|false|False|FALSE)$" content)
(convert-scalar (string-downcase content) "tag:yaml.org,2002:bool"))
((all-matches "^[-+]?(0|[1-9][0-9]*)$" content)
(convert-scalar content "tag:yaml.org,2002:int"))
((all-matches "^0o[0-7]+$" content)
(parse-integer content :start 2 :radix 8))
((all-matches "^0x[0-9a-fA-F]+$" content)
(parse-integer content :start 2 :radix 16))
((all-matches "^[-+]?(\\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$" content)
(convert-scalar content "tag:yaml.org,2002:float"))
((all-matches "^[-+]?(\\.inf|\\.Inf|\\.INF)$" content)
:infinity)
((all-matches "^[-+]?(\\.nan|\\.NaN|\\.NAN)$" content)
:nan)
(t
(convert-scalar content "tag:yaml.org,2002:str"))))
(defparameter schemas (make-hash-table :test 'eq)
"Hash table of available schemas. The keys are symbols and the
values are instances of YAML-SCHEMA.")
(defun register-schema (name class-name &rest init-args)
(declare (type symbol name class-name))
"Register a schema with a symbol. After registering, the symbol can be passed
as the SCHEMA argument to the parsing functions.
This function creates a new instance of CLASS-NAME with the arguments passed as
INIT-ARGS and registers it with the symbol NAME.
NAME: The symbol for the schema to be registered.
CLASS-NAME: The symbol for the name of the class of the schema to create and register.
INIT-ARGS: Additional arguments to pass to MAKE-INSTANCE."
(setf (gethash name schemas)
(apply #'make-instance class-name init-args)))
;;; Initially populate the schemas table.
(register-schema :failsafe 'failsafe-schema)
(register-schema :json 'json-schema)
(register-schema :core 'core-schema)
| 6,500 | Common Lisp | .lisp | 111 | 47.828829 | 102 | 0.627356 | mabragor/cl-yaclyaml | 14 | 3 | 8 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 960c7c8feabfcd23cebe0827431b59d02b0911d92e82d39d04d5b58193e476dc | 7,979 | [
-1
] |
7,980 | package.lisp | mabragor_cl-yaclyaml/package.lisp | ;;;; package.lisp
(defpackage #:cl-yaclyaml
(:nicknames #:cl-yy)
(:use #:cl #:iterate #:rutils.string #:esrap-liquid #:parse-number #:cl-ppcre)
;; (:shadowing-import-from #:cl-test-more
;; :ok :plan :finalize :is :isnt :is-expand :diag)
(:shadowing-import-from #:alexandria #:flatten #:symbolicate #:make-keyword #:with-gensyms #:once-only)
(:export #:yaclyaml-parse #:yy-parse
#:ncompose-representation-graph #:construct #:yaml-load #:hash->assoc #:yaml-simple-load
#:yaml-load-file #:define-yaml-config
#:nserialize #:represent-node
;; For custom schemas:
#:yaml-schema #:install-converters
#:yaml-schema-unspecific-mixin #:convert-non-specific-scalar
#:failsafe-schema #:json-schema #:core-schema
#:register-schema
;; Conversion of parsed data
#:install-scalar-converter #:install-sequence-converter #:install-mapping-converter
#:install-sequence-list-converter #:install-mapping-hashtable-converter
#:convert-node #:convert-scalar #:convert-sequence #:convert-mapping
#:convert-sequence-to-list #:convert-mapping-to-hashtable))
| 1,198 | Common Lisp | .lisp | 21 | 49.285714 | 105 | 0.653912 | mabragor/cl-yaclyaml | 14 | 3 | 8 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | b045fa07b08117d1001500fb84f17af7cebc2e3ecf9191a17c8083c328389554 | 7,980 | [
-1
] |
7,981 | representing.lisp | mabragor_cl-yaclyaml/representing.lisp | ;;;; This file is one of components of CL-YACLYAML system, licenced under GPL, see COPYING for details
(in-package #:cl-yaclyaml)
;;; Representing native structures as sequences, mappings and scalars with tags.
(defparameter tag-prefix "tag:yaml.org,2002:")
(defparameter lisp-tag-prefix "tag:lisp,2013:")
(defparameter cons-maps-as-maps nil "If T, represent alists and plists as mappings, not as sequences")
(defun represent-scalar (x)
(flet ((frob (type obj &optional (prefix tag-prefix))
;; FIXME: maybe FORMAT-aesthetic on the next line is not what we really want?
(values `((:properties . ((:tag . ,(strcat prefix type)))) (:content . ,(format nil "~a" obj))) t)))
(typecase x
(integer (frob "int" x))
(float (frob "float" x))
(string (frob "str" x))
(symbol (cond ((eq x t) (frob "bool" "true"))
((eq x nil) (frob "null" "null"))
((keywordp x) (frob "keyword" x lisp-tag-prefix))
(t (frob "symbol" x lisp-tag-prefix))))
(t (values nil nil)))))
(defun represent-mapping (x)
(declare (special representation-cache))
(declare (special visited-cache))
(declare (special initialization-callbacks))
(let (result last-cons)
(macrolet ((collect-result (o!-key o!-val)
(once-only (o!-key o!-val)
`(if result
(progn (setf (cdr last-cons) (list `(,,o!-key . ,,o!-val)))
(setf last-cons (cdr last-cons)))
(progn (setf result (list `(,,o!-key . ,,o!-val)))
(setf last-cons result)))))
(frob ()
`(progn
(if (gethash key visited-cache)
(if (gethash val visited-cache)
(progn (collect-result nil nil)
(let (initialized-key
initialized-val
(encap-key key)
(encap-val val)
(encap-last-cons last-cons))
(flet ((frob-key ()
(if initialized-val
(setf (caar encap-last-cons) initialized-key
(cdar encap-last-cons) initialized-val)
(setf initialized-key (gethash encap-key representation-cache))))
(frob-val ()
(if initialized-key
(setf (caar encap-last-cons) initialized-key
(cdar encap-last-cons) initialized-val)
(setf initialized-val (gethash encap-val representation-cache)))))
(push #'frob-key (gethash key initialization-callbacks))
(push #'frob-val (gethash val initialization-callbacks)))))
(progn (collect-result nil (%represent-node val))
(push (let ((encap-key key)
(encap-last-cons last-cons))
(lambda ()
(setf (caar encap-last-cons)
(gethash encap-key representation-cache))))
(gethash key initialization-callbacks))))
(if (gethash val visited-cache)
(progn (collect-result (%represent-node key) nil)
(push (let ((encap-val val)
(encap-last-cons last-cons))
(lambda ()
(setf (cdar encap-last-cons)
(gethash encap-val representation-cache))))
(gethash val initialization-callbacks)))
(collect-result (%represent-node key) (%represent-node val))))
(collect `(,(%represent-node key) . ,(%represent-node val)) into res)
(finally (return (values `((:properties . ((:tag . ,(strcat tag-prefix "map"))))
(:content . (:mapping ,.result)))
t))))))
(typecase x
(hash-table (if (eq (hash-table-test x) 'equal)
(iter (for (key val) in-hashtable x)
(frob))
(error "Hash-tables with test-functions other than EQUAL cannot be dumped now.")))
(cons (cond ((and cons-maps-as-maps (alist-p x))
(iter (for (key . val) in x)
(frob)))
((and cons-maps-as-maps (plist-p x))
(iter (for key in x by #'cddr)
(for val in (cdr x) by #'cddr)
(frob)))
(t (values nil nil))))
(t (values nil nil))))))
(defun represent-sequence (x)
(declare (special representation-cache))
(declare (special visited-cache))
(declare (special initialization-callbacks))
(let (result last-cons)
(macrolet ((collect-result (o!-node)
(once-only (o!-node)
`(if result
(progn (setf (cdr last-cons) (list ,o!-node))
(setf last-cons (cdr last-cons)))
(progn (setf result (list ,o!-node))
(setf last-cons result)))))
(frob ()
`(progn (if (gethash subnode visited-cache)
(progn (collect-result nil)
(push (let ((encap-subnode subnode)
(encap-last-cons last-cons))
(lambda ()
(setf (car encap-last-cons)
(gethash encap-subnode representation-cache))))
(gethash subnode initialization-callbacks)))
(collect-result (%represent-node subnode)))
(finally (return (values `((:properties . ((:tag . ,(strcat tag-prefix "seq"))))
(:content . ,result))
t))))))
(typecase x
(cons (iter (for subnode in x)
(frob)))
((and array (not string)) (iter (for subnode in-vector x)
(frob)))
(t (values nil nil))))))
(defun %represent-node (x)
(declare (special representation-cache))
(declare (special initialization-callbacks))
(declare (special visited-cache))
(setf (gethash x visited-cache) t)
(multiple-value-bind (it got) (gethash x representation-cache)
(if got
it
(let ((res (multiple-value-bind (it got) (represent-mapping x)
(if got
it
(multiple-value-bind (it got) (represent-sequence x)
(if got
it
(multiple-value-bind (it got) (represent-scalar x)
(if got
it
(error "Failed to represent object: ~a" x)))))))))
(setf (gethash x representation-cache) res)
(iter (for callback in (gethash x initialization-callbacks))
(funcall callback))
(remhash x initialization-callbacks)
res))))
(defun represent-node (x)
(let ((representation-cache (make-hash-table :test #'eq))
(visited-cache (make-hash-table :test #'eq))
(initialization-callbacks (make-hash-table :test #'eq)))
(declare (special representation-cache))
(declare (special visited-cache))
(declare (special initialization-callbacks))
(%represent-node x)))
(defun plist-p (x)
(declare (ignorable x))
"Returns T if X is a property list in a narrow sense - all odd elements are non-duplicating symbols."
nil)
(defun alist-p (x)
(declare (ignorable x))
"Returns T if X is an association list in a narrow sense - all CAR's of assocs are non-duplicating symbols."
nil)
| 6,354 | Common Lisp | .lisp | 157 | 34.324841 | 110 | 0.633145 | mabragor/cl-yaclyaml | 14 | 3 | 8 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 97d0e1f27190aec29c0de1f4d860839f0352938fcfc91fb89ee5bad00a1ed6da | 7,981 | [
-1
] |
7,982 | macro-utils.lisp | mabragor_cl-yaclyaml/macro-utils.lisp | ;;;; This file is one of components of CL-YACLYAML system, licenced under GPL, see COPYING for details
(in-package #:cl-yaclyaml)
;;; (macro-) utilities, that should be put into separate file to ensure proper loading/compiling order.
(defmacro crunch-tag-into-properties (props-var crunch-if-absent crunch-if-vanilla)
(with-gensyms (g!-new-props)
`(if ,props-var
(let ((it (assoc :tag (cdr ,props-var))))
(if it
(if (equal (cdr it) :vanilla)
(setf (cdr it) ,crunch-if-vanilla))
(let ((,g!-new-props `((:tag . ,,crunch-if-absent) ,.(cdr ,props-var))))
(setf ,props-var (cons :properties ,g!-new-props)))))
(setf ,props-var `(:properties (:tag . ,,crunch-if-absent))))))
| 710 | Common Lisp | .lisp | 13 | 50.461538 | 103 | 0.664265 | mabragor/cl-yaclyaml | 14 | 3 | 8 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 1730a054613ec28dd79fd634e195f3199be8aff56a4bbc5fb995b237a69dae13 | 7,982 | [
-1
] |
7,983 | serializing.lisp | mabragor_cl-yaclyaml/serializing.lisp | ;;;; This file is one of components of CL-YACLYAML system, licenced under GPL, see COPYING for details
(in-package #:cl-yaclyaml)
;;; Converting representation graph into representation tree.
(defparameter node-aliases (make-hash-table :test #'eq))
(defparameter alias-count 0)
(defparameter encountered-nodes (make-hash-table :test #'eq))
(defun %nserialize (node)
;; (format t "encountered nodes: ~a~%" (hash->assoc encountered-nodes))
;; (format t "node: ~a~%" node)
;; (format t "~a~%" (multiple-value-list (gethash node encountered-nodes)))
(let ((it (gethash node node-aliases)))
(if it
(values it t)
(if (gethash node encountered-nodes)
;; need to create an alias node
(progn ;; (format t "Encountered node for at least second time.~%")
(let ((alias-name (format nil "a~a" (incf alias-count))))
;; KLUDGE: here we assume that :PROPERTIES is the first assoc-element
;; and content is the second
(setf (car node) `(:properties (:anchor . ,alias-name) ,.(cdar node)))
(values (setf (gethash node node-aliases) `(:alias . ,alias-name))
t)))
(progn ;; (format t "Encountered node for the first time. ")
(setf (gethash node encountered-nodes) t)
(cond ((scalar-p node)
;; (format t "scalar~%")
nil)
((mapping-p node)
;; (format t "mapping~%")
(iter (for map-entry in (cddr (assoc :content node)))
(multiple-value-bind (it got) (%nserialize (car map-entry))
(if got
(setf (car map-entry) it)))
(multiple-value-bind (it got) (%nserialize (cdr map-entry))
(if got
(setf (cdr map-entry) it)))))
;; sequence
(t
;; (format t "sequence~%")
(iter (for subnode on (cdr (assoc :content node)))
(multiple-value-bind (it got) (%nserialize (car subnode))
(if got
(setf (car subnode) it))))))
(values node nil))))))
(defun nserialize (representation-graph)
"Destructively convert representation graph (which may contain loops) to representation tree,
where all shared-ness is represented via alias-nodes."
(let ((node-aliases (make-hash-table :test #'eq))
(encountered-nodes (make-hash-table :test #'eq))
(alias-count 0))
(%nserialize representation-graph)))
| 2,250 | Common Lisp | .lisp | 51 | 39.117647 | 102 | 0.656164 | mabragor/cl-yaclyaml | 14 | 3 | 8 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 53e05465d2ca68b7d93fe17c440e23cc556e481e58c8265059cd1d859ee9cf89 | 7,983 | [
-1
] |
7,984 | convert.lisp | mabragor_cl-yaclyaml/convert.lisp | ;;;; This file is one of components of CL-YACLYAML system, licenced under GPL, see COPYING for details
(in-package #:cl-yaclyaml)
;;; Generating native structures from the nodes
(eval-when (:compile-toplevel :load-toplevel :execute)
(defparameter visited-nodes (make-hash-table :test #'eq))
(defparameter converted-nodes (make-hash-table :test #'eq))
(defparameter scalar-converters (make-hash-table :test #'equal))
(defparameter sequence-converters (make-hash-table :test #'equal))
(defparameter mapping-converters (make-hash-table :test #'equal))
(defparameter initialization-callbacks (make-hash-table :test #'eq)))
(defun mark-node-as-visited (node)
(setf (gethash node visited-nodes) t))
(defun scalar-p (node)
(atom (cdr (assoc :content node))))
(defun mapping-p (node)
(equal :mapping (car (cdr (assoc :content node)))))
(defun converted-p (node)
(gethash node converted-nodes))
(defun visited-p (node)
(gethash node visited-nodes))
(defun install-scalar-converter (tag converter)
"Install a scalar converter in the current scheme.
Should be called from an INSTALL-CONVERTERS method.
TAG is a string containing the yaml tag for the content.
CONVERTER is a function which takes a string containing the scalar
input and returns the converted value."
(setf (gethash tag scalar-converters) converter))
(defun install-sequence-converter (tag converter)
"Install a sequence converter in the current scheme.
Should be called from an INSTALL-CONVERTERS method.
TAG is a string containing the yaml tag for the content.
CONVERTER is a function which takes a list of raw nodes
as input and returns the converted value.
The converter function should convert the nodes, either with
CONVERT-SEQUENCE-TO-LIST, or CONVERT-NODE on each node."
(setf (gethash tag sequence-converters) converter))
(defun install-mapping-converter (tag converter)
"Install a mapping converter in the current scheme.
Should be called from an INSTALL-CONVERTERS method.
TAG is a string containing the yaml tag for the content.
CONVERTER is a function which takes a raw mapping node
as input and returns the converted value.
The content is a list where the CAR is the keyword :MAPPING
and the CDR is an alist of key-value pairs, where both the key and
value are raw nodes.
The converter function should convert the sub-nodes, either with
CONVERT-SEQUENCE-TO-LIST, or CONVERT-NODE on each node."
(setf (gethash tag mapping-converters) converter))
(defun trivial-scalar-converter (content)
(copy-seq content))
(defun install-sequence-list-converter (tag converter)
"Install a sequence converter in the current scheme.
Should be called from an INSTALL-CONVERTERS method.
TAG is a string containing the yaml tag for the content.
CONVERTER is a function that takes a list of converted values
and returns the converted value from the list.
This is probably preferable to INSTALL-SEQUENCE-CONVERTER in user code."
(setf (gethash tag sequence-converters)
(lambda (content)
(funcall converter (convert-sequence-to-list content)))))
(defun install-mapping-hashtable-converter (tag converter)
"Install a mapping converter in the current scheme.
Should be called from an INSTALL-CONVERTERS method.
TAG is a string containing the yaml tag for the content.
CONVERTER is a function that takes a hash-table of converted values
and returns the converted value from the list.
This is probably preferable to INSTALL-MAPPING-CONVERTER in user code."
(setf (gethash tag mapping-converters)
(lambda (content)
(funcall converter (convert-mapping-to-hashtable content)))))
(defun convert-scalar (content tag)
(let ((converter (gethash tag scalar-converters)))
(if converter
(funcall converter content)
;; fallback behaviour is to convert nothing
;; yet, we strip unneeded :PROPERTIES list, leaving only :TAG property.
`((:content . ,content) (:tag . ,tag)))))
(defun convert-sequence (content tag)
(let ((converter (gethash tag sequence-converters)))
(if converter
(funcall converter content)
`((:content . ,(convert-sequence-to-list content)) (:tag . ,tag)))))
(defun convert-mapping (content tag)
(let ((converter (gethash tag mapping-converters)))
(if converter
(funcall converter content)
`((:content . ,(convert-mapping-to-hashtable content)) (:tag . ,tag)))))
(defun convert-node (node)
"Convert a parsed node into a user object."
(when (not (nth-value 1 (gethash node converted-nodes)))
(let* ((content (cdr (assoc :content node)))
(properties (cdr (assoc :properties node)))
(tag (cdr (assoc :tag properties))))
(setf (gethash node converted-nodes)
(cond ((scalar-p node)
(convert-scalar content tag))
((mapping-p node)
(convert-mapping content tag))
(t (convert-sequence content tag)))))
(iter (for callback in
(gethash node initialization-callbacks))
(funcall callback))
(remhash node initialization-callbacks))
(gethash node converted-nodes))
(defun convert-sequence-to-list (nodes)
"Convert a raw sequence node to a list of converted values."
(let (result last-cons)
(macrolet ((collect-result (o!-node)
`(if result
(progn (setf (cdr last-cons) (list ,o!-node))
(setf last-cons (cdr last-cons)))
(progn (setf result (list ,o!-node))
(setf last-cons result)))))
(iter (for subnode in nodes)
(multiple-value-bind (it got) (gethash subnode converted-nodes)
(if got
(progn (collect-result it))
(progn (collect-result nil)
;; LET block here is extremely important, since it results in
;; LAMBDA capturing current values of SUBNODE and LAST-CONS and not the
;; ones they have upon last iteration.
(push (let ((encap-subnode subnode)
(place last-cons))
(lambda ()
(setf (car place) (gethash encap-subnode converted-nodes))))
(gethash subnode initialization-callbacks))))))
result)))
(defun convert-mapping-to-hashtable (content)
"Convert a raw mapping node to a hash-table of converted values."
(let ((result (make-hash-table :test #'equal)))
(iter (for (key . val) in (cdr content)) ; CAR of content is :MAPPING keyword
(multiple-value-bind (conv-key got-key) (gethash key converted-nodes)
(multiple-value-bind (conv-val got-val) (gethash val converted-nodes)
;; LET blocks here are extremely important, since they result in
;; LAMBDAs capturing current values of KEY and VAL and not the
;; ones they have upon last iteration.
;; ENCAP- stands for "encaptured"
(if got-key
(if got-val
(setf (gethash conv-key result) conv-val)
(push (let ((encap-key conv-key)
(encap-val val))
(lambda ()
(setf (gethash encap-key result)
(gethash encap-val converted-nodes))))
(gethash val initialization-callbacks)))
(if got-val
(push (let ((encap-key got-key)
(encap-val val))
(lambda ()
(setf (gethash encap-key result)
(gethash encap-val converted-nodes))))
(gethash key initialization-callbacks))
(let (key-installed
val-installed
(encap-key key)
(encap-val val))
(flet ((frob-key ()
(if val-installed
(setf (gethash key-installed result) val-installed)
(setf key-installed (gethash encap-key converted-nodes))))
(frob-val ()
(if key-installed
(setf (gethash key-installed result) val-installed)
(setf val-installed (gethash encap-val converted-nodes)))))
(push #'frob-key (gethash key initialization-callbacks))
(push #'frob-val (gethash val initialization-callbacks)))))
))))
result))
(defmacro define-bang-convert (name converter-name)
`(defun ,name (node)
(multiple-value-bind (it got) (gethash node converted-nodes)
(if (not got)
(let* ((content (cdr (assoc :content node)))
(properties (cdr (assoc :properties node)))
(tag (cdr (assoc :tag properties))))
(setf (gethash node converted-nodes)
(,converter-name content tag))
(iter (for callback in
(gethash node initialization-callbacks))
(funcall callback)))
it))))
(define-bang-convert convert-scalar! convert-scalar)
(define-bang-convert convert-sequence! convert-sequence)
(define-bang-convert convert-mapping! convert-mapping)
(defun %depth-first-traverse (cur-level &optional (level 0))
(macrolet ((add-node-if-not-visited (node)
`(when (not (visited-p ,node))
(mark-node-as-visited ,node)
(push ,node next-level))))
(let (next-level)
(iter (for node in cur-level)
(cond ((scalar-p node) nil)
((mapping-p node) (iter (for (key . val) in (cdr (cdr (assoc :content node))))
(add-node-if-not-visited key)
(add-node-if-not-visited val)))
(t (iter (for subnode in (cdr (assoc :content node)))
(add-node-if-not-visited subnode))))
(finally (if next-level
(%depth-first-traverse next-level (1+ level)))
(iter (for node in cur-level)
(convert-node node))
)))))
| 9,195 | Common Lisp | .lisp | 203 | 40.133005 | 102 | 0.701361 | mabragor/cl-yaclyaml | 14 | 3 | 8 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | b41b531336f74d31864bad988e22c663a1028551e51535e228301d4aa6f09059 | 7,984 | [
-1
] |
7,985 | tests.lisp | mabragor_cl-yaclyaml/tests.lisp | (in-package :cl-user)
(defpackage :cl-yaclyaml-tests
(:use :alexandria :cl :cl-yaclyaml :esrap-liquid :fiveam :iterate)
(:shadowing-import-from #:esrap-liquid #:! #:!!)
(:export #:run-tests))
(in-package :cl-yaclyaml-tests)
(cl-interpol:enable-interpol-syntax)
(def-suite yaclyaml)
(in-suite yaclyaml)
(defun run-tests ()
(let ((results (run 'yaclyaml)))
(fiveam:explain! results)
(unless (fiveam:results-status results)
(error "Tests failed."))))
(test basic
(is (equal #\tab (yaclyaml-parse 's-white #?"\t")))
(is (equal #\space (yaclyaml-parse 's-white #?" ")))
(is (equal nil (yaclyaml-parse 's-white #?"a" :junk-allowed t)))
(is (equal '(#\tab #\space #\tab) (yaclyaml-parse 's-separate-in-line #?"\t \t")))
(is (equal nil (yaclyaml-parse 's-separate-in-line #?"")))
(is (equal nil (yaclyaml-parse 's-separate-in-line #?"\n" :start 1))))
(test indents
(let ((cl-yaclyaml::n 5)
(cl-yaclyaml::indent-style :determined))
(is (equal 3 (yaclyaml-parse 's-indent-<n " ")))
(is (equal 4 (yaclyaml-parse 's-indent-<n " ")))
(signals (esrap-liquid::esrap-error) (yaclyaml-parse 's-indent-<n " "))
(is (equal 5 (yaclyaml-parse 's-indent-<=n " ")))
(signals (esrap-liquid::esrap-error) (yaclyaml-parse 's-indent-<n " "))
(signals (esrap-liquid::esrap-error) (yaclyaml-parse 's-indent-=n " "))
(is (equal 5 (yaclyaml-parse 's-indent-=n " ")))
(signals (esrap-liquid::esrap-error) (yaclyaml-parse 's-indent-=n " "))))
(test flow-line-prefix
(let ((cl-yaclyaml::n 0))
(is (equal '(0 (#\space #\space #\space)) (yaclyaml-parse 's-flow-line-prefix #?" ")))
(is (equal '(0 (#\tab #\space #\space)) (yaclyaml-parse 's-flow-line-prefix #?"\t ")))
(let ((cl-yaclyaml::n 2))
(is (equal '(2 (#\space)) (yaclyaml-parse 's-flow-line-prefix #?" ")))
(signals (esrap-liquid::esrap-error) (yaclyaml-parse 's-flow-line-prefix #?"\t ")))))
(test b-l-folded
(is (equal #?"\n\n\n" (let ((cl-yaclyaml::context :flow-out))
(yaclyaml-parse 'b-l-folded #?"\n \n \n\n")))))
(test flow-folded
(let ((cl-yaclyaml::n 0))
(is (equal " " (yaclyaml-parse 's-flow-folded #?"\n ")))
(is (equal #?"\n" (yaclyaml-parse 's-flow-folded #?" \n \n \t ")))
(is (equal #?"\n" (yaclyaml-parse 's-flow-folded #?"\n\n ")))
(is (equal " " (yaclyaml-parse 's-flow-folded #?"\n")))))
(test block-scalar-header
(is (equal '((:block-indentation-indicator . "3") (:block-chomping-indicator . "-"))
(yaclyaml-parse 'c-b-block-header #?"3- #asdf\n")))
(is (equal '((:block-chomping-indicator . "-") (:block-indentation-indicator . "3"))
(yaclyaml-parse 'c-b-block-header #?"-3 #asdf\n")))
(is (equal '((:block-chomping-indicator . "-") (:block-indentation-indicator . ""))
(yaclyaml-parse 'c-b-block-header #?"- #asdf\n")))
(is (equal '((:block-indentation-indicator . "3") (:block-chomping-indicator . ""))
(yaclyaml-parse 'c-b-block-header #?"3 #asdf\n")))
(is (equal '((:block-chomping-indicator . "") (:block-indentation-indicator . ""))
(yaclyaml-parse 'c-b-block-header #?" #asdf\n"))))
(test literal-block-scalars
(is (equal #?" explicit\n" (yaclyaml-parse 'c-l-block-scalar #?"|1\n explicit\n")))
(is (equal #?"text" (let ((cl-yaclyaml::n -1))
(yaclyaml-parse 'c-l-block-scalar #?"|-\n text\n"))))
(is (equal #?"text\n" (let ((cl-yaclyaml::n -1))
(yaclyaml-parse 'c-l-block-scalar #?"|\ntext\n"))))
(is (equal #?"text\n" (let ((cl-yaclyaml::n -1))
(yaclyaml-parse 'c-l-block-scalar #?"|+\ntext\n"))))
(is (equal #?"\n\nliteral\n \n\ntext\n"
(yaclyaml-parse 'c-l-block-scalar
#?"|2\n \n \n literal\n \n \n text\n\n\n # Comment\n"))))
(test folded-block-scalars
(is (equal #?"folded text\n" (yaclyaml-parse 'c-l-block-scalar #?">\n folded text\n\n")))
(is (equal #?"\nfolded line\nnext line\nlast line\n"
(yaclyaml-parse 'c-l-block-scalar
#?">\n\n folded\n line\n\n next\n line\n\n last\n line\n
# Comment\n")))
(is (equal #?"foobar\n * bullet\n * list\n\n * lines\n"
(yaclyaml-parse 'c-l-block-scalar
#?">\n foobar\n * bullet\n * list\n\n * lines\n"))))
(test plain-scalars-simple
(is (equal #?"1st non-empty\n2nd non-empty 3rd non-empty"
(yaclyaml-parse 'ns-plain
#?"1st non-empty\n\n 2nd non-empty \n\t3rd non-empty"))))
(test double-quoted-scalars
(is (equal "implicit block key" (let ((cl-yaclyaml::context :block-key))
(yaclyaml-parse 'c-double-quoted "\"implicit block key\""))))
(is (equal "implicit flow key" (let ((cl-yaclyaml::context :flow-key))
(yaclyaml-parse 'c-double-quoted "\"implicit flow key\""))))
(is (equal #?"folded to a space"
(yaclyaml-parse 'c-double-quoted
#?"\"folded \nto a space\"")))
(is (equal #?",\nto a line feed"
(yaclyaml-parse 'c-double-quoted
#?"\",\t\n \nto a line feed\"")))
(is (equal #?"or \t \tnon-content"
(yaclyaml-parse 'c-double-quoted
#?"\"or \t\\\n \\ \tnon-content\"")))
;; and all the above components together
(is (equal #?"folded to a space,\nto a line feed, or \t \tnon-content"
(yaclyaml-parse 'c-double-quoted
#?"\"folded \nto a space,\t\n \nto a line feed, or \t\\\n \\ \tnon-content\"")))
(is (equal #?" 1st non-empty\n2nd non-empty 3rd non-empty "
(yaclyaml-parse 'c-double-quoted
#?"\" 1st non-empty\n\n 2nd non-empty \n\t3rd non-empty \""))))
(test single-quoted-scalars
(is (equal "here's to \"quotes\""
(yaclyaml-parse 'c-single-quoted "'here''s to \"quotes\"'")))
(is (equal #?" 1st non-empty\n2nd non-empty 3rd non-empty "
(yaclyaml-parse 'c-single-quoted
#?"' 1st non-empty\n\n 2nd non-empty \n\t3rd non-empty '"))))
(test flow-sequence-nodes
(is (equal '(((:properties (:tag . :non-specific)) (:content . "one"))
((:properties (:tag . :non-specific)) (:content . "two")))
(yaclyaml-parse 'c-flow-sequence #?"[ one, two, ]")))
(is (equal '(((:properties (:tag . :non-specific)) (:content . "three"))
((:properties (:tag . :non-specific)) (:content . "four")))
(yaclyaml-parse 'c-flow-sequence #?"[three ,four]")))
(is (equal '(((:PROPERTIES (:TAG . "tag:yaml.org,2002:str")) (:CONTENT . "double quoted"))
((:PROPERTIES (:TAG . "tag:yaml.org,2002:str")) (:CONTENT . "single quoted"))
((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "plain text"))
((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT ((:PROPERTIES (:TAG . :NON-SPECIFIC))
(:CONTENT . "nested"))))
(:MAPPING (((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "single"))
(:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "pair"))))
(yaclyaml-parse 'c-flow-sequence
#?"[\n\"double\n quoted\", 'single
quoted',\nplain\n text, [ nested ],\nsingle: pair,\n]")))
)
(test plain-scalars
(is (equal "::vector"
(let ((cl-yaclyaml::context :block-in))
(yaclyaml-parse 'ns-plain
#?"::vector"))))
(is (equal "Up, up, and away!"
(let ((cl-yaclyaml::context :block-in))
(yaclyaml-parse 'ns-plain
#?"Up, up, and away!"))))
(is (equal "-123"
(let ((cl-yaclyaml::context :block-in))
(yaclyaml-parse 'ns-plain
#?"-123"))))
(is (equal "http://example.com/foo#bar"
(let ((cl-yaclyaml::context :block-in))
(yaclyaml-parse 'ns-plain
#?"http://example.com/foo#bar"))))
)
(test flow-mapping-nodes-simple
(is (equal '(:mapping (((:properties (:tag . :non-specific)) (:content . "one"))
. ((:properties (:tag . :non-specific)) (:content . "two")))
(((:properties (:tag . :non-specific)) (:content . "three"))
. ((:properties (:tag . :non-specific)) (:content . "four"))))
(yaclyaml-parse 'c-flow-mapping
#?"{ one : two , three: four , }")))
(is (equal '(:mapping (((:properties (:tag . :non-specific)) (:content . "five"))
. ((:properties (:tag . :non-specific)) (:content . "six")))
(((:properties (:tag . :non-specific)) (:content . "seven"))
. ((:properties (:tag . :non-specific)) (:content . "eight"))))
(yaclyaml-parse 'c-flow-mapping
#?"{five: six,seven : eight}")))
(is (equal '(:mapping (((:properties (:tag . :non-specific)) (:content . "explicit"))
. ((:properties (:tag . :non-specific)) (:content . "entry")))
(((:properties (:tag . :non-specific)) (:content . "implicit"))
. ((:properties (:tag . :non-specific)) (:content . "entry")))
(((:properties (:tag . :non-specific)) (:content . :empty))
. ((:properties (:tag . :non-specific)) (:content . :empty))))
(yaclyaml-parse 'c-flow-mapping
#?"{\n? explicit: entry,\nimplicit: entry,\n?\n}"))))
(test tags-simple
(is (equal '(:tag . "asdf") (yaclyaml-parse 'c-ns-tag-property "!<asdf>")))
(signals (esrap-liquid::esrap-error) (yaclyaml-parse 'c-ns-tag-property ":")))
(test flow-mapping-nodes-individual-complex
(is (equal '(:mapping (((:properties (:tag . :non-specific)) (:content . "unquoted"))
. ((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "separate"))))
(yaclyaml-parse 'c-flow-mapping
#?"{\nunquoted : \"separate\"}"))))
(test flow-mapping-nodes-complex)
(test flow-mapping-nodes-complex
(is (equal '(:mapping (((:properties (:tag . :non-specific)) (:content . "unquoted"))
. ((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "separate")))
(((:properties (:tag . :non-specific)) (:content . "http://foo.com"))
. ((:properties (:tag . :non-specific)) (:content . :empty)))
(((:properties (:tag . :non-specific)) (:content . "omitted value"))
. ((:properties (:tag . :non-specific)) (:content . :empty)))
(((:properties (:tag . :non-specific)) (:content . :empty))
. ((:properties (:tag . :non-specific)) (:content . "omitted key")))
(((:properties (:tag . "tag:yaml.org,2002:str")) (:content . ""))
. ((:properties (:tag . "tag:yaml.org,2002:str")) (:content . ""))))
(yaclyaml-parse 'c-flow-mapping
#?"{\nunquoted : \"separate\",\nhttp://foo.com,
omitted value:,\n: omitted key,'':'',\n}"))))
(test flow-mapping-nodes-next
(is (equal '(:mapping (((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "adjacent"))
. ((:properties (:tag . :non-specific)) (:content . "value")))
(((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "readable"))
. ((:properties (:tag . :non-specific)) (:content . "value")))
(((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "empty"))
. ((:properties (:tag . :non-specific)) (:content . :empty))))
(yaclyaml-parse 'c-flow-mapping
#?"{\n\"adjacent\":value,\n\"readable\": value,\n\"empty\":\n}")))
(is (equal '((:mapping (((:properties (:tag . :non-specific)) (:content . "foo"))
. ((:properties (:tag . :non-specific)) (:content . "bar")))))
(yaclyaml-parse 'c-flow-sequence
#?"[\nfoo: bar\n]")))
(is (equal '((:mapping (((:properties (:tag . :non-specific)) (:content . "foo bar"))
. ((:properties (:tag . :non-specific)) (:content . "baz")))))
(yaclyaml-parse 'c-flow-sequence
#?"[\n? foo\n bar : baz\n]")))
(is (equal '((:mapping (((:properties (:tag . :non-specific)) (:content . "YAML"))
. ((:properties (:tag . :non-specific)) (:content . "separate")))))
(yaclyaml-parse 'c-flow-sequence
#?"[ YAML : separate ]")))
(is (equal '((:mapping (((:properties (:tag . :non-specific)) (:content . :empty))
. ((:properties (:tag . :non-specific)) (:content . "empty key entry")))))
(yaclyaml-parse 'c-flow-sequence
#?"[ : empty key entry ]")))
(is (equal '((:mapping (((:properties (:tag . :non-specific))
(:content . (:mapping (((:properties (:tag . :non-specific)) (:content . "JSON"))
. ((:properties (:tag . :non-specific)) (:content . "like"))))))
. ((:properties (:tag . :non-specific)) (:content . "adjacent")))))
(yaclyaml-parse 'c-flow-sequence
#?"[ {JSON: like}:adjacent ]")))
)
(test block-sequences
(is (equal `(((:properties (:tag . :non-specific)) (:content . "foo"))
((:properties (:tag . :non-specific)) (:content . "bar"))
((:properties (:tag . :non-specific)) (:content . "baz")))
(let ((cl-yy::n -1))
(yaclyaml-parse 'l+block-sequence #?"- foo\n- bar\n- baz\n"))))
(is (equal `(((:properties (:tag . :non-specific))
(:content . (:mapping (((:properties (:tag . :non-specific)) (:content . "one"))
. ((:properties (:tag . :non-specific)) (:content . "two")))))))
(let ((cl-yy::n -1))
(yaclyaml-parse 'l+block-sequence #?"- one: two # compact mapping\n"))))
(is (equal `(((:properties (:tag . :non-specific)) (:content . :empty))
((:properties (:tag . "tag:yaml.org,2002:str")) (:content . ,#?"block node\n"))
((:properties (:tag . :non-specific))
(:content . (((:properties (:tag . :non-specific)) (:content . "one"))
((:properties (:tag . :non-specific)) (:content . "two")))))
((:properties (:tag . :non-specific))
(:content . (:mapping (((:properties (:tag . :non-specific)) (:content . "one"))
. ((:properties (:tag . :non-specific)) (:content . "two")))))))
(let ((cl-yy::n -1))
(yaclyaml-parse 'l+block-sequence
#?"- # Empty\n- |\n block node\n- - one # Compact\n - two # sequence\n- one: two\n")))))
(test detect-block-mapping
(is (equal 0 (let ((cl-yy::n -1)) (yaclyaml-parse 'detect-block-mapping "a" :junk-allowed t))))
(is (equal 1 (let ((cl-yy::n -1)) (yaclyaml-parse 'detect-block-mapping " a" :junk-allowed t))))
(is (equal 1 (let ((cl-yy::n 0)) (yaclyaml-parse 'detect-block-mapping " a" :junk-allowed t))))
(is (equal 0 (let ((cl-yy::n -1)) (yaclyaml-parse 'detect-block-mapping "?" :junk-allowed t))))
(is (equal nil (let ((cl-yy::n 2)) (yaclyaml-parse 'detect-block-mapping " a" :junk-allowed t)))))
(test block-map-entry
(is (equal '(((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "explicit key"))
(:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . :EMPTY))
(let ((cl-yy::n 0)) (yaclyaml-parse 'ns-l-block-map-entry #?"? explicit key # Empty value\n"))))
(is (equal '(((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "explicit key"))
(:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . :EMPTY))
(let ((cl-yy::n 0)) (yaclyaml-parse '(progn (v cl-yy::s-indent-=n) (v cl-yy::ns-l-block-map-entry))
#?"? explicit key # Empty value\n"))))
(is (equal '(((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "explicit key"))
(:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . :EMPTY))
(let ((cl-yy::n -1)) (yaclyaml-parse '(let ((cl-yy::n (v cl-yy::detect-block-mapping))
(cl-yy::indent-style :determined))
(progn (v cl-yy::s-indent-=n) (v cl-yy::ns-l-block-map-entry)))
#?"? explicit key # Empty value\n"))))
(is (equal '((((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "explicit key"))
(:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . :EMPTY)))
(let ((cl-yy::n -1)) (yaclyaml-parse '(let ((cl-yy::n (v cl-yy::detect-block-mapping))
(cl-yy::indent-style :determined))
(cl-yy::postimes
(progn (v cl-yy::s-indent-=n)
(v cl-yy::ns-l-block-map-entry))))
#?"? explicit key # Empty value\n"))))
(is (equal '(:mapping (((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "explicit key"))
(:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . :EMPTY)))
(let ((cl-yy::n -1)) (yaclyaml-parse '(let ((cl-yy::n (v cl-yy::detect-block-mapping))
(cl-yy::indent-style :determined))
`(:mapping ,.(cl-yy::postimes
(progn (v cl-yy::s-indent-=n)
(v cl-yy::ns-l-block-map-entry)))))
#?"? explicit key # Empty value\n")))))
(test block-mappings-basic
(is (equal '(((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "one"))
((:PROPERTIES (:TAG . :NON-SPECIFIC))
(:CONTENT :MAPPING (((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "two"))
(:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "three")))))
(let ((cl-yy::n 0)) (yaclyaml-parse 'l+block-sequence #?" - one\n - two : three\n"))))
(is (equal '(((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "block sequence"))
14)
(multiple-value-list
(let ((cl-yy::n 0)
(cl-yy::indent-style :determined))
(yaclyaml-parse 'ns-s-block-map-implicit-key #?"block sequence:\n - one\n - two : three\n"
:junk-allowed t)))))
(is (equal '((:PROPERTIES (:TAG . :NON-SPECIFIC))
(:CONTENT ((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "one"))
((:PROPERTIES (:TAG . :NON-SPECIFIC))
(:CONTENT :MAPPING (((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "two"))
(:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "three"))))))
(let ((cl-yy::n 0)
(cl-yy::indent-style :determined))
(yaclyaml-parse 'c-l-block-map-implicit-value #?"block sequence:\n - one\n - two : three\n"
:start 14))))
(is (equal '(((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "block sequence"))
((:PROPERTIES (:TAG . :NON-SPECIFIC))
(:CONTENT ((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "one"))
((:PROPERTIES (:TAG . :NON-SPECIFIC))
(:CONTENT :MAPPING (((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "two"))
(:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "three")))))))
(let ((cl-yy::n 0)
(cl-yy::indent-style :determined))
(yaclyaml-parse 'ns-l-block-map-implicit-entry #?"block sequence:\n - one\n - two : three\n"))))
(is (equal '(((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "block sequence"))
(:PROPERTIES (:TAG . :NON-SPECIFIC))
(:CONTENT ((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "one"))
((:PROPERTIES (:TAG . :NON-SPECIFIC))
(:CONTENT :MAPPING (((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "two"))
(:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "three"))))))
(let ((cl-yy::n 0)
(cl-yy::indent-style :determined))
(yaclyaml-parse 'ns-l-block-map-entry #?"block sequence:\n - one\n - two : three\n"))))
(is (equal '(:MAPPING
(((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "block sequence"))
(:PROPERTIES (:TAG . :NON-SPECIFIC))
(:CONTENT ((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "one"))
((:PROPERTIES (:TAG . :NON-SPECIFIC))
(:CONTENT :MAPPING (((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "two"))
(:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "three")))))))
(let ((cl-yy::n -1))
(yaclyaml-parse 'l+block-mapping #?"block sequence:\n - one\n - two : three\n")))))
(test block-mappings
(is (equal `(:mapping (((:properties (:tag . :non-specific)) (:content . "explicit key"))
. ((:properties (:tag . :non-specific)) (:content . :empty))))
(let ((cl-yy::n -1)) (yaclyaml-parse 'l+block-mapping #?"? explicit key # Empty value\n"))))
(is (equal `(:mapping (((:properties (:tag . "tag:yaml.org,2002:str")) (:content . ,#?"block key\n"))
. ((:properties (:tag . :non-specific)) (:content . "flow value"))))
(let ((cl-yy::n -1)) (yaclyaml-parse 'l+block-mapping #?"? |\n block key\n: flow value\n"))))
(is (equal `(:mapping (((:properties (:tag . "tag:yaml.org,2002:str")) (:content . ,#?"block key\n"))
. ((:properties (:tag . :non-specific))
(:content . (((:properties (:tag . :non-specific)) (:content . "one"))
((:properties (:tag . :non-specific)) (:content . "two")))))))
(let ((cl-yy::n -1))
(yaclyaml-parse 'l+block-mapping #?"? |\n block key\n: - one # Explicit compact\n - two # block value\n")))))
(test block-mappings-implicit
(is (equal `(:mapping (((:properties (:tag . :non-specific)) (:content . "block mapping"))
. ((:properties (:tag . :non-specific))
(:content . (:mapping (((:properties (:tag . :non-specific)) (:content . "key"))
. ((:properties (:tag . :non-specific)) (:content . "value"))))))))
(let ((cl-yy::n -1))
(yaclyaml-parse 'l+block-mapping #?"block mapping:\n key: value\n"))))
(is (equal `(:mapping (((:properties (:tag . :non-specific)) (:content . "plain key"))
. ((:properties (:tag . :non-specific)) (:content . "in-line value")))
(((:properties (:tag . :non-specific)) (:content . :empty))
. ((:properties (:tag . :non-specific)) (:content . :empty)))
(((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "quoted key"))
. ((:properties (:tag . :non-specific))
(:content . (((:properties (:tag . :non-specific)) (:content . "entry")))))))
(let ((cl-yy::n -1))
(yaclyaml-parse 'l+block-mapping #?"plain key: in-line value\n: # Both empty
\"quoted key\":\n- entry\n"))))
)
(test compact-block-mappings
(is (equal `(((:properties (:tag . :non-specific))
(:content . (:mapping (((:properties (:tag . :non-specific)) (:content . "sun"))
. ((:properties (:tag . :non-specific)) (:content . "yellow"))))))
((:properties (:tag . :non-specific))
(:content . (:mapping (((:properties (:tag . :non-specific))
(:content . (:mapping (((:properties (:tag . :non-specific)) (:content . "earth"))
. ((:properties (:tag . :non-specific))
(:content . "blue"))))))
. ((:properties (:tag . :non-specific))
(:content . (:mapping (((:properties (:tag . :non-specific)) (:content . "moon"))
. ((:properties (:tag . :non-specific))
(:content . "white")))))))))))
(let ((cl-yy::n -1))
(yaclyaml-parse 'l+block-sequence #?"- sun: yellow\n- ? earth: blue\n : moon: white\n")))))
(test node-properties
(is (equal `(:mapping (((:properties (:tag . "tag:yaml.org,2002:str") (:anchor . "a1")) (:content . "foo"))
. ((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "bar")))
(((:properties (:tag . :non-specific) (:anchor . "a2")) (:content . "baz"))
. (:alias . "a1")))
(let ((cl-yy::n -1))
(yaclyaml-parse 'l+block-mapping #?"!!str &a1 \"foo\":\n !!str bar\n&a2 baz : *a1\n")))))
(test bare-document
(is (equal '((:document ((:properties (:tag . :non-specific)) (:content . "Bare document"))) 14)
(multiple-value-list (yaclyaml-parse 'l-bare-document
#?"Bare document\n...\n# No document\n...\n|\n%!PS-Adobe-2.0 # Not the first line\n" :junk-allowed t))))
;; bare documents may not be empty!
(signals (esrap-liquid::esrap-error) (yaclyaml-parse 'l-bare-document
#?"# No document\n"))
(is (equal `(:document ((:properties (:tag . "tag:yaml.org,2002:str"))
(:content . ,#?"%!PS-Adobe-2.0 # Not the first line\n")))
(yaclyaml-parse 'l-bare-document
#?"|\n%!PS-Adobe-2.0 # Not the first line\n")))
)
(test explicit-documents
(is (equal '(:document ((:properties (:tag . :non-specific))
(:content . (:mapping (((:properties (:tag . :non-specific)) (:content . "matches %"))
. ((:properties (:tag . :non-specific)) (:content . "20")))))))
(yaclyaml-parse 'l-explicit-document
#?"---\n{ matches\n% : 20 }\n")))
(is (equal '(:DOCUMENT ((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . :EMPTY)))
(yaclyaml-parse 'l-explicit-document
#?"---\n# Empty\n")))
)
(test directive-documents
(is (equal `(:document ((:properties (:tag . "tag:yaml.org,2002:str")) (:content . ,#?"%!PS-Adobe-2.0\n")))
(yaclyaml-parse 'l-directive-document
#?"%YAML 1.2\n--- |\n%!PS-Adobe-2.0\n")))
(is (equal '(:DOCUMENT ((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . :EMPTY)))
(yaclyaml-parse 'l-directive-document
#?"%YAML 1.2\n---\n# Empty\n")))
)
(test nested-tag-handles
(is (equal '(:DOCUMENT ((:PROPERTIES (:TAG . "edcf")) (:CONTENT . "asdf")))
(yy-parse 'l-directive-document
#?"%TAG !a! !b!c\n%TAG !b! !d\n%TAG ! e\n---\n!a!f asdf"))))
(test yaml-stream
(is (equal '((:document ((:properties (:tag . :non-specific)) (:content . "Document")))
(:document ((:properties (:tag . :non-specific)) (:content . "another")))
(:document ((:properties (:tag . :non-specific))
(:content . (:mapping (((:properties (:tag . :non-specific)) (:content . "matches %"))
. ((:properties (:tag . :non-specific)) (:content . "20"))))))))
(yaclyaml-parse 'l-yaml-stream
#?"Document\n---\nanother\n...\n%YAML 1.2\n---\nmatches %: 20")))
(is (equal `((:DOCUMENT ((:PROPERTIES (:TAG . :NON-SPECIFIC)) (:CONTENT . "Bare document")))
(:DOCUMENT
((:PROPERTIES (:TAG . "tag:yaml.org,2002:str"))
;; sadly, block scalars do not strip comment of their contents.
(:CONTENT . ,#?"%!PS-Adobe-2.0 # Not the first line\n"))))
(yaclyaml-parse 'l-yaml-stream
#?"Bare document\n...\n# No document\n...\n|\n%!PS-Adobe-2.0 # Not the first line\n")))
)
(test tag-handle-compilation
(is (equal '((:SECONDARY-TAG-HANDLE . "tag:yaml.org,2002:")
(:PRIMARY-TAG-HANDLE . "e")
((:NAMED-TAG-HANDLE "a") . "edc") ((:NAMED-TAG-HANDLE "b") . "ed"))
(let ((cl-yy::tag-handles (make-hash-table :test #'equal)))
(setf (gethash :secondary-tag-handle cl-yy::tag-handles) "tag:yaml.org,2002:"
(gethash :primary-tag-handle cl-yy::tag-handles) "!"
(gethash '(:named-tag-handle "a") cl-yy::tag-handles) "!b!c"
(gethash '(:named-tag-handle "b") cl-yy::tag-handles) "!d"
(gethash :primary-tag-handle cl-yy::tag-handles) "e")
(cl-yy::compile-tag-handles)
(hash->assoc cl-yy::tag-handles)))))
(test tag-shorthands
(is (equal '((:document ((:properties (:tag . :non-specific))
(:content . (((:properties (:tag . "!local")) (:content . "foo"))
((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "bar"))
((:properties (:tag . "tag:example.com,2000:app/tag%21")) (:content . "baz")))))))
(yaclyaml-parse 'l-yaml-stream #?"%TAG !e! tag:example.com,2000:app/\n---
- !local foo\n- !!str bar\n- !e!tag%21 baz")))
)
(test construction-of-representation-graph
;; FIXME: for now such a lame check will suffice, I dunno how to check shared structured-ness easily
(is (equal `(:mapping (((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "foo"))
. ((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "bar")))
(((:properties) (:content . "baz"))
. ((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "foo"))))
(ncompose-representation-graph
(copy-tree `(:mapping (((:properties (:tag . "tag:yaml.org,2002:str") (:anchor . "a1")) (:content . "foo"))
. ((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "bar")))
(((:properties (:anchor . "a2")) (:content . "baz"))
. (:alias . "a1"))))))))
;;; Generating native language structures from representation graph
;; (defmacro with-flat-nodes ((from to) &body body)
;; (iter (for i from from to to)
;; (collect `(,(sb-int:symbolicate "NODE" (format nil "~a" i))
;; '((:properties) (:content . ,(format nil "~a" i)))) into res)
;; (finally (return `(let ,res ,@body)))))
;; (defmacro with-cons-nodes ((from to) &body body)
;; (iter (for i from from to to)
;; (collect `(,(sb-int:symbolicate "CONS-NODE" (format nil "~a" i))
;; (list (list :properties) (list :content))) into res)
;; (finally (return `(let ,res ,@body)))))
;; (defmacro link-nodes (which where)
;; `(push ,which (cdr (assoc :content ,where))))
;; (defun mk-node (num)
;; (sb-int:symbolicate "NODE" (format nil "~a" num)))
;; (defun mk-cons-node (num)
;; (sb-int:symbolicate "CONS-NODE" (format nil "~a" num)))
;; (test find-parents
;; (with-flat-nodes (1 5)
;; (with-cons-nodes (1 5)
;; (is (equal
;; (let ((res (make-hash-table :test #'eq)))
;; (setf (gethash cons-node2 res) (list cons-node1)
;; (gethash node1 res) (list cons-node1)
;; (gethash cons-node3 res) (list cons-node2)
;; (gethash node2 res) (list cons-node2)
;; (gethash cons-node4 res) (list cons-node3)
;; (gethash node3 res) (list cons-node3)
;; (gethash cons-node5 res) (list cons-node4)
;; (gethash node4 res) (list cons-node4)
;; (gethash node5 res) (list cons-node5))
;; res)
;; (macrolet ((with-simple-chain ((from to) &body body)
;; (iter (for i from from below to)
;; (collect `(link-nodes ,(mk-node (1+ i))
;; ,(mk-cons-node (1+ i))) into res)
;; (collect `(link-nodes ,(mk-cons-node (1+ i))
;; ,(mk-cons-node i)) into res)
;; (finally (return
;; `(progn (link-nodes ,(mk-node from)
;; ,(mk-cons-node from))
;; ,@res
;; (let ((chain ,(mk-cons-node from)))
;; ,@body)))))))
;; (with-simple-chain (1 5)
;; (cl-yaclyaml::find-parents chain))))))))
(test scalar-construction-failsafe
(is (equal '((:content . "asdf") (:tag . :non-specific))
(construct '((:properties . ((:tag . :non-specific))) (:content . "asdf")) :schema :failsafe)))
(is (equal "asdf"
(construct '((:properties . ((:tag . "tag:yaml.org,2002:str"))) (:content . "asdf")) :schema :failsafe)))
(is (equal '((:content . :empty) (:tag . "tag:yaml.org,2002:null"))
(construct '((:properties . ((:tag . "tag:yaml.org,2002:null"))) (:content . :empty)) :schema :failsafe))))
(test scalar-construction-json
(signals (error "JSON impication of scalar didn't signal an error.")
(construct '((:properties . ((:tag . :non-specific))) (:content . "asdf")) :schema :json))
(is (equal "asdf"
(construct '((:properties . ((:tag . "tag:yaml.org,2002:str"))) (:content . "asdf")) :schema :json)))
(is (equal 123
(construct '((:properties . ((:tag . :non-specific))) (:content . "123")) :schema :json)))
(is (equal -3.14
(construct '((:properties . ((:tag . :non-specific))) (:content . "-3.14")) :schema :json)))
(is (equal nil
(construct '((:properties . ((:tag . :non-specific))) (:content . :empty)) :schema :json)))
(is (equal nil
(construct '((:properties . ((:tag . :non-specific))) (:content . "null")) :schema :json))))
(test scalar-construction-core
(is (equal "asdf"
(construct '((:properties . ((:tag . :non-specific))) (:content . "asdf")) :schema :core)))
(is (equal "asdf"
(construct '((:properties . ((:tag . "tag:yaml.org,2002:str"))) (:content . "asdf")) :schema :core)))
(is (equal 123
(construct '((:properties . ((:tag . :non-specific))) (:content . "123")) :schema :core)))
(is (equal -3.14
(construct '((:properties . ((:tag . :non-specific))) (:content . "-3.14")) :schema :core)))
(is (equal nil
(construct '((:properties . ((:tag . :non-specific))) (:content . :empty)) :schema :core)))
(is (equal nil
(construct '((:properties . ((:tag . :non-specific))) (:content . "null")) :schema :core)))
(is (equal ""
(construct '((:properties . ((:tag . :non-specific))) (:content . "")) :schema :core)))
(is (equal t
(construct '((:properties . ((:tag . :non-specific))) (:content . "true")) :schema :core)))
(is (equal t
(construct '((:properties . ((:tag . :non-specific))) (:content . "True")) :schema :core)))
(is (equal nil
(construct '((:properties . ((:tag . :non-specific))) (:content . "false")) :schema :core)))
(is (equal nil
(construct '((:properties . ((:tag . :non-specific))) (:content . "FALSE")) :schema :core)))
(is (equal 0
(construct '((:properties . ((:tag . :non-specific))) (:content . "0")) :schema :core)))
(is (equal 7
(construct '((:properties . ((:tag . :non-specific))) (:content . "0o7")) :schema :core)))
(is (equal 58
(construct '((:properties . ((:tag . :non-specific))) (:content . "0x3A")) :schema :core)))
(is (equal -19
(construct '((:properties . ((:tag . :non-specific))) (:content . "-19")) :schema :core)))
(is (equalp 0
(construct '((:properties . ((:tag . :non-specific))) (:content . "0.")) :schema :core)))
(is (equalp 0
(construct '((:properties . ((:tag . :non-specific))) (:content . "-0.0")) :schema :core)))
(is (equal 0.5
(construct '((:properties . ((:tag . :non-specific))) (:content . ".5")) :schema :core)))
(is (equalp 12000
(construct '((:properties . ((:tag . :non-specific))) (:content . "+12e03")) :schema :core)))
(is (equalp -200000
(construct '((:properties . ((:tag . :non-specific))) (:content . "-2E+05")) :schema :core)))
(is (equalp :nan
(construct '((:properties . ((:tag . :non-specific))) (:content . ".NAN")) :schema :core)))
(is (equalp :infinity
(construct '((:properties . ((:tag . :non-specific))) (:content . ".Inf")) :schema :core)))
)
(test simple-sequences
(is (equal '((:document ("foo" "bar" "baz")))
(yaml-load #?"- foo\n- bar\n- baz\n")))
(is (equal '((:document ((:content . (((:content . "foo") (:tag . :non-specific))
((:content . "bar") (:tag . :non-specific))
((:content . "baz") (:tag . :non-specific))))
(:tag . :non-specific))))
(yaml-load #?"- foo\n- bar\n- baz\n" :schema :failsafe)))
)
(test simple-sequences-load
(is (equal '("foo" "bar" "baz")
(yaml-simple-load #?"- foo\n- bar\n- baz\n")))
(is (equal '((:content . (((:content . "foo") (:tag . :non-specific))
((:content . "bar") (:tag . :non-specific))
((:content . "baz") (:tag . :non-specific))))
(:tag . :non-specific))
(yaml-simple-load #?"- foo\n- bar\n- baz\n" :schema :failsafe)))
(signals (error "simple load of multiple documents doesn't signal an error.")
(cl-yaclyaml::yaml-simple-load #?"- foo\n- bar\n- baz\n...\n- goo...\n- goo"))
(is (equal '("foo" "bar" ("baz" "baz2" "baz3"))
(yaml-simple-load #?"- foo\n- bar\n- - baz\n - baz2\n - baz3")))
)
(test simple-mappings
(is (equal '(("earth" . "green") ("moon" . "blue") ("sun" . "gold"))
(sort (hash->assoc (cadar (yaml-load #?"sun : gold\nearth : green\nmoon : blue")))
#'string< :key #'car))))
(test special-symbols
(is (equal "~/.ssh/id_rsa" (cl-yy::yaml-simple-load "'~/.ssh/id_rsa'"))))
(test simple-cyclics
(let ((simplest-cyclic (yaml-simple-load #?"&foo\n- 1\n- *foo\n- 2\n- 3")))
(is (equal 1 (car simplest-cyclic)))
(is (equal 2 (caddr simplest-cyclic)))
(is (equal 3 (cadddr simplest-cyclic)))
(is (equal nil (nth 4 simplest-cyclic)))
(is (equal 1 (car (cadr simplest-cyclic))))))
(test alias-mappings
(let ((alias-mapping
;; additional sequence level in all but first map is to ensure actual values of &FOO and &BAR are
;; processed after those maps, thus the need to use callback-code is there.
(let ((loadee (yaml-simple-load #?"- ? &foo a\n : &bar b
- - ? *foo
: b
- - ? a
: *bar
- - ? *foo
: *bar")))
(mapcar #'hash->assoc `(,(car loadee) ,@(mapcar #'car (cdr loadee)))))))
(is (eq (caar (first alias-mapping)) (caar (second alias-mapping))))
(is (not (eq (cdar (first alias-mapping)) (cdar (second alias-mapping)))))
(is (not (eq (caar (first alias-mapping)) (caar (third alias-mapping)))))
(is (eq (cdar (first alias-mapping)) (cdar (third alias-mapping))))
(is (eq (caar (first alias-mapping)) (caar (fourth alias-mapping))))
(is (eq (cdar (first alias-mapping)) (cdar (fourth alias-mapping))))))
;;;; tests for process of dumping
(test represent-node
(is (equal '((:properties (:tag . "tag:yaml.org,2002:int")) (:CONTENT . "123"))
(represent-node 123)))
(is (equal '((:properties (:tag . "tag:yaml.org,2002:float")) (:CONTENT . "12.3"))
(represent-node 12.3)))
(is (equal '((:properties (:tag . "tag:yaml.org,2002:str")) (:CONTENT . "123"))
(represent-node "123")))
(is (equal '((:properties (:tag . "tag:lisp,2013:symbol")) (:CONTENT . "ASDF"))
(represent-node 'asdf)))
(is (equal '((:properties (:tag . "tag:lisp,2013:keyword")) (:CONTENT . "ASDF"))
(represent-node :asdf)))
(is (equal '((:properties (:tag . "tag:yaml.org,2002:seq"))
(:content . (((:properties (:tag . "tag:yaml.org,2002:int")) (:CONTENT . "1"))
((:properties (:tag . "tag:yaml.org,2002:int")) (:CONTENT . "2"))
((:properties (:tag . "tag:yaml.org,2002:int")) (:CONTENT . "3")))))
(represent-node '(1 2 3))))
(is (equal '((:properties (:tag . "tag:yaml.org,2002:map"))
(:content . (:mapping
(((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "e"))
. ((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "r")))
(((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "q"))
. ((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "w")))
(((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "t"))
. ((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "y"))))))
(let ((res (represent-node (let ((a (make-hash-table :test #'equal)))
(setf (gethash "q" a) "w"
(gethash "e" a) "r"
(gethash "t" a) "y")
a))))
(setf (cddadr res) (sort (cddadr res) #'string< :key (lambda (x)
(cdr (assoc :content (car x))))))
res)))
)
(defun gen-shared-sequence1 ()
(declare (optimize (safety 3) (speed 0)))
(let ((lst (list `(,(list :properties '(:tag . "tag:yaml.org,2002:str")) (:content . "foo"))
`(,(list :properties '(:tag . "tag:yaml.org,2002:str")) (:content . "bar"))
`(,(list :properties) (:content . "baz")))))
`(,(list :properties '(:tag . "tag:yaml.org,2002:seq"))
(:content . (,. lst ,(car lst))))))
(defun gen-shared-sequence2 ()
(let* ((list0 (list `(,(list :properties '(:tag . "tag:yaml.org,2002:str")) (:content . "foo"))))
(list1 (cons nil list0))
(seq `(,(list :properties '(:tag . "tag:yaml.org,2002:seq"))
(:content . ,list1))))
(setf (car list1) seq)
seq))
(defun gen-shared-mapping1 ()
(let ((node1 `(,(list :properties '(:tag . "tag:yaml.org,2002:str")) (:content . "foo")))
(node2 `(,(list :properties '(:tag . "tag:yaml.org,2002:str")) (:content . "bar")))
(node3 `(,(list :properties) (:content . "baz"))))
`(,(list :properties '(:tag . "tag:yaml.org,2002:map"))
(:content . (:mapping (,node1 . ,node2) (,node3 . ,node1))))))
;; (test serialization
;; (is (equal `((:properties (:tag . "tag:yaml.org,2002:seq"))
;; (:content .(((:properties (:anchor . "a1") (:tag . "tag:yaml.org,2002:str")) (:content . "foo"))
;; ((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "bar"))
;; ((:properties) (:content . "baz"))
;; (:alias . "a1"))))
;; (nserialize (gen-shared-sequence1))))
;; (is (equal '((:properties (:anchor . "a1") (:tag . "tag:yaml.org,2002:seq"))
;; (:content . ((:alias . "a1")
;; ((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "foo")))))
;; (nserialize (gen-shared-sequence2))))
;; (is (equal `((:properties (:tag . "tag:yaml.org,2002:map"))
;; (:content . (:mapping (((:properties (:anchor . "a1") (:tag . "tag:yaml.org,2002:str")) (:content . "foo"))
;; . ((:properties (:tag . "tag:yaml.org,2002:str")) (:content . "bar")))
;; (((:properties) (:content . "baz"))
;; . (:alias . "a1")))))
;; (nserialize (gen-shared-mapping1)))))
;;; Tests for loading of config files
(defun make-random-file-name (&optional (prefix "/tmp/cl-yy-"))
(concatenate 'string
prefix
(iter (for i from 1 to 8)
(collect (code-char (+ (char-code #\a) (random 26)))))))
(defmacro with-tmp-file ((var &optional prefix) &body body)
`(let ((,var (make-random-file-name ,@(if prefix `(,prefix)))))
(unwind-protect (progn ,@body)
(delete-file ,var))))
(defparameter *config-string*
#?"a : b\nc : d\ne : f")
(test yaml-load-file
(is (equal '(("a" . "b") ("c" . "d") ("e" . "f"))
(with-tmp-file (path)
(with-open-file (stream path :direction :output :if-exists :supersede)
(write-sequence *config-string* stream))
(hash->assoc (yaml-load-file path)))))
(signals (cl-yy::yaml-load-file-error)
(with-tmp-file (path)
(with-open-file (stream path :direction :output :if-exists :supersede)
(write-sequence *config-string* stream))
(hash->assoc (yaml-load-file path :size-limit 2))))
(is (equal nil
(with-tmp-file (path)
(with-open-file (stream path :direction :output :if-exists :supersede)
(write-sequence *config-string* stream))
(yaml-load-file path :size-limit 2 :on-size-exceed nil)))))
| 40,573 | Common Lisp | .lisp | 727 | 50.554333 | 119 | 0.573157 | mabragor/cl-yaclyaml | 14 | 3 | 8 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 4121074fa70e3f494848eb2a9828a65c4eec52cb36828e883319bb4cdd14d2b4 | 7,985 | [
-1
] |
7,986 | parsing.lisp | mabragor_cl-yaclyaml/parsing.lisp | ;;;; This file is one of components of CL-YACLYAML system, licenced under GPL, see COPYING for details
(in-package #:cl-yaclyaml)
;;; Parsing presentation stream
(register-yaclyaml-context n nil)
(setf n 0)
(register-yaclyaml-context indent-style determined autodetect)
(register-yaclyaml-context context block-out block-in flow-out flow-in block-key flow-key)
(register-yaclyaml-context block-scalar-chomping clip keep strip)
(register-yaclyaml-context block-scalar-style literal folded)
;;; Indicator characters
;; block structure indicators
(define-alias-rule c-sequence-entry #\-)
(define-alias-rule c-mapping-key #\?)
(define-alias-rule c-mapping-value #\:)
;; flow collection indicators
(define-alias-rule c-colon-entry #\,)
(define-alias-rule c-sequence-start #\[)
(define-alias-rule c-sequence-end #\])
(define-alias-rule c-mapping-start #\{)
(define-alias-rule c-mapping-end #\})
;; comments
(define-alias-rule c-comment #\#)
;; tags and aliases
(define-alias-rule c-anchor #\&)
(define-alias-rule c-alias #\*)
(define-alias-rule c-tag #\!)
;; block-scalar style
(define-alias-rule c-literal #\|)
(define-alias-rule c-folded #\>)
;; quoted scalars
(define-alias-rule c-single-quote #\')
(define-alias-rule c-double-quote #\")
(define-alias-rule c-directive #\%)
(define-alias-rule c-reserved (|| #\@ #\`))
(defun c-printable-p (char)
(let ((code (char-code char)))
(or (equal code 9)
(equal code #xa)
(equal code #xd)
(and (>= code #x20) (<= code #x7e))
(equal code #x85)
(and (>= code #xa0) (<= code #xd7ff))
(and (>= code #xe000) (<= code #xfffd))
(and (>= code #x10000) (<= code #x10ffff)))))
(define-yaclyaml-rule c-printable ()
(pred #'c-printable-p character))
(defun nb-json-p (char)
(let ((code (char-code char)))
(or (equal code 9)
(and (>= code #x20) (<= code #x10ffff)))))
(define-yaclyaml-rule nb-json ()
(pred #'nb-json-p character))
(define-yaclyaml-rule c-indicator ()
(|| c-sequence-entry c-mapping-key c-mapping-value
c-colon-entry c-sequence-start c-sequence-end c-mapping-start c-mapping-end
c-comment
c-anchor c-alias c-tag
c-literal c-folded
c-single-quote c-double-quote
c-directive
c-reserved))
(define-yaclyaml-rule c-flow-indicator ()
(|| c-colon-entry
c-sequence-start c-sequence-end
c-mapping-start c-mapping-end))
(define-yaclyaml-rule b-line-feed ()
(v #\newline))
(define-yaclyaml-rule b-carriage-return ()
(v #\return))
(define-yaclyaml-rule b-char ()
(|| b-line-feed b-carriage-return))
(define-yaclyaml-rule b-break ()
(|| (list (v b-carriage-return) (v b-line-feed))
b-carriage-return
b-line-feed)
#\newline)
;; ;; TODO - include BOM
(define-yy-rule nb-char ()
(! b-char)
(v character))
(define-yy-rule s-space () (v #\space))
(define-yy-rule s-tab () (v #\tab))
(define-yy-rule s-white () (|| s-space s-tab))
(define-yy-rule ns-char ()
(! s-white)
(v nb-char))
;; ;; TODO: write a character-ranges macro
;; ;; TODO: write ~ (ignore-case macro)
(define-yy-rule ns-dec-digit ()
(character-ranges (#\0 #\9)))
(define-yy-rule ns-hex-digit ()
(|| ns-dec-digit
;; KLUDGE, until I write ignore-case macro
#\a #\b #\c #\d #\e #\f
#\A #\B #\C #\D #\E #\F))
(define-yy-rule ns-ascii-letter ()
(pred #'alpha-char-p character))
(define-yy-rule ns-word-char ()
(|| ns-dec-digit
ns-ascii-letter
#\-))
(define-yy-rule ns-uri-char ()
(text (|| (list (v #\%) (v ns-hex-digit) (v ns-hex-digit))
ns-word-char
#\# #\; #\/ #\? #\: #\@ #\& #\= #\+ #\$ #\,
#\_ #\. #\! #\~ #\* #\' #\( #\) #\[ #\])))
(define-yy-rule ns-tag-char ()
(! #\!)
(! c-flow-indicator)
(v ns-uri-char))
;; ;; Escaped characters
(define-yy-rule c-escape () (v #\\))
(define-yy-rule ns-esc-null () (v #\0) (code-char 0))
(define-yy-rule ns-esc-bell () (v #\a) (code-char 7))
(define-yy-rule ns-esc-backspace () (v #\b) (code-char 8))
(define-yy-rule ns-esc-horizontal-tab () (v #\t) (code-char 9))
(define-yy-rule ns-esc-line-feed () (v #\n) (code-char 10))
(define-yy-rule ns-esc-vertical-tab () (v #\v) (code-char 11))
(define-yy-rule ns-esc-form-feed () (v #\f) (code-char 12))
(define-yy-rule ns-esc-carriage-return () (v #\r) (code-char 13))
(define-yy-rule ns-esc-escape () (v #\e) (code-char 27))
(define-yy-rule ns-esc-space () (v #\space) nil)
(define-yy-rule ns-esc-double-quote () (v #\")) ; TODO: fix this sad notation flaw ")
(define-yy-rule ns-esc-slash () (v #\/))
(define-yy-rule ns-esc-backslash () (v #\\))
(define-yy-rule ns-esc-next-line () (v #\N) (code-char 133))
(define-yy-rule ns-esc-non-breaking-space () (v #\_) (code-char 160))
(define-yy-rule ns-esc-line-separator () (v #\L) (code-char 8232))
(define-yy-rule ns-esc-paragraph-separator () (v #\P) (code-char 8233))
(define-yy-rule ns-esc-8-bit ()
(v #\x)
(code-char (parse-integer (text (times ns-hex-digit :exactly 2))
:radix 16)))
(define-yy-rule ns-esc-16-bit ()
(v #\u)
(code-char (parse-integer (text (times ns-hex-digit :exactly 4))
:radix 16)))
(define-yy-rule ns-esc-32-bit ()
(v #\U)
(code-char (parse-integer (text (times ns-hex-digit :exactly 8))
:radix 16)))
(define-yy-rule c-ns-esc-char ()
(v #\\)
(|| ns-esc-null
ns-esc-bell
ns-esc-backspace
ns-esc-horizontal-tab
ns-esc-line-feed
ns-esc-vertical-tab
ns-esc-form-feed
ns-esc-carriage-return
ns-esc-escape
ns-esc-space
ns-esc-double-quote
ns-esc-slash
ns-esc-backslash
ns-esc-next-line
ns-esc-non-breaking-space
ns-esc-line-separator
ns-esc-paragraph-separator
ns-esc-8-bit
ns-esc-16-bit
ns-esc-32-bit))
;; ;; Indentation
(define-yy-rule s-indent-<n ()
(length (cond-parse ((v autodetect-indent-style) (times s-space))
((v determined-indent-style) (times s-space :upto (- n 1))))))
(define-yy-rule s-indent-<=n ()
(length (cond-parse ((v autodetect-indent-style) (times s-space))
((v determined-indent-style) (times s-space :upto n)))))
(define-yy-rule s-indent-=n ()
(length (cond-parse ((v autodetect-indent-style) (times s-space :from (+ n 1)))
((v determined-indent-style) (times s-space :exactly n)))))
(define-yy-rule start-of-line ()
(|| (<- sof) (<- b-char)))
(define-yy-rule s-separate-in-line ()
(|| (postimes s-white)
start-of-line))
(define-yy-rule s-block-line-prefix () (v s-indent-=n))
(define-yy-rule s-flow-line-prefix ()
(list (v s-indent-=n)
(? s-separate-in-line)))
(define-yy-rule s-line-prefix ()
(cond-parse ((|| block-out-context block-in-context) (v s-block-line-prefix))
((|| flow-out-context flow-in-context) (v s-flow-line-prefix))))
(define-yy-rule l-empty ()
(|| s-line-prefix s-indent-<n)
(v b-break))
(define-yy-rule b-l-trimmed ()
(v b-break)
(make-string (length (postimes l-empty))
:initial-element #\newline))
(define-yy-rule b-as-space ()
(v b-break)
(! l-empty)
" ")
(define-yy-rule b-l-folded ()
(|| b-l-trimmed b-as-space))
(define-context-forcing-rule flow-in b-l-folded)
(define-yy-rule s-flow-folded ()
(? s-separate-in-line)
(prog1 (v flow-in-b-l-folded)
(v s-flow-line-prefix)))
;; comments
(define-yy-rule c-nb-comment-text ()
(v #\#)
(times nb-char)
nil)
(define-yy-rule b-comment () (|| (-> eof) b-char))
(define-yy-rule s-b-comment ()
(? (progn (v s-separate-in-line)
(? c-nb-comment-text)))
(v b-comment)
nil)
(define-yy-rule l-comment ()
(v s-separate-in-line)
(? c-nb-comment-text)
(v b-comment)
nil)
(define-yy-rule s-l-comments ()
(|| s-b-comment start-of-line)
(times l-comment)
nil)
;; ;; separation lines
(define-yy-rule s-separate-lines ()
(|| (progn (v s-l-comments)
(v s-flow-line-prefix))
s-separate-in-line)
" ")
(define-yy-rule s-separate ()
(cond-parse ((|| block-out-context
block-in-context
flow-out-context
flow-in-context) (v s-separate-lines))
((|| block-key-context flow-key-context) (v s-separate-in-line))))
;; ;; Directives (finally, something non-trivial)
(define-yy-rule l-directive ()
(v #\%)
(prog1 (|| ns-yaml-directive
ns-tag-directive
ns-reserved-directive)
(v s-l-comments)))
(define-yy-rule ns-reserved-directive ()
(list (v ns-directive-name) (times (progn (v s-separate-in-line)
(v ns-directive-parameter)))))
(define-yy-rule ns-directive-name () (postimes ns-char))
(define-yy-rule ns-directive-parameter () (postimes ns-char))
;; YAML directive
;;; Lets hack logic of %YAML directive, since this is simple enough for me to understand now.
(defparameter yaml-version nil)
(define-yy-rule ns-yaml-directive ()
(let ((version (progn (v "YAML") (v s-separate-in-line) (v ns-yaml-version))))
(if yaml-version
(fail-parse "The YAML directive must be only given once per document.")
(if (not (equal (car version) 1))
(fail-parse-format "Major version ~a differs from processor's version." (car version))
(progn (if (> (cadr version) 2)
(warn-parse "Minor version is greater than that of the processor, attempt to parse anyway."))
(setf yaml-version version)
nil)))))
(define-yy-rule ns-yaml-version ()
(let* ((major (postimes ns-dec-digit))
(pt (v #\.))
(minor (postimes ns-dec-digit)))
(declare (ignore pt))
`(,(parse-integer (text major)) ,(parse-integer (text minor)))))
;; TAG directive
(eval-when (:compile-toplevel :load-toplevel :execute)
(defparameter tag-handles (make-hash-table :test #'equal))
(defparameter default-yaml-tagspace "tag:yaml.org,2002:")
(defparameter default-local-tagspace "!")
(setf (gethash :secondary-tag-handle tag-handles) default-yaml-tagspace
(gethash :primary-tag-handle tag-handles) default-local-tagspace))
(define-yy-rule ns-tag-directive ()
(let* ((tag (v "TAG"))
(sep (v s-separate-in-line))
(handle (v c-tag-handle))
(sep1 (v s-separate-in-line))
(prefix (v ns-tag-prefix)))
(declare (ignore tag sep sep1))
;; (format t (literal-string "got tag directive: ~a ~a~%") handle prefix)
(if (gethash handle tag-handles)
(fail-parse "The TAG directive must be given at most once per handle in the same document.")
(setf (gethash handle tag-handles) prefix))
;; TODO: should I write NIL here, or I must emit a tag-prefix instead?
nil))
(define-yy-rule c-tag-handle ()
(|| c-named-tag-handle
c-secondary-tag-handle
c-primary-tag-handle))
(define-yy-rule c-primary-tag-handle ()
(v #\!) :primary-tag-handle)
(define-yy-rule c-secondary-tag-handle ()
(v "!!") :secondary-tag-handle)
(define-yy-rule c-named-tag-handle ()
`(:named-tag-handle ,(text (progn (v #\!)
(prog1 (postimes ns-word-char)
(v #\!))))))
(define-yy-rule ns-tag-prefix ()
(text (|| c-ns-local-tag-prefix
ns-global-tag-prefix)))
(define-yy-rule c-ns-local-tag-prefix ()
(list (v #\!) (times ns-uri-char)))
(define-yy-rule ns-global-tag-prefix ()
(list (v ns-tag-char) (times ns-uri-char)))
;;; Node properties
(define-yy-rule c-ns-properties ()
`(:properties ,@(remove-if-not #'identity
(|| (list (v c-ns-tag-property) (? (progn (v s-separate)
(v c-ns-anchor-property))))
(list (v c-ns-anchor-property) (? (progn (v s-separate)
(v c-ns-tag-property))))))))
(define-yy-rule c-ns-tag-property ()
(|| c-verbatim-tag
c-ns-shorthand-tag
c-non-specific-tag))
(define-yy-rule c-verbatim-tag ()
`(:tag . ,(text (progm "!<" (postimes ns-uri-char) ">"))))
(defun resolve-handle (handle)
(or (gethash handle tag-handles)
(fail-parse-format "Unknown handle ~a. Did you forget to declare it?" handle)))
(define-yy-rule c-ns-shorthand-tag ()
(let ((handle (v c-tag-handle))
(meat (postimes ns-tag-char)))
`(:tag . ,(text (resolve-handle handle) meat))))
(define-yy-rule c-non-specific-tag ()
`(:tag . ,(progn (v "!") :vanilla)))
(define-yy-rule c-ns-anchor-property ()
`(:anchor . ,(text (progn (v #\&) (v ns-anchor-name)))))
(define-yy-rule ns-anchor-char ()
(! c-flow-indicator)
(v ns-char))
(define-yy-rule ns-anchor-name ()
(postimes ns-anchor-char))
;;; alias nodes
(define-yy-rule c-ns-alias-node ()
`(:alias . ,(text (progn (v #\*) (v ns-anchor-name)))))
;;; empty node
(define-yy-rule e-scalar () :empty)
(define-yy-rule e-node ()
`((:properties (:tag . :non-specific)) (:content . ,(v e-scalar))))
;;; double-quoted-scalars
(define-yy-rule nb-double-char ()
(|| c-ns-esc-char
(progn (! #\\)
(! #\")
(v nb-json))))
(define-yy-rule ns-double-char ()
(! s-white)
(v nb-double-char))
(define-yy-rule c-double-quoted ()
(text (progm #\" nb-double-text #\")))
(define-yy-rule nb-double-text ()
(cond-parse ((|| block-key-context flow-key-context) (v nb-double-one-line))
((|| block-out-context
block-in-context
flow-out-context
flow-in-context) (v nb-double-multi-line))))
(define-yy-rule nb-double-one-line ()
(times nb-double-char))
(define-context-forcing-rule flow-in l-empty)
(define-yy-rule s-double-escaped ()
(destructuring-bind (white slash bnc empties pref)
(list (times s-white) (v #\\) (v b-non-content)
(times flow-in-l-empty) (v s-flow-line-prefix))
(declare (ignore slash bnc))
`(,white ,empties ,(mapcar (lambda (x)
(if (numberp x)
(make-string x :initial-element #\space)
x))
pref))))
(define-yy-rule s-double-break ()
(|| s-double-escaped s-flow-folded))
(define-yy-rule nb-ns-double-in-line ()
(times (list (times s-white) (v ns-double-char))))
(define-yy-rule s-double-next-line ()
(list (v s-double-break)
(? (list (v ns-double-char)
(v nb-ns-double-in-line)
(|| (v s-double-next-line) (times s-white))))))
(define-yy-rule nb-double-multi-line ()
(list (v nb-ns-double-in-line)
(|| (v s-double-next-line) (times s-white))))
(defun whitespace-p (text)
(iter (for char in-string text)
(if (not (member char '(#\tab #\space)))
(return nil))
(finally (return t))))
;;; single-quoted-scalars
(define-yy-rule c-quoted-quote ()
(v #\') (v #\'))
(define-yy-rule nb-single-char ()
(|| c-quoted-quote
(progn (! #\')
(v nb-json))))
(define-yy-rule ns-single-char ()
(! s-white)
(v nb-single-char))
(define-yy-rule c-single-quoted ()
(text (progm #\' nb-single-text #\')))
(define-yy-rule nb-single-text ()
(cond-parse ((|| block-key-context flow-key-context) (v nb-single-one-line))
((|| block-out-context
block-in-context
flow-out-context
flow-in-context) (v nb-single-multi-line))))
(define-yy-rule nb-single-one-line ()
(times nb-single-char))
(define-yy-rule nb-ns-single-in-line ()
(times (list (times s-white) (v ns-single-char))))
(define-yy-rule s-single-next-line ()
(list (v s-flow-folded)
(? (list (v ns-single-char)
(v nb-ns-single-in-line)
(|| s-single-next-line (times s-white))))))
(define-yy-rule nb-single-multi-line ()
(list (v nb-ns-single-in-line)
(|| s-single-next-line
(times s-white))))
;; Block scalars
(define-yy-rule c-b-block-header ()
(prog1 (|| (list (v c-indentation-indicator-ne) (v c-chomping-indicator))
(list (v c-chomping-indicator-ne) (v c-indentation-indicator))
(list (v c-chomping-indicator) (v c-indentation-indicator)))
(v s-b-comment)))
(define-yy-rule c-indentation-indicator-ne ()
`(:block-indentation-indicator . ,(string (v ns-dec-digit))))
(define-yy-rule c-indentation-indicator ()
`(:block-indentation-indicator . ,(string (|| ns-dec-digit
""))))
(define-yy-rule c-chomping-indicator-ne ()
`(:block-chomping-indicator . ,(string (|| #\- #\+))))
(define-yy-rule c-chomping-indicator ()
`(:block-chomping-indicator . ,(string (|| #\- #\+ ""))))
(defun hash->assoc (hash)
(iter (for (key val) in-hashtable hash)
(collect `(,key . ,val))))
(define-yy-rule b-chomped-last ()
(v b-break)
(case block-scalar-chomping
(:clip #\newline)
(:keep #\newline)
(:strip nil)))
(define-yy-rule b-non-content ()
(v b-break)
nil)
(define-yy-rule b-as-line-feed ()
(v b-break))
(define-yy-rule l-chomped-empty ()
(cond-parse ((|| strip-block-scalar-chomping
clip-block-scalar-chomping) (v l-strip-empty))
((v keep-block-scalar-chomping) (v l-keep-empty))))
(define-yy-rule l-strip-empty ()
(times (progn (v s-indent-<=n) (v b-non-content)))
(? l-trail-comments)
(v ""))
(define-yy-rule l-keep-empty ()
(list (times l-empty)
(? l-trail-comments)))
(define-yy-rule l-trail-comments ()
(v s-indent-<n)
(v c-nb-comment-text)
(v b-comment)
(times l-comment)
(v ""))
(define-yy-rule l-literal-content ()
(text (? (list (v l-nb-literal-text)
(times b-nb-literal-next)
(v b-chomped-last)))
(v l-chomped-empty)))
(let ((chomping-map '(("+" . :keep) ("-" . :strip) ("" . :clip)))
(style-map '(("|" . :literal) (">" . :folded))))
(define-yy-rule c-l-block-scalar ()
(macrolet ((call-parser ()
`(text (v block-scalar-content))))
(let ((header (list (|| "|" ">") (v c-b-block-header))))
(let ((block-scalar-chomping (cdr (assoc (cdr (assoc :block-chomping-indicator
(cadr header)))
chomping-map
:test #'equal)))
(block-scalar-style (cdr (assoc (car header)
style-map
:test #'equal))))
(let ((it (cdr (assoc :block-indentation-indicator
(cadr header)))))
(if (not (equal it ""))
(let ((n (+ n (parse-integer it)))
(indent-style :determined))
(call-parser))
(let ((indent-style :autodetect))
(call-parser)))))))))
(define-yy-rule block-scalar-content ()
(let ((wrapper (cond-parse ((v autodetect-indent-style) (v detect-indent))
(t ""))))
(macrolet ((call-parser ()
`(cond-parse ((v literal-block-scalar-style) (v l-literal-content))
((v folded-block-scalar-style) (v l-folded-content)))))
(if (equal wrapper "")
(call-parser)
(let ((n wrapper)
(indent-style :determined))
(call-parser))))))
(define-yy-rule detect-indent ()
(& (progm (times l-empty) s-indent-=n nb-char)))
(define-yy-rule l-nb-literal-text ()
(list (times l-empty)
(progn (v s-indent-=n) (postimes nb-char))))
(define-yy-rule b-nb-literal-next ()
(list (v b-as-line-feed) (v l-nb-literal-text)))
(define-yy-rule s-nb-folded-text ()
(v s-indent-=n)
(list (v ns-char) (times nb-char)))
(define-yy-rule l-nb-folded-lines ()
(list (v s-nb-folded-text)
(times (list (v b-l-folded) (v s-nb-folded-text)))))
(define-yy-rule s-nb-spaced-text ()
(v s-indent-=n)
(list (v s-white) (times nb-char)))
(define-yy-rule b-l-spaced ()
(list (v b-as-line-feed) (times l-empty)))
(define-yy-rule l-nb-spaced-lines ()
(list (v s-nb-spaced-text)
(times (list (v b-l-spaced) (v s-nb-spaced-text)))))
(define-yy-rule l-nb-same-lines ()
(list (times l-empty)
(|| l-nb-folded-lines l-nb-spaced-lines)))
(define-yy-rule l-nb-diff-lines ()
(list (v l-nb-same-lines)
(times (list (v b-as-line-feed) (v l-nb-same-lines)))))
(define-yy-rule l-folded-content ()
(list (? (list (v l-nb-diff-lines) (v b-chomped-last)))
(v l-chomped-empty)))
;;; Plain scalars
(define-yy-rule ns-plain-first ()
(|| (progn (! c-indicator)
(v ns-char))
(prog1 (|| #\? #\: #\-)
(& ns-plain-safe))))
(define-yy-rule ns-plain-safe ()
(cond-parse ((|| flow-out-context
block-key-context
block-in-context
block-out-context) (v ns-plain-safe-out))
((|| flow-in-context flow-key-context) (v ns-plain-safe-in))))
(define-yy-rule ns-plain-safe-out () (v ns-char))
(define-yy-rule ns-plain-safe-in ()
(! c-flow-indicator)
(v ns-char))
(define-yy-rule ns-plain-char ()
(cond-parse ((list (! #\:) (! #\#)) (v ns-plain-safe))
((<- ns-char) (v #\#))
(t (prog1 (v #\:) (-> ns-plain-safe)))))
(define-yy-rule ns-plain ()
(cond-parse ((|| flow-out-context
flow-in-context
block-out-context
block-in-context) (v ns-plain-multi-line))
((|| block-key-context flow-key-context) (v ns-plain-one-line))))
(define-yy-rule nb-ns-plain-in-line ()
(times (list (times s-white) (v ns-plain-char))))
(define-yy-rule ns-plain-one-line ()
(text (v ns-plain-first) (v nb-ns-plain-in-line)))
(define-yy-rule s-ns-plain-next-line ()
(list (v s-flow-folded) (v ns-plain-char) (v nb-ns-plain-in-line)))
(define-yy-rule ns-plain-multi-line ()
(text (v ns-plain-one-line) (times s-ns-plain-next-line)))
;; block sequences
(define-yy-rule l+block-sequence ()
(let ((n (v detect-block-sequence))
(indent-style :determined)
(context :block-in))
(postimes (progn (v s-indent-=n)
(v c-l-block-seq-entry)))))
(define-yy-rule detect-block-sequence ()
(let ((indent-style :autodetect))
(& (prog1 (v s-indent-=n)
(& (list (v #\-) (! ns-char)))))))
(define-yy-rule detect-block-mapping ()
(let ((indent-style :autodetect))
(& (prog1 (v s-indent-=n)
(v ns-char)))))
(define-yy-rule c-l-block-seq-entry ()
(v "-") (! ns-char)
(v s-l+block-indented))
(define-yy-rule s-l+block-indented ()
(|| compact-block-node
s-l+block-node
(prog1 (v e-node)
(v s-l-comments))))
(define-yy-rule compact-block-node ()
(let ((n (+ n 1 (length (postimes s-space))))
(indent-style :determined))
`((:properties (:tag . :non-specific))
(:content . ,(|| ns-l-compact-sequence ns-l-compact-mapping)))))
(define-yy-rule ns-l-compact-sequence ()
`(,(v c-l-block-seq-entry)
,.(times (progn (v s-indent-=n) (v c-l-block-seq-entry)))))
(define-yy-rule l+block-mapping ()
(let ((n (v detect-block-mapping))
(indent-style :determined))
`(:mapping ,.(postimes (progn (v s-indent-=n) (v ns-l-block-map-entry))))))
(define-yy-rule ns-l-block-map-entry ()
(destructuring-bind (key value) (|| c-l-block-map-explicit-entry
ns-l-block-map-implicit-entry)
`(,key . ,value)))
(define-yy-rule c-l-block-map-explicit-entry ()
(list (v c-l-block-map-explicit-key)
(|| l-block-map-explicit-value
e-node)))
(define-yy-rule c-l-block-map-explicit-key ()
(let ((context :block-out))
(v #\?)
(v s-l+block-indented)))
(define-yy-rule l-block-map-explicit-value ()
(let ((context :block-out))
(v s-indent-=n)
(v ":")
(v s-l+block-indented)))
(define-yy-rule ns-l-block-map-implicit-entry ()
(list (|| ns-s-block-map-implicit-key
e-node)
(v c-l-block-map-implicit-value)))
(define-yy-rule ns-s-block-map-implicit-key ()
(let ((context :block-key))
(|| c-s-implicit-json-key
ns-s-implicit-yaml-key)))
(define-yy-rule c-l-block-map-implicit-value ()
(v #\:)
(let ((context :block-out))
(|| s-l+block-node
(prog1 (v e-node)
(v s-l-comments)))))
(define-yy-rule ns-l-compact-mapping ()
`(:mapping ,(v ns-l-block-map-entry) ,.(times (progn (v s-indent-=n)
(v ns-l-block-map-entry)))))
;; block nodes
(define-yy-rule s-l+block-node ()
(|| s-l+block-in-block s-l+flow-in-block))
(define-yy-rule s-l+flow-in-block ()
(let ((context :flow-out)
(n (1+ n)))
(progm s-separate ns-flow-node s-l-comments)))
(define-yy-rule s-l+block-in-block ()
(|| s-l+block-scalar s-l+block-collection))
(define-yy-rule s-separate-n+1 ()
(let ((n (1+ n)))
(v s-separate)))
(defparameter vanilla-scalar-tag "tag:yaml.org,2002:str")
(defparameter vanilla-mapping-tag "tag:yaml.org,2002:map")
(defparameter vanilla-sequence-tag "tag:yaml.org,2002:seq")
(define-yy-rule s-l+block-scalar ()
(v s-separate-n+1)
(let ((props (v block-node-properties))
(content (v c-l-block-scalar)))
(crunch-tag-into-properties props vanilla-scalar-tag vanilla-scalar-tag)
`(,props (:content . ,content))))
(define-yy-rule block-node-properties ()
(let ((n (1+ n)))
(? (progn (v s-separate) (v c-ns-properties)))))
(defun seq-spaces (n)
(if (eql context :block-out)
(1- n)
n))
(define-yy-rule s-l+block-collection ()
(let ((props (v block-node-properties)))
(v s-l-comments)
(let ((content (|| l+block-sequence-seq-spaces
l+block-mapping)))
(crunch-tag-into-properties props :non-specific
(case (car content)
(:mapping vanilla-mapping-tag)
(t vanilla-sequence-tag)))
`(,props (:content . ,content)))))
(define-yy-rule l+block-sequence-seq-spaces ()
(let ((n (seq-spaces n)))
(v l+block-sequence)))
;; flow collections
(defun in-flow (context)
(case context
((:block-in :block-out :flow-in :flow-out) :flow-in)
((:block-key :flow-key) :flow-key)))
(define-yy-rule c-flow-sequence ()
(v #\[) (? s-separate)
(let ((context (in-flow context)))
(prog1 (? ns-s-flow-seq-entries)
(v #\]))))
(define-yy-rule ns-s-flow-seq-entries ()
(let ((entry (v ns-flow-seq-entry)))
(? s-separate)
(let ((entries (? (progn (v #\,) (? s-separate) (? ns-s-flow-seq-entries)))))
`(,entry ,. entries))))
(define-yy-rule ns-flow-seq-entry ()
(|| ns-flow-pair ns-flow-node))
(define-yy-rule c-flow-mapping ()
(v #\{) (? s-separate)
(let ((context (in-flow context)))
`(:mapping ,. (prog1 (? ns-s-flow-map-entries)
(v #\})))))
(define-yy-rule ns-s-flow-map-entries ()
(let ((entry (v ns-flow-map-entry)))
(? s-separate)
(let ((entries (? (progn (v #\,) (? s-separate) (? ns-s-flow-map-entries)))))
`(,entry ,. entries))))
(define-yy-rule ns-flow-map-entry ()
(destructuring-bind (key value) (|| (progn (v #\?) (v s-separate) (v ns-flow-map-explicit-entry))
ns-flow-map-implicit-entry)
`(,key . ,value)))
(define-yy-rule ns-flow-map-explicit-entry ()
(|| ns-flow-map-implicit-entry
(list (v e-node) (v e-node))))
(define-yy-rule ns-flow-map-implicit-entry ()
(|| ns-flow-map-yaml-key-entry
c-ns-flow-map-empty-key-entry
c-ns-flow-map-json-key-entry))
(define-yy-rule ns-flow-map-yaml-key-entry ()
(list (v ns-flow-yaml-node)
(|| (progn (? s-separate) (v c-ns-flow-map-separate-value))
e-node)))
(define-yy-rule c-ns-flow-map-empty-key-entry ()
(list (v e-node) (v c-ns-flow-map-separate-value)))
(define-yy-rule c-ns-flow-map-separate-value ()
(v #\:) (! ns-plain-safe)
(|| (progn (v s-separate) (v ns-flow-node))
e-node))
(define-yy-rule c-ns-flow-map-json-key-entry ()
(list (v c-flow-json-node)
(|| (progn (? s-separate) (v c-ns-flow-map-adjacent-value))
e-node)))
(define-yy-rule c-ns-flow-map-adjacent-value ()
(v #\:)
(|| (progn (? s-separate) (v ns-flow-node))
e-node))
(define-yy-rule ns-flow-pair ()
(destructuring-bind (key value) (|| (progn (v #\?) (v s-separate) (v ns-flow-map-explicit-entry))
ns-flow-pair-entry)
`(:mapping (,key . ,value))))
(define-yy-rule ns-flow-pair-entry ()
(|| ns-flow-pair-yaml-key-entry
c-ns-flow-map-empty-key-entry
c-ns-flow-pair-json-key-entry))
(define-context-forcing-rule flow-key ns-s-implicit-yaml-key)
(define-context-forcing-rule flow-key c-s-implicit-json-key)
(define-yy-rule ns-flow-pair-yaml-key-entry ()
(list (v flow-key-ns-s-implicit-yaml-key)
(v c-ns-flow-map-separate-value)))
(define-yy-rule c-ns-flow-pair-json-key-entry ()
(list (v flow-key-c-s-implicit-json-key)
(v c-ns-flow-map-adjacent-value)))
;; FIXME: implement restriction on the length of the key
;; FIXME: implement n/a in the indentation portion
(define-yy-rule ns-s-implicit-yaml-key ()
(prog1 (v ns-flow-yaml-node)
(? s-separate-in-line)))
(define-yy-rule c-s-implicit-json-key ()
(prog1 (v c-flow-json-node)
(? s-separate-in-line)))
(define-yy-rule ns-flow-yaml-content () (v ns-plain))
(define-yy-rule c-flow-json-content ()
(|| c-flow-sequence
c-flow-mapping
c-single-quoted
c-double-quoted))
(define-yy-rule ns-flow-content ()
(|| (list :yaml (v ns-flow-yaml-content))
(list :json (v c-flow-json-content))))
(defmacro with-ensured-properties-not-alias (var &body body)
`(if (alias-p ,var)
,var
(let ((,var (cond ((property-node-p ,var) ,var)
(t `(,(list :properties) (:content . ,,var))))))
,@body)))
(define-yy-rule ns-flow-yaml-node ()
(let ((node (|| c-ns-alias-node
ns-flow-yaml-content
ns-flow-yaml-properties-node)))
(with-ensured-properties-not-alias node
(let ((props (assoc :properties node))
(content (cdr (assoc :content node))))
(crunch-tag-into-properties props :non-specific vanilla-scalar-tag)
`(,props (:content . ,content))))))
(define-yy-rule ns-flow-yaml-properties-node ()
`(,(v c-ns-properties) (:content . ,(|| (progn (v s-separate) (v ns-flow-yaml-content))
e-scalar))))
(define-yy-rule c-flow-json-node ()
(let ((props (? (prog1 (v c-ns-properties)
(v s-separate))))
(content (v c-flow-json-content)))
(if (atom content)
(crunch-tag-into-properties props vanilla-scalar-tag vanilla-scalar-tag)
(crunch-tag-into-properties props :non-specific (if (equal (car content) :mapping)
vanilla-mapping-tag
vanilla-sequence-tag)))
`(,props (:content . ,content))))
(define-yy-rule ns-flow-node ()
(let ((node (|| c-ns-alias-node
ns-flow-content
ns-flow-properties-node)))
(with-ensured-properties-not-alias node
(let ((props (assoc :properties node))
(content (cdr (assoc :content node))))
(destructuring-bind (content-type content) content
(crunch-tag-into-properties props
(cond ((eql content-type :yaml) :non-specific)
((eql content-type :json)
(cond ((atom content) vanilla-scalar-tag)
((eql (car content) :mapping) :non-specific)
(t :non-specific))))
(cond ((atom content) vanilla-scalar-tag)
((eql (car content) :mapping) vanilla-mapping-tag)
(t vanilla-sequence-tag)))
`(,props (:content . ,content)))))))
(define-yy-rule ns-flow-properties-node ()
`(,(v c-ns-properties)
(:content . ,(|| (progn (v s-separate) (v ns-flow-content))
(list :yaml (v e-scalar))))))
;;; YaML documents
;; FIXME: correct definition of byte-order-mark
(define-yy-rule c-byte-order-mark ()
(progn (v #\UEFBB) (v #\INVERTED_QUESTION_MARK) :utf8-bom))
(define-yy-rule l-document-prefix ()
(list (? c-byte-order-mark) (times l-comment)))
(define-yy-rule c-directives-end ()
(times #\- :exactly 3))
(define-yy-rule c-document-end ()
(times #\. :exactly 3))
(define-yy-rule l-document-suffix ()
(list (v c-document-end) (v s-l-comments)))
(define-yy-rule c-forbidden ()
(list (v start-of-line)
(|| c-directives-end c-document-end)
(|| b-char s-white (-> eof))))
(define-yy-rule l-bare-document ()
(let ((text (times (list (! c-forbidden)
(list (times nb-char)
(? b-break))))))
;; (format t (literal-string "text: ~a~%") text)
(let ((n -1)
(indent-style :determined)
(context :block-in))
(let ((it (handler-case (yy-parse 's-l+block-node (text text))
(esrap-liquid::simple-esrap-error ()
(fail-parse "Bare document parse failed")))))
`(:document ,it)))))
(define-yy-rule l-explicit-document ()
(let ((text (progn (v c-directives-end) (|| l-bare-document
(prog1 (v e-node) (v s-l-comments))))))
`(:document ,(if (and (consp text) (eql (car text) :document))
(cadr text)
text))))
(define-yy-rule l-directive-document ()
(let ((yaml-version nil)
(tag-handles (make-hash-table :test #'equal)))
(postimes l-directive)
(compile-tag-handles)
(if (not (gethash :secondary-tag-handle tag-handles))
(setf (gethash :secondary-tag-handle tag-handles) default-yaml-tagspace))
(if (not (gethash :primary-tag-handle tag-handles))
(setf (gethash :primary-tag-handle tag-handles) default-local-tagspace))
(v l-explicit-document)))
(let (path)
(declare (special path))
(defun try-resolve (handle)
(multiple-value-bind (prefix position)
(yaclyaml-parse 'c-tag-handle handle :junk-allowed t)
;; (format t "~%in resolving handle: ~a ~a ~a~%" handle prefix position)
(if prefix
(let ((pos (position prefix path :test #'equal)))
(if (and pos position (not (equal 0 pos)))
(error "Loop in prefixes resolution: ~a~%" `(,@(subseq path pos) ,prefix))
(strcat (gethash prefix tag-handles)
(if position
(subseq handle position)))))
handle)))
(defun compile-tag-handles ()
;; (format t "~%handles: ~a ~%" (hash->assoc tag-handles))
(iter (for (key . nil) in (hash->assoc tag-handles))
;; (format t "handle: ~a ~%" key)
(let ((path `(,key)))
(declare (special path))
(iter (while t)
(let ((val (gethash key tag-handles)))
;; (format t "value: ~a ~%" val)
(let ((try-val (try-resolve val)))
;; (format t "try-value: ~a ~%" try-val)
(if (equal try-val val)
(terminate)
(setf (gethash key tag-handles) try-val
val try-val
path (cons try-val path))))))))
;; (format t "~%compiled handles: ~a ~%" (hash->assoc tag-handles))
))
(define-yy-rule l-any-document ()
(|| l-directive-document
l-explicit-document
l-bare-document))
(define-yy-rule l-yaml-stream ()
(let ((first (progn (times l-document-prefix) (? l-any-document)))
(rest (times (|| (progn (postimes l-document-suffix)
(times l-document-prefix)
(? l-any-document))
(progn (times l-document-prefix)
(? l-explicit-document))))))
`(,first ,.(if (and rest (car rest)) rest (list)))))
| 33,417 | Common Lisp | .lisp | 903 | 33.094131 | 102 | 0.635536 | mabragor/cl-yaclyaml | 14 | 3 | 8 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | a8b756d593f06058327218690a4b2a98f17f4c4bfdd6c4594bf92657b02c6f9a | 7,986 | [
-1
] |
7,987 | esrap-parser-basics.lisp | mabragor_cl-yaclyaml/esrap-parser-basics.lisp | ;;; Basic constructions needed to start writing an ESRAP-based parser
;;; Pilfered from cl-closure-templates
(in-package #:esrap-parser-basics)
(defmacro define-esrap-env (symbol)
`(progn (eval-always
(defvar ,(sb-int:symbolicate symbol "-RULES") (make-hash-table))
(defvar ,(sb-int:symbolicate symbol "-CONTEXTS") nil))
(defmacro ,(sb-int:symbolicate "WITH-" symbol "-RULES") (&body body)
`(let ((esrap-liquid::*rules* ,',(sb-int:symbolicate symbol "-RULES")))
,@body))
(defmacro ,(sb-int:symbolicate "WITH-" symbol "-CONTEXTS") (&body body)
`(let ((esrap-liquid::contexts ,',(sb-int:symbolicate symbol "-CONTEXTS")))
,@body))
(defmacro ,(sb-int:symbolicate 'define-rule) (symbol expression &body options)
`(,',(sb-int:symbolicate "WITH-" symbol "-RULES")
(,',(sb-int:symbolicate "WITH-" symbol "-CONTEXTS")
(defrule ,symbol ,expression ,@options))))
(defmacro ,(sb-int:symbolicate "REGISTER-" symbol "-CONTEXT")
(context-var &rest plausible-contexts)
`(progn (defparameter ,context-var ,(sb-int:keywordicate (format nil "~a" (car plausible-contexts))))
,@(mapcar (lambda (context-name)
(let ((pred-name (sb-int:symbolicate context-name
"-"
context-var
"-P"))
(rule-name (sb-int:symbolicate context-name
"-"
context-var)))
`(progn
(defun ,pred-name (x)
(declare (ignore x))
(equal ,context-var ,(sb-int:keywordicate context-name)))
(,(sb-int:symbolicate 'define-rule) ,rule-name (,pred-name "")
(:constant nil)))))
(mapcar (lambda (x) (format nil "~a" x)) plausible-contexts))
(push ',context-var ,',(sb-int:symbolicate symbol "-CONTEXTS"))))
(defmacro ,(sb-int:symbolicate symbol "-PARSE")
(expression text &key (start nil start-p)
(end nil end-p)
(junk-allowed nil junk-allowed-p))
`(,',(sb-int:symbolicate "WITH-" symbol "-RULES")
(,',(sb-int:symbolicate "WITH-" symbol "-CONTEXTS")
(parse ,(if (and (consp expression)
(eql (car expression) 'quote)
(equal (length expression) 2)
(symbolp (cadr expression))
(not (keywordp (cadr expression))))
`',(intern (string (cadr expression))
',*package*)
expression)
,text
,@(if start-p `(:start ,start))
,@(if end-p `(:end ,end))
,@(if junk-allowed-p
`(:junk-allowed ,junk-allowed))))))))
;; This is the example of macroexpansion
#+nil
(define-esrap-env yaclyaml)
| 2,578 | Common Lisp | .lisp | 58 | 37.068966 | 106 | 0.609475 | mabragor/cl-yaclyaml | 14 | 3 | 8 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | dd99ea939e9873bec977f6ed0998eccaf9e8d05ba1d0bad19d4b20af880eadf4 | 7,987 | [
-1
] |
7,988 | composing.lisp | mabragor_cl-yaclyaml/composing.lisp | ;;;; This file is one of components of CL-YACLYAML system, licenced under GPL, see COPYING for details
(in-package #:cl-yaclyaml)
;;; Composing representation graph
(defparameter anchors (make-hash-table :test #'equal))
(defun property-node-p (node)
(handler-case (assoc :properties node)
(error () nil)))
(defun mapping-node-p (node)
(eql (car node) :mapping))
(defun alias-p (node)
(and (consp node) (eql (car node) :alias)))
(defun ncompose-representation-graph (representation-tree)
"Destructively composes representation graph from representation tree."
(let ((anchors (make-hash-table :test #'equal)))
(flet ((update-anchors-if-present (node)
(let ((anchor (cdr (assoc :anchor (cdr (assoc :properties node))))))
(if anchor
(setf (gethash anchor anchors) node
(cdr (assoc :properties node)) (remove-if (lambda (x)
(eql (car x) :anchor))
(cdr (assoc :properties node))))))))
(macrolet ((glue-alias (place)
(with-gensyms (g!-node)
`(let ((,g!-node (gethash (cdr ,place) anchors)))
(if ,g!-node
(setf ,place ,g!-node)
(error "Alias ~a referenced before anchoring." (cdr ,place))))))
(glue-if-alias-rec-otherwise (place)
`(if (alias-p ,place)
(glue-alias ,place)
(rec ,place))))
(labels ((rec (node)
;; (format t "analyzing: ~a~%" node)
(if (consp node)
(cond ((property-node-p node) (progn (update-anchors-if-present node)
(rec (cdr (assoc :content node)))))
((mapping-node-p node) (iter (for cell in (cdr node))
;; (format t "analyzing cell: ~a~%" cell)
(glue-if-alias-rec-otherwise (car cell))
(glue-if-alias-rec-otherwise (cdr cell))))
(t (iter (for seq-entry on node)
(glue-if-alias-rec-otherwise (car seq-entry))))))))
(rec representation-tree)
representation-tree)))))
| 1,905 | Common Lisp | .lisp | 44 | 37.113636 | 102 | 0.634186 | mabragor/cl-yaclyaml | 14 | 3 | 8 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | cf5a40f6e413b8a1c0e37c6f575c867bcf00ca19bd0a5fb592b3032228c7a2ec | 7,988 | [
-1
] |
7,989 | constructing.lisp | mabragor_cl-yaclyaml/constructing.lisp | ;;;; This file is one of components of CL-YACLYAML system, licenced under GPL, see COPYING for details
(in-package #:cl-yaclyaml)
(defun construct (representation-graph &key (schema :core))
(let ((visited-nodes (make-hash-table :test #'eq))
(converted-nodes (make-hash-table :test #'eq))
(initialization-callbacks (make-hash-table :test #'eq)))
(let ((schema (if (symbolp schema)
(gethash schema schemas)
schema)))
(with-schema schema
(%depth-first-traverse (list representation-graph))))
(gethash representation-graph converted-nodes)))
(defun yaml-load (string &key (schema :core))
(iter (for (document content) in (ncompose-representation-graph (yaclyaml-parse 'l-yaml-stream string)))
(collect `(:document ,(construct content :schema schema)))))
(defun yaml-simple-load (string &key (schema :core))
(let ((result (yaml-load string :schema schema)))
(if (equal (length result) 1)
(cadar result)
(error "Simple form assumed, but multiple documents found in the input."))))
(define-condition yaml-load-file-error (simple-error)
((message :initarg :message :reader yaml-load-file-error-message)))
(defun yaml-load-file (path &key (schema :core) (size-limit 4096) (on-size-exceed :error)
(simple t))
(when (probe-file path)
(let ((file-length (with-open-file (stream path :element-type '(unsigned-byte 8))
(file-length stream))))
(if (< size-limit file-length)
(cond
((eq :error on-size-exceed)
(error 'yaml-load-file-error :message "Size of file exceeds the limit set in SIZE-LIMIT"))
((eq :warn on-size-exceed)
(warn "Size of file exceeds the limit set in SIZE-LIMIT, ignoring config"))
((eq nil on-size-exceed) nil))
(with-open-file (stream path)
(let ((seq (make-string file-length)))
(read-sequence seq stream)
(if simple
(yaml-simple-load seq :schema schema)
(yaml-load seq :schema schema))))))))
(defmacro define-yaml-config (reader-name (path var
&key schema size-limit (on-size-exceed :warn))
&rest variable-specs)
(multiple-value-bind (decls var-names field-names)
(iter (for spec in variable-specs)
(if (atom (car spec))
(progn (collect spec into declarations)
(collect (car spec) into var-names)
(collect (string-trim '(#\* #\+) (string-downcase (car spec))) into field-names))
(progn (collect `(,(caar spec) ,@(cdr spec)) into declarations)
(collect (caar spec) into var-names)
(collect (cadar spec) into field-names)))
(finally (return (values declarations var-names field-names))))
`(progn ,@(mapcar (lambda (x)
`(defvar ,@x))
decls)
(defvar ,var nil)
(defun ,reader-name ()
(setf ,var (yaml-load-file ,path
,@(if schema `(:schema ,schema))
,@(if size-limit `(:size-limit ,size-limit))
:on-size-exceed ,on-size-exceed))
,@(iter (for var-name in var-names)
(for field-name in field-names)
(collect `(setf ,var-name (gethash ,field-name ,var))))
,var))))
| 3,096 | Common Lisp | .lisp | 66 | 40.924242 | 106 | 0.655526 | mabragor/cl-yaclyaml | 14 | 3 | 8 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | dac2b94d40b20a7fd2d2dc015e7e9811aa5b386eae65d4a92c94daf23bdccc07 | 7,989 | [
-1
] |
7,990 | cl-yaclyaml.asd | mabragor_cl-yaclyaml/cl-yaclyaml.asd | ;;;; cl-yaclyaml.asd
(defpackage :cl-yaclyaml-system
(:use :cl :asdf))
(in-package cl-yaclyaml-system)
(defsystem #:cl-yaclyaml
:version "1.1"
:serial t
:description "Yet Another Common Lisp YaML processor."
:author "Alexander Popolitov <[email protected]>"
:license "GPL"
:depends-on (#:iterate #:rutils #:cl-test-more #:cl-interpol
#:esrap-liquid #:alexandria
#:cl-ppcre #:parse-number)
:components ((:file "package")
;; (:file "esrap-parser-basics")
(:file "macro-utils")
(:file "parsing-macro")
(:file "parsing-macro-2")
(:file "parsing")
(:file "composing")
(:file "convert")
(:file "schema")
(:file "constructing")
(:file "representing")
(:file "serializing")
;; (:file "cl-yaclyaml-new")
;; (:file "cl-yaclyaml")
;; (:file "cl-yaclyaml-t")))
))
(defsystem :cl-yaclyaml-tests
:description "Tests for CL-YACLYAML."
:licence "GPL"
:depends-on (:cl-yaclyaml :fiveam :cl-interpol)
:components ((:file "tests")))
(defmethod perform ((op test-op) (sys (eql (find-system :cl-yaclyaml))))
(load-system :cl-yaclyaml-tests)
(funcall (intern "RUN-TESTS" :cl-yaclyaml-tests)))
| 1,335 | Common Lisp | .asd | 37 | 27.891892 | 72 | 0.568445 | mabragor/cl-yaclyaml | 14 | 3 | 8 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 484800882d4b4cf8c9a3eac732cba65284a108149bbe78d7328e10d46425b9d0 | 7,990 | [
-1
] |
8,020 | package.lisp | glv2_cl-monero-tools/monero-utils/package.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(defpackage :monero-utils
(:use :cl)
(:import-from :alexandria
#:define-constant)
(:import-from :babel
#:octets-to-string
#:string-to-octets)
(:import-from :cffi
#:mem-aref)
(:import-from :ironclad
#:integer-to-octets
#:octets-to-integer)
(:export
#:octet-vector
#:+base58-checksum-size+
#:base58-encoded-length #:base58-decoded-length
#:base58-encode #:base58-decode
#:integer->bytes #:bytes->integer
#:string->bytes #:bytes->string
#:utf-8-string->bytes #:bytes->utf-8-string
#:hex-string->bytes #:bytes->hex-string
#:join-bytes #:split-bytes
#:geta
#:read-float #:format-float
#:lisp-array->c-array #:c-array->lisp-array
#:json-name->lisp-name #:lisp-name->json-name
#:decode-json-from-string #:encode-json-to-string
#:get-unix-time))
| 1,088 | Common Lisp | .lisp | 32 | 28.15625 | 60 | 0.634725 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | d8b332885250240b3fd541506f85ac5addb66fc7402b1cdadf00373fe8607d58 | 8,020 | [
-1
] |
8,021 | utils.lisp | glv2_cl-monero-tools/monero-utils/utils.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-utils)
(deftype octet-vector (&optional size)
(if size
`(simple-array (unsigned-byte 8) (,size))
'(simple-array (unsigned-byte 8) (*))))
(defun read-varint (bytes &key (start 0))
"Read the variable size integer encoded in BYTES."
(let ((n 0)
(size 0))
(do ((l (length bytes))
(i start (1+ i))
(j 0 (+ j 7)))
((= i l))
(let ((b (aref bytes i)))
(incf n (ash (logand b #x7f) j))
(incf size)
(when (zerop (logand b #x80))
(return))))
(values n size)))
(defun write-varint (n)
"Return the variable size integer encoding of an integer N."
(let* ((size (max 1 (ceiling (integer-length n) 7)))
(bytes (make-array size :element-type '(unsigned-byte 8))))
(dotimes (i size bytes)
(setf (aref bytes i) (logior (logand n #x7f) (if (< i (- size 1)) #x80 0)))
(setf n (ash n -7)))))
(defun bytes->integer (bytes &key (start 0) end big-endian varint)
"Convert a sequence of BYTES to an integer."
(if varint
(read-varint bytes :start start)
(let ((end (or end (length bytes)))
(n (octets-to-integer bytes :start start :end end :big-endian big-endian)))
(values n (- end start)))))
(defun integer->bytes (n &key buffer (start 0) size big-endian varint)
"Convert an integer N to a sequence of SIZE bytes. If BUFFER is
supplied, put the bytes in it starting at index START."
(let ((bytes (if varint
(write-varint n)
(if size
(integer-to-octets n :big-endian big-endian :n-bits (* 8 size))
(integer-to-octets n :big-endian big-endian)))))
(if buffer
(replace buffer bytes :start1 start)
bytes)))
(defun string->bytes (string)
"Convert a STRING to a sequence of bytes."
(map 'octet-vector #'char-code string))
(defun bytes->string (byte-vector &key (start 0) end)
"Convert a sequence of bytes to a string."
(let ((data (subseq byte-vector start end)))
(map 'string #'code-char data)))
(defun utf-8-string->bytes (string)
"Convert a UTF-8 STRING to a sequence of bytes."
(string-to-octets string :encoding :utf-8))
(defun bytes->utf-8-string (byte-vector &key (start 0) end)
"Convert a sequence of bytes to a UTF-8 string."
(octets-to-string byte-vector :start start :end end :encoding :utf-8))
(defun hex-string->bytes (hex-string &key (start 0) end)
"Return the part of the HEX-STRING between START and END as a byte vector."
(let ((end (or end (length hex-string))))
(if (oddp (- end start))
(error "The size of the HEX-STRING must be a multiple of 2.")
(do ((index-hs start (+ index-hs 2))
(index-bv 0 (+ index-bv 1))
(byte-vector (make-array (/ (- end start) 2) :element-type '(unsigned-byte 8))))
((>= index-hs end) byte-vector)
(setf (aref byte-vector index-bv)
(parse-integer hex-string
:start index-hs
:end (+ index-hs 2)
:radix 16))))))
(defun bytes->hex-string (byte-vector &key (start 0) end)
"Return the part of the BYTE-VECTOR between START and END as a hex string."
(let ((end (or end (length byte-vector))))
(do ((index-bv start (+ index-bv 1))
(index-hs 0 (+ index-hs 2))
(hex-string (make-string (* (- end start) 2))))
((>= index-bv end) hex-string)
(let ((s (format nil "~(~2,'0x~)" (aref byte-vector index-bv))))
(replace hex-string s :start1 index-hs)))))
(defun join-bytes (byte-vectors)
"Return the concatenation of the BYTE-VECTORS."
(apply #'concatenate 'octet-vector byte-vectors))
(defun split-bytes (byte-vector size)
"Split the BYTE-VECTOR in chunks of SIZE bytes and return them in a list."
(loop for i from 0 below (length byte-vector) by size
collect (subseq byte-vector i (+ i size))))
(defun geta (alist key &key (test #'eql))
"Return the element of the ALIST specified by the KEY. GETA is
SETF-able, it is equivalent to (cdr (assoc key alist :test test))."
(cdr (assoc key alist :test test)))
(defun (setf geta) (new-value alist key &key (test #'eql))
(setf (cdr (assoc key alist :test test)) new-value))
(defun read-float (string)
"Read a decimal number from a STRING and return it as a rational
number."
(labels ((parse-digit (character)
(- (char-code character) (char-code #\0)))
(parse (numerator denominator point index length)
(if (= index length)
(values (/ numerator denominator) length)
(let ((c (char string index)))
(cond ((char<= #\0 c #\9)
(parse (+ (* numerator 10) (parse-digit c))
(if point (* denominator 10) denominator)
point
(1+ index)
length))
((and (not point)
(or (char= c #\.) (char= c #\,)))
(parse numerator denominator t (1+ index) length))
(t
(parse numerator denominator point index index)))))))
(let ((length (length string)))
(if (zerop length)
0
(case (char string 0)
((#\+) (parse 0 1 nil 1 length))
((#\-) (parse 0 -1 nil 1 length))
(t (parse 0 1 nil 0 length)))))))
(defun format-float (x &optional (precision 12))
"Return a string representing the number X with at most PRECISION
decimals."
(let ((d (expt 10 precision)))
(multiple-value-bind (q r) (truncate (round (* x d)) d)
(with-output-to-string (output)
(format output "~@[~a~]~d" (when (and (zerop q) (minusp r)) #\-) q)
(unless (or (zerop precision) (zerop r))
(write-string (string-right-trim '(#\0) (format nil ".~v,'0d" precision (abs r)))
output))))))
(defun lisp-array->c-array (lisp-array c-array)
"Copy bytes from a LISP-ARRAY to a FFI C-ARRAY."
(dotimes (i (length lisp-array) c-array)
(setf (mem-aref c-array :unsigned-char i) (aref lisp-array i))))
(defun c-array->lisp-array (c-array length &optional lisp-array)
"Copy LENGTH bytes from a FFI C-ARRAY to a LISP-ARRAY. If LISP-ARRAY
is not specfied, a new LISP-ARRAY is created."
(let ((lisp-array (or lisp-array (make-array length :element-type '(unsigned-byte 8)))))
(dotimes (i length lisp-array)
(setf (aref lisp-array i) (mem-aref c-array :unsigned-char i)))))
(defun json-name->lisp-name (name)
"Convert a JSON name to a Lisp name."
(map 'string
(lambda (c) (if (char= c #\_) #\- c))
(string-upcase name)))
(defun lisp-name->json-name (name)
"Convert a Lisp name to a JSON name."
(map 'string
(lambda (c) (if (char= c #\-) #\_ c))
(string-downcase name)))
(defun decode-json-from-string (json-string)
"Convert a JSON object to a Lisp object."
(let ((json:*json-identifier-name-to-lisp* #'json-name->lisp-name))
(json:decode-json-from-string json-string)))
(defun encode-json-to-string (object)
"Convert a Lisp object to a JSON object."
(let ((json:*lisp-identifier-name-to-json* #'lisp-name->json-name))
(json:encode-json-to-string object)))
(defun get-unix-time ()
"Get the number of seconds elapsed since epoch."
(- (get-universal-time)
#.(encode-universal-time 0 0 0 1 1 1970 0)))
| 7,745 | Common Lisp | .lisp | 166 | 38.596386 | 93 | 0.595708 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 29ff91ed6f38a563f3875990cdf4115af9376daf6842c20f0692e79f5eb7e314 | 8,021 | [
-1
] |
8,022 | base58.lisp | glv2_cl-monero-tools/monero-utils/base58.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-utils)
(define-constant +base58-alphabet+ "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
:test #'string=)
(defconstant +base58-alphabet-size+ 58)
(define-constant +base58-encoded-block-sizes+ #(0 2 3 5 6 7 9 10 11) :test #'equalp)
(defconstant +base58-full-block-size+ 8)
(defconstant +base58-full-encoded-block-size+ 11)
(defconstant +base58-checksum-size+ 4)
(defun base58-encoded-length (n)
"Return the length of the base58 encoding of N bytes."
(multiple-value-bind (full-block-count remaining-bytes)
(floor n +base58-full-block-size+)
(+ (* full-block-count +base58-full-encoded-block-size+)
(aref +base58-encoded-block-sizes+ remaining-bytes))))
(defun base58-decoded-length (n)
"Return the number of bytes encoded in a base58 string of
N characters."
(multiple-value-bind (full-encoded-block-count remaining-characters)
(floor n +base58-full-encoded-block-size+)
(+ (* full-encoded-block-count +base58-full-block-size+)
(or (position remaining-characters +base58-encoded-block-sizes+)
(error "Invalid size.")))))
(defun base58-encode (data)
"Return the base58 encoding of the DATA byte sequence."
(multiple-value-bind (full-block-count last-block-size)
(floor (length data) +base58-full-block-size+)
(flet ((encode-block (data start size)
(do* ((encoded-size (aref +base58-encoded-block-sizes+ size))
(encoded-string (make-string encoded-size
:initial-element (aref +base58-alphabet+ 0)))
(n (bytes->integer data :start start :end (+ start size) :big-endian t))
(r 0)
(i (1- encoded-size) (1- i)))
((zerop n) encoded-string)
(setf (values n r) (floor n +base58-alphabet-size+))
(setf (aref encoded-string i) (aref +base58-alphabet+ r)))))
(with-output-to-string (output-stream)
(dotimes (i full-block-count)
(write-string (encode-block data
(* i +base58-full-block-size+)
+base58-full-block-size+)
output-stream))
(when (plusp last-block-size)
(write-string (encode-block data
(* full-block-count +base58-full-block-size+)
last-block-size)
output-stream))))))
(defun base58-decode (string)
"Return the bytes encoded in a base58 STRING."
(multiple-value-bind (full-block-count last-block-size)
(floor (length string) +base58-full-encoded-block-size+)
(flet ((decode-block (data start size)
(do* ((decoded-size (position size +base58-encoded-block-sizes+))
(n 0)
(order 1 (* order +base58-alphabet-size+))
(i (1- size) (1- i)))
((minusp i)
(if (and (< decoded-size +base58-full-block-size+)
(<= (ash 1 (* 8 decoded-size)) n))
(error "Overflow.")
(integer->bytes n :size decoded-size :big-endian t)))
(let ((digit (position (aref data (+ start i)) +base58-alphabet+)))
(unless digit
(error "Invalid symbol."))
(let ((tmp (+ n (* order digit))))
(when (or (< tmp n) (plusp (ash tmp -64)))
(error "Overflow."))
(setf n tmp))))))
(let ((last-block-decoded-size (position last-block-size +base58-encoded-block-sizes+)))
(unless last-block-decoded-size
(error "Invalid size."))
(let ((data (make-array (+ (* full-block-count +base58-full-block-size+)
last-block-decoded-size)
:element-type '(unsigned-byte 8)
:initial-element 0)))
(dotimes (i full-block-count)
(replace data
(decode-block string
(* i +base58-full-encoded-block-size+)
+base58-full-encoded-block-size+)
:start1 (* i +base58-full-block-size+)))
(when (plusp last-block-size)
(replace data
(decode-block string
(* full-block-count +base58-full-encoded-block-size+)
last-block-size)
:start1 (* full-block-count +base58-full-block-size+)))
data)))))
| 4,876 | Common Lisp | .lisp | 92 | 38.565217 | 95 | 0.548576 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 2de327741a72105ca9a07562ab47fdc33c8004718dd6c472c848f3778bf33a4d | 8,022 | [
-1
] |
8,023 | rpc-payment-to-daemon.lisp | glv2_cl-monero-tools/examples/rpc-payment-to-daemon.lisp | ;;; Make a RPC request to a Monero node requiring payment.
;;; If we don't have credits on this node, generate some.
;;; Mining credits requires a running randomx-service daemon.
(asdf:load-system "ironclad")
(asdf:load-system "iterate")
(asdf:load-system "monero-rpc")
(asdf:load-system "monero-tools")
(asdf:load-system "monero-utils")
(use-package :iterate)
(use-package :monero-rpc)
(use-package :monero-daemon-rpc)
(use-package :monero-tools)
(use-package :monero-utils)
(defun need-credits-p (access-info)
(let ((credits (geta access-info :credits)))
(zerop credits)))
(defun maybe-reseed-randomx-service (seed)
(let* ((randomx-info (randomx-service-info))
(randomx-seed (hex-string->bytes (geta randomx-info :seed))))
(unless (equalp seed randomx-seed)
(randomx-service-reseed seed))))
(defun hash-templates (templates seed)
(maybe-reseed-randomx-service seed)
(randomx-service-hash-batch templates :seed seed))
(defun mine-credits (access-info)
(let* ((cookie (geta access-info :cookie))
(difficulty (geta access-info :diff))
(template (hex-string->bytes (geta access-info :hashing-blob)))
(seed (hex-string->bytes (geta access-info :seed-hash)))
(nonces (iter (repeat 256)
(collect (ironclad:random-data 4))))
(templates (mapcar (lambda (template nonce)
(modify-block-template template nonce))
(make-list 256 :initial-element template)
nonces))
(hashes (hash-templates templates seed))
(good-nonces (iter (for hash in hashes)
(for nonce in nonces)
(when (acceptable-hash-p hash difficulty)
(collect (bytes->integer nonce))))))
(iter (for nonce in good-nonces)
(rpc-access-submit-nonce nonce cookie))))
(defun maybe-mine-credits ()
(iter (for access-info next (rpc-access-info))
(while (need-credits-p access-info))
(mine-credits access-info)))
(let ((*randomx-service-host* "localhost")
(*randomx-service-port* 39093)
(*rpc-host* "some-monero-node")
(*rpc-port* 18081)
(*rpc-user* "rpc-user-if-necessary")
(*rpc-password* "rpc-password-if-necessary")
(*rpc-client-secret-key* (generate-secret-key)))
;; In this example, a new *rpc-client-secret-key* is generated every time,
;; as if each request was done by a different client.
;; You should instead generate a secret key once, save it, and reuse it for
;; every RPC request you make. This will allow you to use the credits you
;; still have on the Monero node instead of having to mine some for every
;; request.
(maybe-mine-credits)
(iter (for (key . value) in (get-info))
(format t "~(~a~): ~a~%" key value)))
| 2,864 | Common Lisp | .lisp | 62 | 38.887097 | 77 | 0.645669 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 13b605e54fd53848f002e8136234f2df2a58e82cfc51485b6b33a350a9a03c23 | 8,023 | [
-1
] |
8,024 | make-wallet.lisp | glv2_cl-monero-tools/examples/make-wallet.lisp | ;;; Generate a new wallet and print its address and seed.
(asdf:load-system "monero-tools")
(let* ((secret-key (monero-tools:generate-secret-key))
(seed (monero-tools:secret-key->mnemonic-seed secret-key :english))
(address (monero-tools:secret-spend-key->address secret-key)))
(format t "Wallet address: ~a~%Seed: ~a~%" address seed))
| 354 | Common Lisp | .lisp | 6 | 55 | 74 | 0.708092 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | cd3708d5dece3d420c2e3268a42e2b6b07e8662d4ba3c8bbb9a1b93eff53dbb5 | 8,024 | [
-1
] |
8,025 | package.lisp | glv2_cl-monero-tools/monero-p2p/package.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2018-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(defpackage :monero-p2p
(:use :cl :iterate :monero-utils)
(:import-from :alexandria
#:define-constant)
(:import-from :ironclad
#:random-bits)
(:import-from :monero-tools
#:+mainnet-genesis-hash+
#:deserialize-from-binary-storage
#:serialize-to-binary-storage)
(:import-from :usocket
#:socket-connect
#:socket-close
#:socket-stream)
(:export
#:network-id*
#:*p2p-port*
#:*peer-id*
#:close-connection
#:open-connection))
| 771 | Common Lisp | .lisp | 24 | 24.583333 | 60 | 0.6 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | d146ac26fbedb97ee9783585525b38f2f3e5f4be92295dcd120c08936dbe8da0 | 8,025 | [
-1
] |
8,026 | levin.lisp | glv2_cl-monero-tools/monero-p2p/levin.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2018-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-p2p)
(defun write-levin-packet (stream return-data-p command return-code flags &optional payload)
(write-sequence +levin-signature+ stream)
(write-sequence (integer->bytes (length payload) :size 8) stream)
(write-byte (if return-data-p 1 0) stream)
(write-sequence (integer->bytes command :size 4) stream)
(write-sequence (integer->bytes return-code :size 4) stream)
(write-sequence (integer->bytes flags :size 4) stream)
(write-sequence (integer->bytes +levin-protocol-version-1+ :size 4) stream)
(when payload
(write-sequence payload stream))
(finish-output stream))
(defun read-levin-packet (stream)
(let ((header (iter (repeat 33)
(for b next (read-byte stream nil nil))
(while b)
(collect b result-type 'octet-vector))))
(when (or (/= (length header) 33)
(mismatch header +levin-signature+ :end1 8))
(error "Bad packet header"))
(let ((payload-length (bytes->integer header :start 8 :end 16))
(return-data-p (plusp (aref header 16)))
(command (bytes->integer header :start 17 :end 21))
(return-code (bytes->integer header :start 21 :end 25))
(flags (bytes->integer header :start 25 :end 29))
(protocol-version (bytes->integer header :start 29 :end 33)))
(unless (and (<= payload-length +levin-max-packet-size+)
(= protocol-version +levin-protocol-version-1+))
(error "Bad packet"))
(let ((payload (iter (repeat payload-length)
(for b next (read-byte stream nil nil))
(while b)
(collect b result-type 'octet-vector))))
(values return-data-p command return-code flags payload)))))
(defun write-request (stream command payload)
(write-levin-packet stream t command 0 +levin-packet-request+ payload))
(defun write-response (stream command payload return-code)
(write-levin-packet stream nil command return-code +levin-packet-response+ payload))
| 2,268 | Common Lisp | .lisp | 42 | 45.690476 | 92 | 0.650293 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | b1611a65e06eac613a16fed4399b85778ba5a07e181501b6cb28d877c358e1ff | 8,026 | [
-1
] |
8,027 | p2p.lisp | glv2_cl-monero-tools/monero-p2p/p2p.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2018-2019 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-p2p)
(defparameter *network-id* +p2p-network-id-mainnet+)
(defparameter *peer-id* (random-bits 64))
(defparameter *p2p-port* 18080)
(defun get-unix-time ()
(- (get-universal-time) #.(encode-universal-time 0 0 0 1 1 1970 0)))
(defun make-handshake-request-payload (&key (network-id *network-id*) (peer-id *peer-id*) (p2p-port *p2p-port*))
(let* ((network-id (coerce network-id 'octet-vector))
(node-data (list (cons :local-time (cons (get-unix-time) '(unsigned-byte 64)))
(cons :my-port (cons p2p-port '(unsigned-byte 32)))
(cons :network-id (bytes->string network-id))
(cons :peer-id (cons peer-id '(unsigned-byte 64)))))
(payload-data (list (cons :cumulative-difficulty (cons 1 '(unsigned-byte 64)))
(cons :current-height (cons 1 '(unsigned-byte 64)))
(cons :top-id (bytes->string +mainnet-genesis-hash+))
(cons :top-version (cons 1 '(unsigned-byte 8)))))
(payload (list (cons :node-data node-data)
(cons :payload-data payload-data))))
(serialize-to-binary-storage payload)))
(defun make-timed-sync-payload ())
(defun make-ping-payload ())
(defun make-stat-info-request-payload ())
(defun make-network-state-request-payload ())
(defun make-peer-id-request-payload ())
(defun make-flags-request-payload ()
(let ((payload (list (cons :support-flags (cons +p2p-support-flags+ '(unsigned-byte 8))))))
(serialize-to-binary-storage payload)))
(defun close-connection (socket)
(socket-close socket))
(defun open-connection (host port)
(declare (optimize (debug 3)))
(let* ((socket (socket-connect host port
:protocol :stream
:element-type '(unsigned-byte 8)))
(stream (socket-stream socket)))
(clear-input stream)
(write-request stream +p2p-command-handshake+ (make-handshake-request-payload))
(multiple-value-bind (return-data-p command return-code flags payload)
(read-levin-packet stream)
(when (and return-data-p
(= command +p2p-command-request-support-flags+)
(= return-code +levin-ok+)
(= flags +levin-packet-request+))
(write-response stream +p2p-command-request-support-flags+ (make-flags-request-payload) 0))
(multiple-value-setq (return-data-p command return-code flags payload)
(read-levin-packet stream))
(unless (and (not return-data-p)
(= command +p2p-command-handshake+)
(= return-code 1)
(= flags +levin-packet-response+)
(plusp (length payload)))
(close-connection socket)
(error "Connection failed"))
(let ((payload (deserialize-from-binary-storage payload 0)))
(setf (geta payload :local-peerlist)
(string->bytes (geta payload :local-peerlist)))
(setf (geta (geta payload :node-data) :network-id)
(string->bytes (geta (geta payload :node-data) :network-id)))
(setf (geta (geta payload :payload-data) :top-id)
(string->bytes (geta (geta payload :payload-data) :top-id)))
(values socket payload)))))
(defun handle-request (socket command payload)
(let ((stream (socket-stream socket)))
(case command
((+p2p-command-handshake+)
;; TODO
)
((+p2p-command-timed-sync+)
;; TODO
)
((+p2p-command-ping+)
;; TODO
)
((+p2p-command-request-stat-info+)
;; TODO
)
((+p2p-command-request-network-state+)
;; TODO
)
((+p2p-command-request-peer-id+)
;; TODO
)
((+p2p-command-request-support-flags+)
(write-response stream
+p2p-command-request-support-flags+
(make-flags-request-payload)
+levin-ok+)))))
(defun handle-response (socket command payload)
(let ((stream (socket-stream socket)))
(case command
((+p2p-command-handshake+)
(setf (geta payload :local-peerlist)
(string->bytes (geta payload :local-peerlist)))
(setf (geta (geta payload :node-data) :network-id)
(string->bytes (geta (geta payload :node-data) :network-id)))
(setf (geta (geta payload :payload-data) :top-id)
(string->bytes (geta (geta payload :payload-data) :top-id)))
payload)
((+p2p-command-timed-sync+)
;; TODO
)
((+p2p-command-ping+)
;; TODO
)
((+p2p-command-request-stat-info+)
;; TODO
)
((+p2p-command-request-network-state+)
;; TODO
)
((+p2p-command-request-peer-id+)
;; TODO
)
((+p2p-command-request-support-flags+)
;; TODO
))))
(defun read-and-handle-packet (socket)
(let ((stream (socket-stream socket)))
(when (listen socket)
(multiple-value-bind (return-data-p command return-code flags payload)
(read-levin-packet stream)
;; TODO: Check return codes
(let ((payload (when (plusp (length payload))
(deserialize-from-binary-storage payload 0))))
(if (= flags +levin-packet-request+)
(handle-request stream command payload)
(handle-response stream command payload))))
;; Return list of payloads?
)))
(defun test-request ()
(multiple-value-bind (socket payload)
(open-connection "127.0.0.1" 18080)
(close-connection socket)
payload))
| 5,865 | Common Lisp | .lisp | 138 | 33.224638 | 112 | 0.592923 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 4d3085a5f589d7ef0121e1c53981e88133a7b707b2c8407198bc39049ee7044f | 8,027 | [
-1
] |
8,028 | constants.lisp | glv2_cl-monero-tools/monero-p2p/constants.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2018-2019 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-p2p)
;;; Levin protocol
(defconstant +levin-ok+ 0)
(define-constant +levin-signature+
(integer->bytes #x0101010101012101 :size 8)
:test #'equalp)
(defconstant +levin-packet-request+ 1)
(defconstant +levin-packet-response+ 2)
(defconstant +levin-max-packet-size+ 100000000)
(defconstant +levin-protocol-version-0+ 0)
(defconstant +levin-protocol-version-1+ 1)
(defconstant +levin-ok+ 0)
(defconstant +levin-error-connection+ (logand -1 #xffffffff))
(defconstant +levin-error-connection-not-found+ (logand -2 #xffffffff))
(defconstant +levin-error-connection-destroyed+ (logand -3 #xffffffff))
(defconstant +levin-error-connection-timedout+ (logand -4 #xffffffff))
(defconstant +levin-error-connection-no-duplex-protocol+ (logand -5 #xffffffff))
(defconstant +levin-error-connection-handler-not-defined+ (logand -6 #xffffffff))
(defconstant +levin-error-format+ (logand -7 #xffffffff))
;;; Peer-to-peer
(define-constant +p2p-network-id-mainnet+
#(18 48 241 113 97 4 65 97 23 49 0 130 22 161 161 16)
:test #'equalp)
(define-constant +p2p-network-id-testnet+
#(18 48 241 113 97 4 65 97 23 49 0 130 22 161 161 17)
:test #'equalp)
(define-constant +p2p-network-id-stagenet+
#(18 48 241 113 97 4 65 97 23 49 0 130 22 161 161 18)
:test #'equalp)
(defconstant +p2p-support-flag-fluffy-blocks+ 1)
(defconstant +p2p-support-flags+ (logior +p2p-support-flag-fluffy-blocks+))
(defconstant +p2p-command-handshake+ 1001)
(defconstant +p2p-command-timed-sync+ 1002)
(defconstant +p2p-command-ping+ 1003)
(defconstant +p2p-command-request-stat-info+ 1004)
(defconstant +p2p-command-request-network-state+ 1005)
(defconstant +p2p-command-request-peer-id+ 1006)
(defconstant +p2p-command-request-support-flags+ 1007)
;;; Seed nodes
(define-constant +mainnet-seed-nodes+
'(("5.9.100.248" 18080)
("107.152.130.98" 18080)
("161.67.132.39" 18080)
("163.172.182.165" 18080)
("195.154.123.123" 18080)
("198.74.231.92" 18080)
("212.83.172.165" 18080)
("212.83.175.67" 18080))
:test #'equalp)
(define-constant +stagenet-seed-nodes+
'(("162.210.173.150" 38080)
("162.210.173.151" 38080))
:test #'equalp)
(define-constant +testnet-seed-nodes+
'(("5.9.100.248" 28080)
("163.172.182.165" 28080)
("195.154.123.123" 28080)
("212.83.172.165" 28080)
("212.83.175.67" 28080))
:test #'equalp)
| 2,596 | Common Lisp | .lisp | 64 | 37.609375 | 81 | 0.714399 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 969cae1b1918db7e40fb5422abc41d2d8345c036e190ef9774c2617674280d97 | 8,028 | [
-1
] |
8,029 | wallet.lisp | glv2_cl-monero-tools/monero-rpc/wallet.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2019 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-wallet-rpc)
;;; Specs in https://getmonero.org/resources/developer-guides/wallet-rpc.html
;;; HTTP JSON RPCs
(defjsonrpc add-address-book ("add_address_book" address &key payment-id description)
"Add an entry to the address book."
(append (list (cons "address" address))
(when payment-id
(list (cons "payment_id" payment-id)))
(when description
(list (cons "description" description)))))
(defjsonrpc auto-refresh ("auto_refresh" &key (enable t) period)
"Configure wallet auto refresh."
(append (list (cons "enable" (when enable t)))
(when period
(list (cons "period" period)))
(list (cons "unused" 0))))
(defjsonrpc change-wallet-password ("change_wallet_password" &key old-password new-password)
"Change a wallet password."
(append (when old-password
(list (cons "old_password" old-password)))
(when new-password
(list (cons "new_password" new-password)))))
(defjsonrpc check-reserve-proof ("check_reserve_proof" address signature &key message)
"Proves a wallet as a disposable reserve using a signature."
(append (list (cons "address" address)
(cons "signature" signature))
(when message
(list (cons "message" message)))))
(defjsonrpc check-spend-proof ("check_spend_proof" transaction-id signature &key message)
"Prove a spend using a signature."
(append (list (cons "txid" transaction-id)
(cons "signature" signature))
(when message
(list (cons "message" message)))))
(defjsonrpc check-tx-key ("check_tx_key" transaction-id transaction-secret-key address)
"Check a transaction in the blockchain with its secret key."
(list (cons "txid" transaction-id)
(cons "tx_key" transaction-secret-key)
(cons "address" address)))
(defjsonrpc check-tx-proof ("check_tx_proof" transaction-id address signature &key message)
"Prove a transaction by checking its signature."
(append (list (cons "txid" transaction-id)
(cons "address" address)
(cons "signature" signature))
(when message
(list (cons "message" message)))))
(defjsonrpc close-wallet ("close_wallet" &key (autosave-current t))
"Close the current wallet."
(list (cons "autosave_current" (when autosave-current t))
(cons "unused" 0)))
(defjsonrpc create-account ("create_account" &key label)
"Create a new account."
(when label
(list (cons "label" label))))
(defjsonrpc create-address ("create_address" account-index &key label)
"Create a new address for an account."
(append (list (cons "account_index" account-index))
(when label
(list (cons "label" label)))))
(defjsonrpc create-wallet ("create_wallet" filename language &key password)
"Create a new wallet."
(append (list (cons "filename" filename)
(cons "language" language))
(when password
(list (cons "password" password)))))
(defjsonrpc delete-address-book ("delete_address_book" index)
"Delete an entry from the address book."
(list (cons "index" index)))
(defjsonrpc describe-transfer ("describe_transfer" &key unsigned-transaction-set multisig-transaction-set)
"Describe the transfers encoded in a string in hex format."
(append (when unsigned-transaction-set
(list (cons "unsigned_txset" unsigned-transaction-set)))
(when multisig-transaction-set
(list (cons "multisig_txset" multisig-transaction-set)))))
(defjsonrpc exchange-multisig-keys ("exchange_multisig_keys" multisig-info password)
"Exchange multisig keys."
(list (cons "multisig_info" multisig-info)
(cons "password" password)))
(defjsonrpc export-key-images ("export_key_images" &key all)
"Export a signed set of key images."
(when all
(list (cons "all" t))))
(defjsonrpc export-multisig-info ("export_multisig_info")
"Export multisig info for other participants.")
(defjsonrpc export-outputs ("export_outputs" &key all)
"Export all outputs in hex format."
(when all
(list (cons "all" t))))
(defjsonrpc finalize-multisig ("finalize_multisig" multisig-info password)
"Turn this wallet into a multisig wallet, extra step for M/N wallets."
(list (cons "multisig_info" (coerce multisig-info 'vector))
(cons "password" password)))
(defjsonrpc generate-from-keys ("generate_from_keys" filename address secret-spend-key secret-view-key password &key restore-height (autosave-current t))
"Generate a wallet from its secret keys."
(append (list (cons "filename" filename)
(cons "address" address)
(cons "spendkey" secret-spend-key)
(cons "viewkey" secret-view-key)
(cons "password" password)
(cons "autosave_current" (when autosave-current t)))
(when restore-height
(list (cons "restore_height" restore-height)))))
(defjsonrpc get-account-tags ("get_account_tags")
"Get a list of user-defined account tags.")
(defjsonrpc get-accounts ("get_accounts" &key tag)
"Get all accounts for a wallet."
(when tag
(list (cons "tag" tag))))
(defjsonrpc get-address ("get_address" &key account-index address-indices)
"Return the wallet's addresses for an account."
(append (when account-index
(list (cons "account_index" account-index)))
(when address-indices
(list (cons "address_index" (coerce address-indices 'vector))))))
(defjsonrpc get-address-book ("get_address_book" &key entries)
"Retrieves entries from the address book."
(when entries
(list (cons "entries" (coerce entries 'vector)))))
(defjsonrpc get-address-index ("get_address_index" address)
"Get account and address indexes from a specific (sub)address."
(list (cons "address" address)))
(defjsonrpc get-attribute ("get_attribute" key)
"Get attribute value by name."
(list (cons "key" key)))
(defjsonrpc get-balance ("get_balance" &key account-index address-indices all-accounts)
"Return the wallet's balance."
(append (when account-index
(list (cons "account_index" account-index)))
(when address-indices
(list (cons "address_indices" (coerce address-indices 'vector))))
(when all-accounts
(list (cons "all_accounts" t)))))
(defjsonrpc get-bulk-payments ("get_bulk_payments" payment-ids min-block-height)
"Get a list of incoming payments."
(list (cons "payment_ids" (coerce payment-ids 'vector))
(cons "min_block_height" min-block-height)))
(defjsonrpc get-height ("get_height")
"Returns the wallet's current block height.")
(defjsonrpc get-languages ("get_languages")
"Get a list of available languages for your wallet's seed.")
(defjsonrpc get-payments ("get_payments" payment-id)
"Get a list of incoming payments."
(list (cons "payment_id" payment-id)))
(defjsonrpc get-reserve-proof ("get_reserve_proof" all &key account-index amount message)
"Generate a signature to prove of an available amount in a wallet."
(append (list (cons "all" all))
(when account-index
(list (cons "account_index" account-index)))
(when amount
(list (cons "amount" amount)))
(when account-index
(list (cons "message" message)))))
(defjsonrpc get-spend-proof ("get_spend_proof" transaction-id &key message)
"Generate a signature to prove a spend."
(append (list (cons "txid" transaction-id))
(when message
(list (cons "message" message)))))
(defjsonrpc get-transfer-by-txid ("get_transfer_by_txid" transaction-id &key account-index)
"Show information about a transfer."
(append (list (cons "txid" transaction-id))
(when account-index
(list (cons "account_index" account-index)))))
(defjsonrpc get-transfers ("get_transfers" &key incoming outgoing pending failed pool filter-by-height min-height max-height account-index subaddress-indices all-accounts)
"Returns a list of transfers."
(append (when incoming
(list (cons "in" t)))
(when outgoing
(list (cons "out" t)))
(when pending
(list (cons "pending" t)))
(when failed
(list (cons "failed" t)))
(when pool
(list (cons "pool" t)))
(when filter-by-height
(list (cons "filter_by_height" t)))
(when min-height
(list (cons "min_height" min-height)))
(when max-height
(list (cons "max_height" max-height)))
(when account-index
(list (cons "account_index" account-index)))
(when subaddress-indices
(list (cons "subaddr_indices" (coerce subaddress-indices 'vector))))
(when all-accounts
(list (cons "all_accounts" t)))))
(defjsonrpc get-tx-key ("get_tx_key" transaction-id)
"Get transaction secret key from transaction id."
(list (cons "txid" transaction-id)))
(defjsonrpc get-tx-notes ("get_tx_notes" transaction-ids)
"Get string notes for transactions."
(list (cons "txids" (coerce transaction-ids 'vector))))
(defjsonrpc get-tx-proof ("get_tx_proof" transaction-id address &key message)
"Get transaction signature to prove it."
(append (list (cons "txid" transaction-id)
(cons "address" address))
(when message
(list (cons "message" message)))))
(defjsonrpc get-version ("get_version")
"Get RPC version, where the major version number is the first 16 bits and the
minor version number is the last 16 bits.")
(defjsonrpc import-key-images ("import_key_images" signed-key-images &key offset)
"Import signed key images list and verify their spent status."
(append (list (cons "signed_key_images" (coerce signed-key-images 'vector)))
(when offset
(list (cons "offset" offset)))))
(defjsonrpc import-multisig-info ("import_multisig_info" multisig-info)
"Import multisig info from other participants."
(list (cons "info" multisig-info)))
(defjsonrpc import-outputs ("import_outputs" outputs-data-hex)
"Import outputs in hex format."
(list (cons "outputs_data_hex" outputs-data-hex)))
(defjsonrpc incoming-transfers ("incoming_transfers" transfer-type &key account-index subaddress-indices)
"Return a list of incoming transfers to the wallet."
(append (list (cons "transfer_type" transfer-type))
(when account-index
(list (cons "account_index" account-index)))
(when subaddress-indices
(list (cons "subaddr_indices" (coerce subaddress-indices 'vector))))))
(defjsonrpc is-multisig ("is_multisig")
"Check if a wallet is a multisig one.")
(defjsonrpc label-account ("label_account" account-index label)
"Label an account."
(list (cons "account_index" account-index)
(cons "label" label)))
(defjsonrpc label-address ("label_address" account-index address-index label)
"Label an address."
(list (cons "index" (list (cons "major" account-index)
(cons "minor" address-index)))
(cons "label" label)))
(defjsonrpc make-integrated-address ("make_integrated_address" &key standard-address payment-id)
"Make an integrated address from the wallet address and a payment id."
(append (when standard-address
(list (cons "standard_address" standard-address)))
(when payment-id
(list (cons "payment_id" payment-id)))))
(defjsonrpc make-multisig ("make_multisig" multisig-info threshold password)
"Make a wallet multisig by importing peers multisig string."
(list (cons "multisig_info" multisig-info)
(cons "threshold" threshold)
(cons "password" password)))
(defjsonrpc make-uri ("make_uri" address &key amount payment-id recipient-name description)
"Create a payment URI."
(append (list (cons "address" address))
(when amount
(list (cons "amount" amount)))
(when payment-id
(list (cons "payment_id" payment-id)))
(when recipient-name
(list (cons "recipient_name" recipient-name)))
(when description
(list (cons "tx_description" description)))))
(defjsonrpc open-wallet ("open_wallet" filename &key password (autosave-current t))
"Open a wallet."
(append (list (cons "filename" filename)
(cons "autosave_current" (when autosave-current t)))
(when password
(list (cons "password" password)))))
(defjsonrpc parse-uri ("parse_uri" uri)
"Parse a payment URI to get payment information."
(list (cons "uri" uri)))
(defjsonrpc prepare-multisig ("prepare_multisig")
"Prepare a wallet for multisig by generating a multisig string to share with
peers.")
(defjsonrpc query-key ("query_key" key-type)
"Return the spend or view private key."
(list (cons "key_type" key-type)))
(defjsonrpc refresh ("refresh" &key start-height)
"Refresh a wallet after openning."
(when start-height
(list (cons "start_height" start-height))))
(defjsonrpc relay-tx ("relay_tx" transaction-data-hex)
"Relay a transaction previously created with DO-NOT-RELAY."
(list (cons "hex" transaction-data-hex)))
(defjsonrpc rescan-blockchain ("rescan_blockchain" &key hard)
"Rescan blockchain from scratch."
(when hard
(list (cons "hard" t))))
(defjsonrpc rescan-spent ("rescan_spent")
"Rescan the blockchain for spent outputs.")
(defjsonrpc restore-deterministic-wallet ("restore_deterministic_wallet" filename seed language password &key seed-offset restore-height (autosave-current t))
"Generate a wallet from its seed."
(append (list (cons "filename" filename)
(cons "seed" seed)
(cons "language" language)
(cons "password" password)
(cons "autosave_current" (when autosave-current t)))
(when seed-offset
(list (cons "seed_offset" seed-offset)))
(when restore-height
(list (cons "restore_height" restore-height)))))
(defjsonrpc set-account-tag-description ("set_account_tag_description" tag description)
"Set description for an account tag."
(list (cons "tag" tag)
(cons "description" description)))
(defjsonrpc set-attribute ("set_attribute" key value)
"Set arbitrary attribute."
(list (cons "key" key)
(cons "value" value)))
(defjsonrpc set-daemon ("set_daemon" address &key trusted (ssl-support :autodetect) ssl-private-key-path ssl-certificate-path ssl-ca-file ssl-allowed-fingerprints ssl-allow-any-cert)
"Set which daemon to connect to."
(append (list (cons "address" address)
(cons "ssl_support" (ecase ssl-support
((:autodetect) "autodetect")
((:enabled t) "enabled")
((:disabled nil) "disabled"))))
(when trusted
(list (cons "trusted" t)))
(when ssl-private-key-path
(list (cons "ssl_private_key_path" ssl-private-key-path)))
(when ssl-certificate-path
(list (cons "ssl_certificate_path" ssl-certificate-path)))
(when ssl-ca-file
(list (cons "ssl_ca_file" ssl-ca-file)))
(when ssl-allowed-fingerprints
(list (cons "ssl_allowed_fingerprints" ssl-allowed-fingerprints)))
(when ssl-allow-any-cert
(list (cons "ssl_allow_any_cert" t)))))
(defjsonrpc set-log-categories ("set_log_categories" categories)
"Set the log categories."
(list (cons "categories" categories)))
(defjsonrpc set-log-level ("set_log_level" level)
"Set the log level."
(list (cons "level" level)))
(defjsonrpc set-tx-notes ("set_tx_notes" transaction-ids notes)
"Set arbitrary string notes for transactions."
(list (cons "txids" (coerce transaction-ids 'vector))
(cons "notes" (coerce notes 'vector))))
(defjsonrpc sign ("sign" string)
"Sign a string."
(list (cons "data" string)))
(defjsonrpc sign-multisig ("sign_multisig" transaction-data-hex)
"Sign a transaction in multisig."
(list (cons "tx_data_hex" transaction-data-hex)))
(defjsonrpc sign-transfer ("sign_transfer" unsigned-transaction-set &key export-raw get-transaction-keys)
"Sign a transaction created on a read-only wallet (in cold-signing process)."
(append (list (cons "unsigned_txset" unsigned-transaction-set))
(when export-raw
(list (cons "export_raw" t)))
(when get-transaction-keys
(list (cons "get_tx_keys" t)))))
(defjsonrpc split-integrated-address ("split_integrated_address" integrated-address)
"Retrieve the standard address and payment id corresponding to an integrated
address."
(list (cons "integrated_address" integrated-address)))
(defjsonrpc start-mining ("start_mining" thread-count background-mining ignore-battery)
"Start mining in the Monero daemon."
(list (cons "threads_count" thread-count)
(cons "do_background_mining" (when background-mining t))
(cons "ignore_battery" (when ignore-battery t))))
(defjsonrpc stop-mining ("stop_mining")
"Stop mining in the Monero daemon.")
(defjsonrpc stop-wallet ("stop_wallet")
"Stop the wallet, storing the current state.")
(defjsonrpc store ("store")
"Save the current state.")
(defjsonrpc submit-multisig ("submit_multisig" transaction-data-hex)
"Submit a signed multisig transaction."
(list (cons "tx_data_hex" transaction-data-hex)))
(defjsonrpc submit-transfer ("submit_transfer" transaction-data-hex)
"Submit a previously signed transaction on a read-only wallet (in cold-signing
process)."
(list (cons "tx_data_hex" transaction-data-hex)))
(defjsonrpc sweep-all ("sweep_all" address &key account-index subaddress-indices priority ring-size outputs unlock-time payment-id get-transaction-keys below-amount do-not-relay get-transaction-hex get-transaction-metadata)
"Send all unlocked balance to an address."
(append (list (cons "address" address))
(when account-index
(list (cons "account_index" account-index)))
(when subaddress-indices
(list (cons "subaddr_indices" (coerce subaddress-indices 'vector))))
(when priority
(list (cons "priority" priority)))
(when ring-size
(list (cons "ring_size" ring-size)))
(when outputs
(list (cons "outputs" outputs)))
(when unlock-time
(list (cons "unlock_time" unlock-time)))
(when payment-id
(list (cons "payment_id" payment-id)))
(when get-transaction-keys
(list (cons "get_tx_keys" t)))
(when below-amount
(list (cons "below_amount" below-amount)))
(when do-not-relay
(list (cons "do_not_relay" t)))
(when get-transaction-hex
(list (cons "get_tx_hex" t)))
(when get-transaction-metadata
(list (cons "get_tx_metadata" t)))))
(defjsonrpc sweep-dust ("sweep_dust" &key get-transaction-keys do-not-relay get-transaction-hex get-transaction-metadata)
"Send all dust outputs back to the wallet."
(append (when get-transaction-keys
(list (cons "get_tx_keys" t)))
(when do-not-relay
(list (cons "do_not_relay" t)))
(when get-transaction-hex
(list (cons "get_tx_hex" t)))
(when get-transaction-metadata
(list (cons "get_tx_metadata" t)))))
(defjsonrpc sweep-single ("sweep_single" address &key priority ring-size outputs unlock-time payment-id get-transaction-key key-image do-not-relay get-transaction-hex get-transaction-metadata)
"Send all of a specific unlocked output to an address."
(append (list (cons "address" address))
(when priority
(list (cons "priority" priority)))
(when ring-size
(list (cons "ring_size" ring-size)))
(when outputs
(list (cons "outputs" outputs)))
(when unlock-time
(list (cons "unlock_time" unlock-time)))
(when payment-id
(list (cons "payment_id" payment-id)))
(when get-transaction-key
(list (cons "get_tx_key" t)))
(when key-image
(list (cons "key_image" key-image)))
(when do-not-relay
(list (cons "do_not_relay" t)))
(when get-transaction-hex
(list (cons "get_tx_hex" t)))
(when get-transaction-metadata
(list (cons "get_tx_metadata" t)))))
(defjsonrpc tag-accounts ("tag_accounts" tag accounts)
"Apply a filtering tag to a list of accounts."
(list (cons "tag" tag)
(cons "accounts" (coerce accounts 'vector))))
(defjsonrpc transfer ("transfer" destinations &key account-index subaddress-indices priority ring-size unlock-time payment-id get-transaction-key do-not-relay get-transaction-hex get-transaction-metadata)
"Send monero to a number of recipients."
(append (list (cons "destinations" (coerce destinations 'vector)))
(when account-index
(list (cons "account_index" account-index)))
(when subaddress-indices
(list (cons "subaddr_indices" (coerce subaddress-indices 'vector))))
(when priority
(list (cons "priority" priority)))
(when ring-size
(list (cons "ring_size" ring-size)))
(when unlock-time
(list (cons "unlock_time" unlock-time)))
(when payment-id
(list (cons "payment_id" payment-id)))
(when get-transaction-key
(list (cons "get_tx_key" t)))
(when do-not-relay
(list (cons "do_not_relay" t)))
(when get-transaction-hex
(list (cons "get_tx_hex" t)))
(when get-transaction-metadata
(list (cons "get_tx_metadata" t)))))
(defjsonrpc transfer-split ("transfer_split" destinations &key account-index subaddress-indices priority ring-size unlock-time payment-id get-transaction-keys do-not-relay get-transaction-hex get-transaction-metadata)
"Like transfer, but can split into several transactions if necessary."
(append (list (cons "destinations" (coerce destinations 'vector)))
(when account-index
(list (cons "account_index" account-index)))
(when subaddress-indices
(list (cons "subaddr_indices" (coerce subaddress-indices 'vector))))
(when priority
(list (cons "priority" priority)))
(when ring-size
(list (cons "ring_size" ring-size)))
(when unlock-time
(list (cons "unlock_time" unlock-time)))
(when payment-id
(list (cons "payment_id" payment-id)))
(when get-transaction-keys
(list (cons "get_tx_keys" t)))
(when do-not-relay
(list (cons "do_not_relay" t)))
(when get-transaction-hex
(list (cons "get_tx_hex" t)))
(when get-transaction-metadata
(list (cons "get_tx_metadata" t)))))
(defjsonrpc untag-accounts ("untag_accounts" accounts)
"Remove filtering tag from a list of accounts."
(list (cons "accounts" (coerce accounts 'vector))))
(defjsonrpc validate-address ("validate_address" address &key any-net-type allow-openalias)
"Check if an address is valid."
(append (list (cons "address" address))
(when any-net-type
(list (cons "any_net_type" t)))
(when allow-openalias
(list (cons "allow_openalias" t)))))
(defjsonrpc verify ("verify" string address signature)
"Verify a signature on a string."
(list (cons "data" string)
(cons "address" address)
(cons "signature" signature)))
| 23,964 | Common Lisp | .lisp | 492 | 41.22561 | 223 | 0.660965 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 32cee8336378d3bfb7390758c3952d60de6386fd6bd86d3daa42441c85bd108f | 8,029 | [
-1
] |
8,030 | package.lisp | glv2_cl-monero-tools/monero-rpc/package.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2018-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(defpackage :monero-rpc
(:use :cl :monero-utils)
(:import-from :base64
#:usb8-array-to-base64-string)
(:import-from :ironclad
#:digest-sequence
#:random-data)
(:import-from :monero-tools
#:fast-hash
#:generate-secret-key
#:generate-signature
#:secret-key->public-key)
(:import-from :split-sequence
#:split-sequence)
(:export
#:*rpc-host* #:*rpc-port* #:*rpc-user* #:*rpc-password*
#:*rpc-client-secret-key*
#:parse-digest-authentication-challenge
#:compute-digest-authentication-response
#:generate-rpc-payment-signature
#:rpc #:json-rpc
#:defrpc #:defrawrpc #:defjsonrpc))
(defpackage :monero-daemon-rpc
(:use :cl :monero-rpc :monero-utils)
(:export
#:banned
#:flush-cache
#:flush-txpool
#:generateblocks
#:get-alternate-chain
#:get-bans
#:get-block
#:get-block-count
#:get-block-hash
#:get-block-header-by-hash
#:get-block-header-by-height
#:get-block-headers-range
#:get-block-template
#:get-coinbase-tx-sum
#:get-connections
#:get-fee-estimate
#:get-info
#:get-last-block-header
#:get-output-distribution
#:get-output-histogram
#:get-txpool-backlog
#:get-version
#:hard-fork-info
#:prune-blockchain
#:relay-tx
#:rpc-access-account
#:rpc-access-data
#:rpc-access-info
#:rpc-access-pay
#:rpc-access-submit-nonce
#:rpc-access-tracking
#:set-bans
#:submit-block
#:sync-info
#:get-alt-blocks-hashes
#:get-height
#:get-limit
#:get-net-stats
#:get-outs
#:get-peer-list
#:get-public-nodes
#:get-transaction-pool
#:get-transaction-pool-hashes
#:get-transaction-pool-stats
#:get-transactions
#:in-peers
#:is-key-image-spent
#:mining-status
#:out-peers
#:pop-blocks
#:save-bc
#:send-raw-transaction
#:set-bootstrap-daemon
#:set-limit
#:set-log-categories
#:set-log-hashrate
#:set-log-level
#:start-mining
#:start-save-graph
#:stop-daemon
#:stop-mining
#:stop-save-graph
#:update))
(defpackage :monero-wallet-rpc
(:use :cl :monero-rpc :monero-utils)
(:export
#:add-address-book
#:auto-refresh
#:change-wallet-password
#:check-reserve-proof
#:check-spend-proof
#:check-tx-key
#:check-tx-proof
#:close-wallet
#:create-account
#:create-address
#:create-wallet
#:delete-address-book
#:describe-transfer
#:exchange-multisig-keys
#:export-key-images
#:export-multisig-info
#:export-outputs
#:finalize-multisig
#:generate-from-keys
#:get-account-tags
#:get-accounts
#:get-address
#:get-address-book
#:get-address-index
#:get-attribute
#:get-balance
#:get-bulk-payments
#:get-height
#:get-languages
#:get-payments
#:get-reserve-proof
#:get-spend-proof
#:get-transfer-by-txid
#:get-transfers
#:get-tx-key
#:get-tx-notes
#:get-tx-proof
#:get-version
#:import-key-images
#:import-multisig-info
#:import-outputs
#:incoming_transfers
#:is-multisig
#:label-account
#:label-address
#:make-integrated-address
#:make-multisig
#:make-uri
#:open-wallet
#:parse-uri
#:prepare-multisig
#:query-key
#:refresh
#:relay-tx
#:rescan-blockchain
#:rescan-spent
#:restore-deterministic-wallet
#:set-account-tag-description
#:set-attribute
#:set-daemon
#:set-log-categories
#:set-log-level
#:set-tx-notes
#:sign
#:sign-multisig
#:sign-transfer
#:split-integrated-address
#:start-mining
#:stop-mining
#:stop-wallet
#:store
#:submit-multisig
#:submit-transfer
#:sweep-all
#:sweep-dust
#:sweep-single
#:tag-accounts
#:transfer
#:transfer-split
#:untag-accounts
#:validate-address
#:verify))
| 4,054 | Common Lisp | .lisp | 177 | 18.463277 | 60 | 0.65625 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 91054e10ee1f868d6939f815930e6fd9ffbe631ff763ad468014d933a80852a6 | 8,030 | [
-1
] |
8,031 | daemon.lisp | glv2_cl-monero-tools/monero-rpc/daemon.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-daemon-rpc)
;;; Specs in https://getmonero.org/resources/developer-guides/daemon-rpc.html
;;; HTTP JSON RPCs
(defjsonrpc banned ("banned" address)
"Check if an address is banned."
(list (cons "address" address)))
(defjsonrpc flush-cache ("flush_cache" &key bad-transactions)
"Flush the transaction cache."
(when bad-transactions
(list (cons "bad_txs" t))))
(defjsonrpc flush-txpool ("flush_txpool" &key transaction-ids)
"Flush transaction ids from transaction pool."
(when transaction-ids
(list (cons "txids" (coerce transaction-ids 'vector)))))
(defjsonrpc generateblocks ("generateblocks" amount-of-blocks wallet-address previous-block &key starting-nonce)
"Generate blocks."
(append (list (cons "amount_of_blocks" amount-of-blocks)
(cons "wallet_address" wallet-address)
(cons "prev_block" previous-block))
(when starting-nonce
(list (cons "starting_nonce" starting-nonce)))))
(defjsonrpc get-alternate-chains ("get_alternate_chains")
"Get alternative chains seen by the node.")
(defjsonrpc get-bans ("get_bans")
"Get list of banned IPs.")
(defjsonrpc get-block ("get_block" block-id &key fill-pow-hash)
"Get full block information. BLOCK-ID can be a block height or hash."
(append (list (cons (etypecase block-id
(integer "height")
(string "hash"))
block-id))
(when fill-pow-hash
(list (cons "fill_pow_hash" fill-pow-hash)))))
(defjsonrpc get-block-count ("get_block_count")
"Look up how many blocks are in the longest chain known to the node.")
(defjsonrpc get-block-hash ("on_get_block_hash" block-height)
"Look up a block's hash by its height."
(vector block-height))
(defjsonrpc get-block-header-by-hash ("get_block_header_by_hash" block-hash &key fill-pow-hash)
"Look up a block's header by its hash."
(append (list (cons "hash" block-hash))
(when fill-pow-hash
(list (cons "fill_pow_hash" fill-pow-hash)))))
(defjsonrpc get-block-header-by-height ("get_block_header_by_height" block-height &key fill-pow-hash)
"Look up a block's header by its height."
(append (list (cons "height" block-height))
(when fill-pow-hash
(list (cons "fill_pow_hash" fill-pow-hash)))))
(defjsonrpc get-block-headers-range ("get_block_headers_range" start-height end-height &key fill-pow-hash)
"Look up headers of a range of blocks."
(append (list (cons "start_height" start-height)
(cons "end_height" end-height))
(when fill-pow-hash
(list (cons "fill_pow_hash" fill-pow-hash)))))
(defjsonrpc get-block-template ("get_block_template" address reserve-size &key previous-block)
"Get a block template on which mining can be done."
(append (list (cons "wallet_address" address)
(cons "reserve_size" reserve-size))
(when previous-block
(list (cons "prev_block" previous-block)))))
(defjsonrpc get-coinbase-tx-sum ("get_coinbase_tx_sum" start-height block-count)
"Get the amount of money emitted and fees in the BLOCK-COUNT blocks starting
at START-HEIGHT."
(list (cons "height" start-height)
(cons "count" block-count)))
(defjsonrpc get-connections ("get_connections")
"Retrieve information about incoming and outgoing connections to your node.")
(defjsonrpc get-fee-estimate ("get_fee_estimate" &key grace-blocks)
"Gives an estimation on fees per kB."
(when grace-blocks
(list (cons "grace_blocks" grace-blocks))))
(defjsonrpc get-info ("get_info")
"Retrieve general information about the state of your node and the network.")
(defjsonrpc get-last-block-header ("get_last_block_header" &key fill-pow-hash)
"Look up the block header of the most recent block."
(when fill-pow-hash
(list (cons "fill_pow_hash" fill-pow-hash))))
(defjsonrpc get-output-distribution ("get_output_distribution" amounts &key cumulative start-height end-height binary compress)
"Get output distribution."
(append (list (cons "amounts" (coerce amounts 'vector)))
(when cumulative
(list (cons "cumulative" t)))
(when start-height
(list (cons "from_height" start-height)))
(when end-height
(list (cons "to_height" end-height)))
(when binary
(list (cons "binary" t)))
(when compress
(list (cons "compress" t)))))
(defjsonrpc get-output-histogram ("get_output_histogram" amounts &key min-count max-count unlocked recent-cutoff)
"Get a histogram of output amounts."
(append (list (cons "amounts" (coerce amounts 'vector)))
(when min-count
(list (cons "min_count" min-count)))
(when max-count
(list (cons "max_count" max-count)))
(when unlocked
(list (cons "unlocked" unlocked)))
(when recent-cutoff
(list (cons "recent_cutoff" recent-cutoff)))))
(defjsonrpc get-txpool-backlog ("get_txpool_backlog")
"Get all transaction pool backlog.")
(defjsonrpc get-version ("get_version")
"Get the node current version.")
(defjsonrpc hard-fork-info ("hard_fork_info" &key version)
"Look up information regarding hard fork voting and readiness."
(when version
(list (cons "version" version))))
(defjsonrpc prune-blockchain ("prune_blockchain" &key check)
"Prune the blockchain."
(when check
(list (cons "check" t))))
(defjsonrpc relay-tx ("relay_tx" transaction-ids)
"Relay a list of transaction IDs."
(list (cons "txids" (coerce transaction-ids 'vector))))
(defjsonrpc rpc-access-account ("rpc_access_account" client &key (delta-balance 0))
"Get RPC access account info."
(list (cons "client" client)
(cons "delta_balance" delta-balance)))
(defjsonrpc rpc-access-data ("rpc_access_data")
"Get RPC access data.")
(defjsonrpc rpc-access-info ("rpc_access_info")
"Get access info for the RPC payment system.")
(defjsonrpc rpc-access-pay ("rpc_access_pay" paying-for payment)
"Pay for RPC access."
(list (cons "paying_for" paying-for)
(cons "payment" payment)))
(defjsonrpc rpc-access-submit-nonce ("rpc_access_submit_nonce" nonce cookie)
"Send a nonce to the RPC payment system."
(list (cons "nonce" nonce)
(cons "cookie" cookie)))
(defjsonrpc rpc-access-tracking ("rpc_access_tracking" &key clear)
"Get RPC access info."
(when clear
(list (cons "clear" t))))
(defjsonrpc set-bans ("set_bans" bans)
"Ban some nodes."
(list (cons "bans" (coerce bans 'vector))))
(defjsonrpc submit-block ("submit_block" block-data)
"Submit a mined block to the network."
(vector block-data))
(defjsonrpc sync-info ("sync_info")
"Get synchronisation information.")
;;; Other HTTP RPCs
(defrpc get-alt-blocks-hashes ("get_alt_blocks_hashes")
"Get the known blocks hashes which are not on the main chain.")
(defrpc get-height ("get_height")
"Get blockchain height.")
(defrpc get-limit ("get_limit")
"Get daemon bandwidth limits.")
(defrpc get-net-stats ("get_net_stats")
"Get network stastitics.")
(defrpc get-outs ("get_outs" outputs &key (get-transaction-id t))
"Get outputs."
(list (cons "outputs" (coerce outputs 'vector))
(cons "get_txid" (when get-transaction-id t))))
(defrpc get-peer-list ("get_peer_list")
"Get the known peers list.")
(defrpc get-public-nodes ("get_public_nodes" &key gray (white t))
"Get public nodes list."
(list (cons "gray" (when gray t))
(cons "white" (when white t))))
(defrawrpc get-transaction-pool ("get_transaction_pool")
"Show information about valid transactions seen by the node but not yet mined
into a block, as well as spent key image information for the txpool in the
node's memory."
nil
(lambda (result)
(let* ((result (let ((json:*use-strict-json-rules* nil))
(decode-json-from-string (bytes->string result))))
(transactions (geta result :transactions)))
(dolist (transaction transactions)
(setf (geta transaction :tx-blob) (string->bytes (geta transaction :tx-blob))))
result)))
(defrpc get-transaction-pool-hashes ("get_transaction_pool_hashes")
"Get hashes from transaction pool.")
(defrawrpc get-transaction-pool-stats ("get_transaction_pool_stats")
"Get the transaction pool statistics."
nil
(lambda (result)
(let* ((result (let ((json:*use-strict-json-rules* nil))
(decode-json-from-string (bytes->string result))))
(stats (geta result :pool-stats))
(histo (when stats
(geta stats :histo))))
(when histo
(setf (geta stats :histo) (string->bytes histo)))
result)))
(defrpc get-transactions ("get_transactions" transaction-ids &key decode-as-json prune split)
"Look up one or more transactions by hash."
(append (list (cons "txs_hashes" (coerce transaction-ids 'vector)))
(when decode-as-json
(list (cons "decode_as_json" t)))
(when prune
(list (cons "prune" t)))
(when split
(list (cons "split" t)))))
(defrpc in-peers ("in_peers" limit)
"Limit the number of incoming connections from peers."
(list (cons "in_peers" limit)))
(defrpc is-key-image-spent ("is_key_image_spent" key-images)
"Check if outputs have been spent using the key image associated with the output."
(list (cons "key_images" (coerce key-images 'vector))))
(defrpc mining-status ("mining_status")
"Get the mining status of the daemon.")
(defrpc out-peers ("out_peers" limit)
"Limit the number of outgoing connections to peers."
(list (cons "out_peers" limit)))
(defrpc pop-blocks ("pop_blocks" block-count)
"Remove blocks from the top of the blockchain."
(list (cons "nblocks" block-count)))
(defrpc save-bc ("save_bc")
"Save the blockchain.")
(defrpc send-raw-transaction ("send_raw_transaction" transaction &key do-not-relay (do-sanity-checks t))
"Broadcast a raw transaction to the network."
(append (list (cons "tx_as_hex" transaction))
(when do-not-relay
(list (cons "do_not_relay" t)))
(list (cons "do_sanity_checks" do-sanity-checks))))
(defrpc set-bootstrap-daemon ("set_bootstrap_daemon" address &key username password)
"Set the bootstrap daemon to use."
(append (list (cons "address" address))
(when username
(list (cons "username" username)))
(when password
(list (cons "password" password)))))
(defrpc set-limit ("set_limit" download-limit upload-limit)
"Set daemon bandwidth limits (kB/s)."
(list (cons "limit_down" download-limit)
(cons "limit_up" upload-limit)))
(defrpc set-log-categories ("set_log_categories" &key categories)
"Set the daemon log categories."
(when categories
(list (cons "categories" categories))))
(defrpc set-log-hash-rate ("set_log_hash_rate" visible)
"Set the log hash rate display mode."
(when visible
(list (cons "visible" (when visible t))
;; workaround to prevent (("visible" . nil)) from being encoded
;; as [["visible"]] instead of {"visible":false}
(cons "unused" 0))))
(defrpc set-log-level ("set_log_level" level)
"Set the daemon log level."
(list (cons "level" level)))
(defrpc start-mining ("start_mining" miner-address thread-count background-mining ignore-battery)
"Start mining in the daemon."
(list (cons "miner_address" miner-address)
(cons "threads_count" thread-count)
(cons "do_background_mining" (when background-mining t))
(cons "ignore_battery" (when ignore-battery t))))
(defrpc start-save-graph ("start_save_graph")
"Start saving graph.")
(defrpc stop-daemon ("stop_daemon")
"Send a command to the daemon to safely disconnect and shut down.")
(defrpc stop-mining ("stop_mining")
"Stop mining in the daemon.")
(defrpc stop-save-graph ("stop_save_graph")
"Stop saving graph.")
(defrpc update ("update" command &key path)
"Update the daemon."
(append (list (cons "command" command))
(when path
(list (cons "path" path)))))
| 12,336 | Common Lisp | .lisp | 268 | 40.537313 | 127 | 0.680003 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 95afd535a0d912cc379410f4ee51fb317daf96051ee4e58ed45258fee6d0db01 | 8,031 | [
-1
] |
8,032 | rpc.lisp | glv2_cl-monero-tools/monero-rpc/rpc.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-rpc)
(defparameter *rpc-host* "127.0.0.1"
"Location of the RPC server.")
(defparameter *rpc-port* 18081
"Port on which the RPC server expects connections.")
(defparameter *rpc-user* nil
"Username to use to connect to the RPC server.")
(defparameter *rpc-password* nil
"Password to use to connect to the RPC server.")
(defparameter *rpc-client-secret-key* nil
"Secret key used to identify a client on the RPC server.")
(defun parse-digest-authentication-challenge (challenge)
"Parse a 'Digest' authentication CHALLENGE received from a HTTP server."
(let* ((tmp (split-sequence #\space challenge))
(authentication-type (first tmp))
(authentication-info (split-sequence #\, (second tmp))))
(unless (string-equal authentication-type "digest")
(error "Bad digest authentication challenge."))
(do ((info authentication-info (cdr info))
(result '()))
((null info) result)
(let* ((index (position #\= (car info)))
(parameter (when index
(list (subseq (car info) 0 index)
(subseq (car info) (1+ index))))))
(when parameter
(let ((key (intern (string-upcase (first parameter)) :keyword))
(value (remove #\" (second parameter))))
(setf result (acons key value result))))))))
(defun compute-digest-authentication-response (user password qop algorithm realm method uri nonce)
"Build the reponse to a 'Digest' authentication challenge."
(unless (string-equal qop "auth")
(error "Unsupported quality of protection."))
(labels ((bytes->hex (bytes)
(string-downcase (bytes->hex-string bytes)))
(digest (string)
(let ((algo (intern (string-upcase algorithm) :keyword)))
(bytes->hex (digest-sequence algo (utf-8-string->bytes string))))))
(let* ((ha1 (digest (format nil "~a:~a:~a" user realm password)))
(ha2 (digest (format nil "~a:~a" method uri)))
(nc "00000001")
(cnonce (usb8-array-to-base64-string (random-data 16)))
(response (digest (format nil "~a:~a:~a:~a:~a:~a" ha1 nonce nc cnonce qop ha2))))
(concatenate 'string
"Digest username=\"" user "\""
", realm=\"" realm "\""
", nonce=\"" nonce "\""
", uri=\"" uri "\""
", cnonce=\"" cnonce "\""
", nc=" nc
", qop=" qop
", response=\"" response "\""
", algorithm=\"" algorithm "\""))))
(defun generate-rpc-payment-signature (secret-key)
"Make a signature of the current time with using a SECRET-KEY."
(let* ((public-key (secret-key->public-key secret-key))
(timestamp (format nil "~16,'0x" (* (get-unix-time) 1000000)))
(hash (fast-hash (string->bytes timestamp)))
(signature (generate-signature hash secret-key)))
(concatenate 'string
(bytes->hex-string public-key)
timestamp
(bytes->hex-string signature))))
(defun rpc (method &key raw parameters (rpc-host *rpc-host*) (rpc-port *rpc-port*) (rpc-user *rpc-user*) (rpc-password *rpc-password*))
"Send a METHOD RPC request to the server at RPC-HOST:RPC-PORT with optional
PARAMETERS."
(let* ((page (format nil "/~(~a~)" method))
(parameters (when parameters
(encode-json-to-string parameters)))
(server-uri (format nil "http://~a:~d~a" rpc-host rpc-port page))
(auth (handler-case (progn (dex:head server-uri) nil)
(dex:http-request-unauthorized (e)
(unless (and rpc-user rpc-password)
(error "USER and PASSWORD required."))
(let* ((response-headers (dex:response-headers e))
(www-authenticate (gethash "www-authenticate" response-headers))
(challenge (parse-digest-authentication-challenge www-authenticate))
(qop (geta challenge :qop))
(algorithm (geta challenge :algorithm))
(realm (geta challenge :realm))
(nonce (geta challenge :nonce)))
(compute-digest-authentication-response rpc-user
rpc-password
qop
algorithm
realm
"POST"
page
nonce)))
(t () nil))))
(multiple-value-bind (body status response-headers uri stream)
(dex:post server-uri
:headers (if auth
(list (cons "authorization" auth)
(cons "content-type" "application/json"))
(list (cons "content-type" "application/json")))
:content parameters
:force-binary raw)
(declare (ignore status response-headers uri stream))
(if raw body (decode-json-from-string body)))))
(defun json-rpc (method &key parameters (rpc-host *rpc-host*) (rpc-port *rpc-port*) (rpc-user *rpc-user*) (rpc-password *rpc-password*))
"Send a METHOD JSON RPC request to RPC-HOST:RPC-PORT with optional
PARAMETERS."
(let* ((request (list (cons :jsonrpc "2.0")
(cons :id (random 1000000))
(cons :method (string-downcase (string method)))
(cons :params parameters)))
(answer (rpc "json_rpc"
:parameters request
:rpc-host rpc-host
:rpc-port rpc-port
:rpc-user rpc-user
:rpc-password rpc-password))
(err (geta answer :error)))
(if err
(error (geta err :message))
(geta answer :result))))
(defmacro defhttprpc (type name (method &rest args) &body body)
(assert (<= (length body) 3))
(let* ((key-args-p (member '&key args))
(docstring (when (stringp (car body))
(pop body)))
(parameters (when body
(pop body)))
(postprocess (car body)))
`(defun ,name (,@args ,@(unless key-args-p (list '&key))
(rpc-host *rpc-host*) (rpc-port *rpc-port*)
(rpc-user *rpc-user*) (rpc-password *rpc-password*)
(rpc-client-secret-key (or *rpc-client-secret-key*
(generate-secret-key))))
,@(list docstring)
(let* ((client (generate-rpc-payment-signature rpc-client-secret-key))
(parameters (acons "client" client ,parameters))
(result (,(case type
((:json) 'json-rpc)
(t 'rpc))
,method
,@(cond
((eql type :raw) (list :raw t)))
:parameters parameters
:rpc-host rpc-host
:rpc-port rpc-port
:rpc-user rpc-user
:rpc-password rpc-password)))
,(if postprocess
`(funcall ,postprocess result)
`result)))))
;; def*rpc macros usage:
;;
;; (def*rpc my-rpc ("my_method" arg1 arg2 arg3 &key optarg1 optarg2)
;; "my docstring" ; optional
;; (make-parameters-form arg1 arg2 arg3 optarg1 optarg2) ; optional unless postprocess
;; (lambda (result) (process result))) ; optional postprocess
;;
;; (my-rpc arg1 arg2 arg3 :optarg2 123)
(defmacro defrpc (name (method &rest args) &body body)
`(defhttprpc :rpc ,name (,method ,@args) ,@body))
(defmacro defrawrpc (name (method &rest args) &body body)
`(defhttprpc :raw ,name (,method ,@args) ,@body))
(defmacro defjsonrpc (name (method &rest args) &body body)
`(defhttprpc :json ,name (,method ,@args) ,@body))
| 8,483 | Common Lisp | .lisp | 165 | 36.866667 | 136 | 0.531912 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | d144d8589d7f78bc94c95a4299071b94e7493b6ae8f1d69a674025d408301c78 | 8,032 | [
-1
] |
8,033 | wallet.lisp | glv2_cl-monero-tools/tests/wallet.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-tools-tests)
(def-suite wallet-tests
:description "Unit tests for wallet functions."
:in monero-tools-tests)
(in-suite wallet-tests)
#|
Info about wallet-1
-------------------
file: wallet-1.keys
password: 123456
mnemonic seed language: english
mnemonic seed: dedicated dubbed coexist having damp ember feline inquest september nobody alley binocular lopped moat agreed wayside gotten bays layout nail vixen imagine weird yahoo moat
address: 43HyW9SFLTmFzDLRgYmeLZ4m4SW7w3G8XfGxfjW79oh6DJdDdwybRJJJKGS3SWsoH5NVMBaXyzty5bv3QNRarqDw5iPfNJJ
secret spend key: f61b1df1b8bc17126ebd95587494fb128a39217dd468e6bea57f2263626c1306
public spend key: 2c124acc92d2bc5999156bae00f552167a396080cd4100e4d5107bb2d102cd49
secret view key: 777cd85ce14d5be04de46f348144e78fdccc79fb0599864f867cb02ce389450b
public view key: 8f5e31dbf970db6784eb5062aded5c80790f5e85667948d0bd7dd269c6722629
testnet: no
Info about wallet-2
-------------------
file: wallet-2.keys
password: bhunjivgy
mnemonic seed language: french
mnemonic seed: brave visuel version tango davantage baobab quinze essai peau tellement balcon brevet tasse ordinaire rhume lueur oreille version stock agonie salon scoop rouge seuil peau
address: 43oErH6q2FfVkVBXrkQt3yfYmmZN3iseWfwet7TyeXmRPPGFcVFffzpSp92tKSUGKF4yKNh5LRLLh8fEaor4Zx3ySdMJNm7
secret spend key: b50710fdc751efdd2602635a0e271d0af6744a2bf58ca15a138dd6ca5ad78d0a
public spend key: 3962d1d1e47c06abe2314ed2849c40e67651a449144a2fe8d21e1146653fd085
secret view key: 9197ed5871e7306e49f9d604dc3d9c64aa678bb0736b80f09158ab5ce9305e0c
public view key: d302c0849107819a5301b91e08928617bdadcf303b05122dca9adc24d80238e3
testnet: no
Info about 2/3 multisig wallets
-------------------------------
file: multisig-wallet-1.keys
password: 123456
mnemonic seed language: english
mnemonic seed: maze olympics madness digit antics heron daily mayor whole juggled bowling ulcers badge ecstatic needed noises zodiac going elite guys cement cider cistern cycling going
address: 48PxjvS2nzN4PsTQmhYhcM5Eq5TFWeMhK9S1KQ53ykLkWAaGoHVLXDPNvLCAqV6h1FYQ9c5kQ8ds9AcUYXYx4JNFUm5JiBF
secret spend key: ddf53de98c2cde52a5daac71a7464dc4f46d7d54afad4259952ae3c97f663305
public spend key: b2bcadb323572b144b1242341a3d3a1957049df4a13fca32680b806a3d99a5ae
secret view key: 6f5631bfa0a7a4719cd2ddf3acf9ab26a93c88dc5560ebf8e426a544ccad8803
public view key: 5dd43c9a09e1be830c517dad4040f6bbb9174267550c543976d6ef8ad80d7cf6
blinded secret view key: 37086110d56edb0d244128eee6980255f427acca9b965fe4a8a26d17ff8be005
secret signer key: 2198d1a8f259eee41ef087eb48559edbd5841cce739709f79767adb3fbd25104
public signer key: eafbc2265dca6fca729f038d00a408f03624f039ea10a9be1ef3d19aaed4e856
multisig info: MultisigV1ACtQwqtBN6x74iS7stvtsWhqcLBXBvy71VCy1WVGE9UGgJdkYqo47wXLAyBkxpieFRA4GWgDAGtNh6BH5ZZenvRTGUVMMQKszEjAPnL2A5hyxVTymHoMaPE2nj82hnS2evNaSXj4yh8LKfa2o1zE9QMaNp2PtGvm6TUdwjb2bzjoBrhg
multisig extra info: MultisigxV1B2HV6651uKBCHqqUYg3aQwaKrpm8Vdbu1ApYBeyxcEnSV163PF3KF4HjEegBM9Y36iQJtbd5W4BDJ1BhyGCuhE3AiDf6VpWP5gE4QcwTTjEbCTgS1xpWwhYs9gh6oJdTrFBPVbdRfcf9EC6XTrT4UwDtfNchktG4LErSCHxrq2tZtirCFED5B41YoxtcoVJjUoaFdWDk9DCW3BXXZUzqQZeLLriK
multisig keys: ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302
f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07
multisig public keys: a768f72c3d0c4be6fc82329c99d1d66b8b5a2103c8ffd4f9011a860da6e5ac71
f66d79e30d769593145edae7e2aa0ac8ebbe951a827ddab8ed4c9b9a593d185a
multisig secret signer key: a0e1217efc88057244e140eeea8d3279582bd540e9d895417e23d47869e29f09
multisig public signer key: 3beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47
multisig seed: 0200000003000000a0e1217efc88057244e140eeea8d3279582bd540e9d895417e23d47869e29f09aeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb93737da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b2d90d31aa9903d3e45b17fbc849b6c95e4d08c3694b721219f1a08208bd7af61ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c073beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb4974d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a4
file: multisig-wallet-2.keys
password: 123456
mnemonic seed language: english
mnemonic seed: hounded touchy august zodiac python sapling females fibula shelter fountain corrode value comb stunning claim auburn voyage winter business awkward gasp hydrogen veteran violin voyage
address: 46gdkg6bsesKKE4pSx8kKgDjb6TJ9L1DJPFZYtcRRsRzHveDSLoNzSjAdAA8Ro6KeT1W5zUbovUVJGFpR6ubqXW3BuFyKCB
secret spend key: 88a82e356a24ec0ec1dd497a3264c1c28741905781aecf051f89ec3dc962d101
public spend key: 858bc0c44c9b5c6d7e5de42c6fc9af4c221c3af2a8d8e18507c6278aefc11165
secret view key: 8bc2f1c91767c32404b5fc906122ee5a22efb8c5c8e229477850069fda334c04
public view key: 2fe5d377480d203988dcdd13a296ec02ff8861fd0fc0dd5b34de998485eb2c60
blinded secret view key: a8d18e7ce2e4de4c6213b9e883280ab0d6ee0c4640942151270125ffa71b500f
secret signer key: f4d31e959d1dfe34619da70dbecec62fb89c29125f094cc1fcc67fd0d6d60909
public signer key: 1892038bd30631aa5f0e056ae47f87b2ed9d72e32dc20b645ab0171d52884f42
multisig info: MultisigV1VEkbitipY51HQUH56z8Pu9cx6ATQD4Cvk7XPkwqkDbfU57N5FsBRiN5Gu9ikLqv44qgkAUxAmw739GAnaLS1MAzMa3kjv1m72PwfVM1z3JEeBpdSWRsSXHpEHbXwSiPywurujVYitznC8aRgqnHu7W1Zs8fbpirY1bFH4CqtBx4iedJe
multisig extra info: MultisigxV1dKNJHKg34Yja8Mef3fkswXAszjskHbs7PVAReAG74PMDV163PF3KF4HjEegBM9Y36iQJtbd5W4BDJ1BhyGCuhE3A1p1sHTeyeHGb4pu6x9ScKvAjuEzwgAe8D8hMyhWjQyQE1YJed5NXQWpji7S4cAHq53cEtkVjydF1ALHYzMs1F2gYd2whUWuFJf4ZPonVdg4hb1hc8k4u79WA1PpS9y37nco6
multisig keys: ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302
b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08
multisig public keys: a768f72c3d0c4be6fc82329c99d1d66b8b5a2103c8ffd4f9011a860da6e5ac71
04d8a58ac5eb2f33cbaac5faf350523d3a3acb77fa05092e2e02bef831993c7b
multisig secret signer key: 627716ec18a622171e639cdc8349be9e85c24a124f0ab301c763838b0db4400b
multisig public signer key: d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a4
multisig seed: 0200000003000000627716ec18a622171e639cdc8349be9e85c24a124f0ab301c763838b0db4400baeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb93737da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b2d90d31aa9903d3e45b17fbc849b6c95e4d08c3694b721219f1a08208bd7af61ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a4eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb49743beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47
file: multisig-wallet-3.keys
password: 123456
mnemonic seed language: english
mnemonic seed: shackles newt tadpoles gags pencil vowels revamp aided podcast niche foyer hitched cupcake damp mops taken agreed tumbling itinerary mops hospital excess elbow empty revamp
address: 45vbpu87oHYZjoKndmjGYrEKUnqqaP9qE9d4CYRKk7gzezD5gUqhh9s2om1rmWg1FYMkVdpvMk5hACozjD6Z3odP136DTtB
secret spend key: 02dea042ab01454d9ca369a454cb0613c6f2c35d9009c3daf959b3d839570b02
public spend key: 7183159c33b0d7c3ba278d37ed48634fa0722e5a5a580d338ba0bb1029aeffe3
secret view key: 64bf5bdbbb82c6d084b1ae8eff4b0710b372e53465c0c9d90db1bbc8dcbb9c06
public view key: 1b051d83f428820acc69d0534f7ff37c0e34f60cf7cb81469be46efc7f9c2600
blinded secret view key: 8b9bc92fc3849735654c8e6be3fea89db96b8724b90cec21d0fea2485b062506
secret signer key: aede2ddc27f47417d81832ae44f917c9d33ad3ae5f4cadb2a9b8e8c55e7c9502
public signer key: 49022814b64909a8c20078877610d80add01fbf6ef9f55fc7c93b2b2f9029122
multisig info: MultisigV1QMNubqf2Zp8HwjCr8qVT32Y1onHiaatCYbxWam4oCdm7DDGqwJDdmzFZT4Xim7nEvDdy422avHWMqMqZ3MH8BCGqGbg2f3xo8YoDvX4kEFYyb9Jd6H5z7DGToJBnLrtpZoqfXzryyUwpGzWEZ2qkVtKipgQ94RWETo1z6QDEtu8SDVN3
multisig extra info: MultisigxV1gwsG1Ys15VfFQRNUd1LeNfYXzC9XtmTvJLcpxPzhRBF1iDf6VpWP5gE4QcwTTjEbCTgS1xpWwhYs9gh6oJdTrFBP1p1sHTeyeHGb4pu6x9ScKvAjuEzwgAe8D8hMyhWjQyQEb9VH6YrT69raSwU7fjnQuyMD5vPeKn9Hqe4VEGz2qdaNWvMx3cXuzqF7xNfbSAZG4JVqesLiFNRc52hV1pDt5JML
multisig keys: f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07
b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08
multisig public keys: f66d79e30d769593145edae7e2aa0ac8ebbe951a827ddab8ed4c9b9a593d185a
04d8a58ac5eb2f33cbaac5faf350523d3a3acb77fa05092e2e02bef831993c7b
multisig secret signer key: a80d07f8df835312b683fc491b5042a42db171e26e4453ba0ad8b2142453ba0f
multisig public signer key: eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb4974
multisig seed: 0200000003000000a80d07f8df835312b683fc491b5042a42db171e26e4453ba0ad8b2142453ba0faeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb93737da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b2d90d31aa9903d3e45b17fbc849b6c95e4d08c3694b721219f1a08208bd7af61f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb4974d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a43beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47
multisig address: 48F6EyTxrPmbxN15svcgLZJYJUTZ8qvfHWv7aoJGfDBYLGNWLsAjmVNBR7tQgVHd7ZS5A9V43JM3v6dAtpt19nTQC1RxFqX
multisig public spend key: aeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb9373
multisig secret view key: 7da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b
multisig public view key: 2d90d31aa9903d3e45b17fbc849b6c95e4d08c3694b721219f1a08208bd7af61
Info about 2/2 multisig wallets
-------------------------------
file: multisig-wallet-4.keys
password: 123456
mnemonic seed language: english
mnemonic seed: space android leopard building goldfish because dwelt aloof victim tutor merger viking iris hotel also together relic roped loyal exquisite audio awakened asked blender merger
address: 49djRyZhy4m2fyo3JBZU8jQ1dtEN9qHgcUDk8dpnxxkd82mvFPhJqjQ7UcuBEQiRYyS42NtwYD1MieYUyEMA3Z1nUqs9C5t
secret spend key: 16f065708dc3f9bf6095ade6867dbd68da2968a668e67d05f14b9dcd2986f90b
public spend key: d363fc369042fa09ff1ee3215de34c8992d5332e90da19a2bc6e884a26f8e62a
secret view key: 5e41a1e789066174019f1c82fab08cb7b7ca96965d972849c06258b79224b704
public view key: 087e269921c94326b7f66c76ef721695c6e4486cbcb181e07426e6d4d3914df6
blinded secret view key: f78e43b21da28affdaabcd00189c7f6a19458b2a695fe90b670ba8197c628b08
multisig secret signer key: 367c0246bc866ac8e559cecd9f7890a9d96ec790b336347c5f56f99c00796900
multisig public signer key: ce57400743c11f83b09b94ac3be9b23f5b9b756a3472d0fdf129f12475a8ebb8
multisig info: MultisigV1iQbqPBYtGQ6daPFHgoANND5EAfofFeaivJEfuRpabfDybWmLZJ5cKU6WYKLxzEaPwLGKhuDaB6qUQhLbJ8yTypx7FXx47Zc4uwgaouaxniTnbuaY7rv9mCAA9KVy7Q7UPiarSTn2exrQPti3TPSPmwQu89MTCfkpxGq7pR6bA4KwDZpe
multisig seed: 0200000002000000367c0246bc866ac8e559cecd9f7890a9d96ec790b336347c5f56f99c007969002297d23c0c69d8cf76464277ceb31e6b0777750308ecfbc49667fd2ebea67bf0bda1410fbb9ad7690e8eddc98d6d77c326cfb6766ad126df4b97a076979a6f02deba7c0440e2e7f7da4fa77470e98f339089d3fe0c609209b4a388266451d1c9367c0246bc866ac8e559cecd9f7890a9d96ec790b336347c5f56f99c00796900156d6f3561c4ff39deda45d6ef841246a8ef9a4836e4fd103d7fa4bb7feb7cedce57400743c11f83b09b94ac3be9b23f5b9b756a3472d0fdf129f12475a8ebb8
file: multisig-wallet-5.keys
password: 123456
mnemonic seed language: english
mnemonic seed: spout fierce thaw vials bowling hiding lion left bygones august renting woken foggy prying haystack daytime cogs warped biscuit knife austere altitude dubbed eldest altitude
address: 4A8PXSb4gttCLcbL3d4MdoSSsMkfy9Z5JAwcgrLo67SBgTQ9rWk6LTiAmbZYBfQBDPYj7Zu5LkKTic788qWZqWVHKkoeqjx
secret spend key: 6919108e1aa3f4402c670aa762e4554400fc3db0c26c12cc31f9e89b1b93a506
public spend key: e06db8373af2f543c955f86af157de9821b84ef65566b93b6fec5799a119d4eb
secret view key: 0724632717bc4d9195c7d0b8c19565adaa88b8e8d62df899559eeef1d74d3e0c
public view key: e31113ef9b84913a67870564e5d82ebdad8ad6587860fdd1e1ea925fdfa49ca6
blinded secret view key: b3e6f3b9b75b5fc2097f076c54cbd66d0d8a2b4c01723dd3e48bf85c1b38e409
multisig secret signer key: 5b84e7b1469852fe1bf19f6057cfd72f22a84381d259f522d7f573112517750c
multisig public signer key: 156d6f3561c4ff39deda45d6ef841246a8ef9a4836e4fd103d7fa4bb7feb7ced
multisig info: MultisigV1X6H2P2QJ8Y92b8FrCQ2Nk43GMS47gHy5UfEC1eEBm9Jp4asf3n68DeYeGx5d4pnk77VFte1eXtwTVBHcaudJktXnfTxL4mA4G3baHFn9ncRvQSXACjyyLriJgbtWeai6kdoiRxx7F6p42AqjSJLoaExLhrRwTjbKrDkdejLj2s4SyadG
multisig seed: 02000000020000005b84e7b1469852fe1bf19f6057cfd72f22a84381d259f522d7f573112517750c2297d23c0c69d8cf76464277ceb31e6b0777750308ecfbc49667fd2ebea67bf0bda1410fbb9ad7690e8eddc98d6d77c326cfb6766ad126df4b97a076979a6f02deba7c0440e2e7f7da4fa77470e98f339089d3fe0c609209b4a388266451d1c95b84e7b1469852fe1bf19f6057cfd72f22a84381d259f522d7f573112517750cce57400743c11f83b09b94ac3be9b23f5b9b756a3472d0fdf129f12475a8ebb8156d6f3561c4ff39deda45d6ef841246a8ef9a4836e4fd103d7fa4bb7feb7ced
multisig address: 42w9C4zK7TVbheCa4DiBDwJuKPLfLU5xEZt9RbD6Mn4AhHjyt3sQYNJiTUyriLSwTU9dEzYHrXWsj2dA646xyia4PhRpXLs
multisig public spend key: 2297d23c0c69d8cf76464277ceb31e6b0777750308ecfbc49667fd2ebea67bf0
multisig secret view key: bda1410fbb9ad7690e8eddc98d6d77c326cfb6766ad126df4b97a076979a6f02
multisig public view key: deba7c0440e2e7f7da4fa77470e98f339089d3fe0c609209b4a388266451d1c9
|#
(test get-wallet-keys
(let* ((file (data-file-path "wallet-1.keys"))
(password "123456")
(keys (get-wallet-keys file password :chacha8 t)))
(is (string-equal "f61b1df1b8bc17126ebd95587494fb128a39217dd468e6bea57f2263626c1306"
(bytes->hex-string (geta keys :secret-spend-key))))
(is (string-equal "2c124acc92d2bc5999156bae00f552167a396080cd4100e4d5107bb2d102cd49"
(bytes->hex-string (geta keys :public-spend-key))))
(is (string-equal "777cd85ce14d5be04de46f348144e78fdccc79fb0599864f867cb02ce389450b"
(bytes->hex-string (geta keys :secret-view-key))))
(is (string-equal "8f5e31dbf970db6784eb5062aded5c80790f5e85667948d0bd7dd269c6722629"
(bytes->hex-string (geta keys :public-view-key)))))
(let* ((file (data-file-path "wallet-2.keys"))
(password "bhunjivgy")
(keys (get-wallet-keys file password)))
(is (string-equal "b50710fdc751efdd2602635a0e271d0af6744a2bf58ca15a138dd6ca5ad78d0a"
(bytes->hex-string (geta keys :secret-spend-key))))
(is (string-equal "3962d1d1e47c06abe2314ed2849c40e67651a449144a2fe8d21e1146653fd085"
(bytes->hex-string (geta keys :public-spend-key))))
(is (string-equal "9197ed5871e7306e49f9d604dc3d9c64aa678bb0736b80f09158ab5ce9305e0c"
(bytes->hex-string (geta keys :secret-view-key))))
(is (string-equal "d302c0849107819a5301b91e08928617bdadcf303b05122dca9adc24d80238e3"
(bytes->hex-string (geta keys :public-view-key))))))
#+sbcl
(test bruteforce-wallet-keys
(let* ((file (data-file-path "wallet-1.keys"))
(keys (bruteforce-wallet-keys file
:threads 4
:characters "0123456789"
:minimum-length 5
:maximum-length 6
:prefix "12"
:suffix "56"
:chacha8 t)))
(is (string= "123456"
(geta keys :password)))
(is (string-equal "f61b1df1b8bc17126ebd95587494fb128a39217dd468e6bea57f2263626c1306"
(bytes->hex-string (geta keys :secret-spend-key)))))
(let* ((file (data-file-path "wallet-1.keys"))
(keys (bruteforce-wallet-keys file
:threads 2
:characters "abcdefgh"
:minimum-length 5
:maximum-length 6
:prefix "12"
:suffix "56"
:chacha8 t)))
(is (null keys)))
(let* ((file (data-file-path "wallet-1.keys"))
(dictionary (data-file-path "dictionary.txt"))
(keys (bruteforce-wallet-keys file :threads 4 :dictionary-file dictionary)))
(is (null keys)))
(let* ((file (data-file-path "wallet-2.keys"))
(keys (bruteforce-wallet-keys file
:minimum-length 9
:maximum-length 9
:prefix "bhunjivg")))
(is (string= "bhunjivgy"
(geta keys :password)))
(is (string-equal "b50710fdc751efdd2602635a0e271d0af6744a2bf58ca15a138dd6ca5ad78d0a"
(bytes->hex-string (geta keys :secret-spend-key)))))
(let* ((file (data-file-path "wallet-2.keys"))
(dictionary (data-file-path "dictionary.txt"))
(keys (bruteforce-wallet-keys file :threads 4 :dictionary-file dictionary)))
(is (string= "bhunjivgy"
(geta keys :password)))
(is (string-equal "b50710fdc751efdd2602635a0e271d0af6744a2bf58ca15a138dd6ca5ad78d0a"
(bytes->hex-string (geta keys :secret-spend-key))))))
(test encode-address
(flet ((encode-address/hex (public-spend-key public-view-key)
(monero-tools::encode-address (hex-string->bytes public-spend-key)
(hex-string->bytes public-view-key))))
(is (string= "43HyW9SFLTmFzDLRgYmeLZ4m4SW7w3G8XfGxfjW79oh6DJdDdwybRJJJKGS3SWsoH5NVMBaXyzty5bv3QNRarqDw5iPfNJJ"
(encode-address/hex "2c124acc92d2bc5999156bae00f552167a396080cd4100e4d5107bb2d102cd49"
"8f5e31dbf970db6784eb5062aded5c80790f5e85667948d0bd7dd269c6722629")))
(is (string= "43oErH6q2FfVkVBXrkQt3yfYmmZN3iseWfwet7TyeXmRPPGFcVFffzpSp92tKSUGKF4yKNh5LRLLh8fEaor4Zx3ySdMJNm7"
(encode-address/hex "3962d1d1e47c06abe2314ed2849c40e67651a449144a2fe8d21e1146653fd085"
"d302c0849107819a5301b91e08928617bdadcf303b05122dca9adc24d80238e3")))))
(test decode-address
(let ((keys (decode-address "43HyW9SFLTmFzDLRgYmeLZ4m4SW7w3G8XfGxfjW79oh6DJdDdwybRJJJKGS3SWsoH5NVMBaXyzty5bv3QNRarqDw5iPfNJJ")))
(is (string-equal "2c124acc92d2bc5999156bae00f552167a396080cd4100e4d5107bb2d102cd49"
(bytes->hex-string (geta keys :public-spend-key))))
(is (string-equal "8f5e31dbf970db6784eb5062aded5c80790f5e85667948d0bd7dd269c6722629"
(bytes->hex-string (geta keys :public-view-key)))))
(let ((keys (decode-address "43oErH6q2FfVkVBXrkQt3yfYmmZN3iseWfwet7TyeXmRPPGFcVFffzpSp92tKSUGKF4yKNh5LRLLh8fEaor4Zx3ySdMJNm7")))
(is (string-equal "3962d1d1e47c06abe2314ed2849c40e67651a449144a2fe8d21e1146653fd085"
(bytes->hex-string (geta keys :public-spend-key))))
(is (string-equal "d302c0849107819a5301b91e08928617bdadcf303b05122dca9adc24d80238e3"
(bytes->hex-string (geta keys :public-view-key))))))
(test valid-address-p
(is-true (valid-address-p "43HyW9SFLTmFzDLRgYmeLZ4m4SW7w3G8XfGxfjW79oh6DJdDdwybRJJJKGS3SWsoH5NVMBaXyzty5bv3QNRarqDw5iPfNJJ"))
(is-true (valid-address-p "43oErH6q2FfVkVBXrkQt3yfYmmZN3iseWfwet7TyeXmRPPGFcVFffzpSp92tKSUGKF4yKNh5LRLLh8fEaor4Zx3ySdMJNm7"))
(is-false (valid-address-p "43oErH6q2FfVkVBXrkQt3yfYm8ZN3iseWfwet7TyeXmRPPGFcVFffzpSp92tKSUGKF4yKNh5LRLLh8fEaor4Zx3ySdMJNm7"))
(is-false (valid-address-p "4BJLvWCVPaHedc26qdvwKWiS638QyHggYgSgX9kKagYR1oGSEH9e46ch4dwe25wDbii7st4VMp2m5ENrtqe1f83E44K8zwK"))
(is-false (valid-address-p "4AeYLx84FNuWTMyA9ssqUWRW9FDQjTp65KLguGrwNLk9P2SmuWh8cx73BkvwKFpCFXhFeCEvRti8R2fAL1jZDFEnV5VgDzA")))
(test pubic-keys->address
(flet ((public-keys->address/hex (public-spend-key public-view-key)
(public-keys->address (hex-string->bytes public-spend-key)
(hex-string->bytes public-view-key))))
(is (string= "43HyW9SFLTmFzDLRgYmeLZ4m4SW7w3G8XfGxfjW79oh6DJdDdwybRJJJKGS3SWsoH5NVMBaXyzty5bv3QNRarqDw5iPfNJJ"
(public-keys->address/hex "2c124acc92d2bc5999156bae00f552167a396080cd4100e4d5107bb2d102cd49"
"8f5e31dbf970db6784eb5062aded5c80790f5e85667948d0bd7dd269c6722629")))
(is (string= "43oErH6q2FfVkVBXrkQt3yfYmmZN3iseWfwet7TyeXmRPPGFcVFffzpSp92tKSUGKF4yKNh5LRLLh8fEaor4Zx3ySdMJNm7"
(public-keys->address/hex "3962d1d1e47c06abe2314ed2849c40e67651a449144a2fe8d21e1146653fd085"
"d302c0849107819a5301b91e08928617bdadcf303b05122dca9adc24d80238e3")))))
(test secret-spend-key->address
(flet ((secret-spend-key->address/hex (secret-spend-key)
(secret-spend-key->address (hex-string->bytes secret-spend-key))))
(is (string= "43HyW9SFLTmFzDLRgYmeLZ4m4SW7w3G8XfGxfjW79oh6DJdDdwybRJJJKGS3SWsoH5NVMBaXyzty5bv3QNRarqDw5iPfNJJ"
(secret-spend-key->address/hex "f61b1df1b8bc17126ebd95587494fb128a39217dd468e6bea57f2263626c1306")))
(is (string= "43oErH6q2FfVkVBXrkQt3yfYmmZN3iseWfwet7TyeXmRPPGFcVFffzpSp92tKSUGKF4yKNh5LRLLh8fEaor4Zx3ySdMJNm7"
(secret-spend-key->address/hex "b50710fdc751efdd2602635a0e271d0af6744a2bf58ca15a138dd6ca5ad78d0a")))))
(test encode-subaddress
(let* ((public-spend-key (hex-string->bytes "2c124acc92d2bc5999156bae00f552167a396080cd4100e4d5107bb2d102cd49"))
(secret-view-key (hex-string->bytes "777cd85ce14d5be04de46f348144e78fdccc79fb0599864f867cb02ce389450b"))
(public-spend-subkey (derive-public-spend-subkey secret-view-key public-spend-key 0 1))
(public-view-subkey (public-spend-subkey->public-view-subkey secret-view-key public-spend-subkey)))
(is (string= "841P6Q51rJJcTR9PgCFNtP6gq2oAJpKtiNh9hQ9AcJ8jabzZRpy8acqHoriBmqCFBPVRBsAseVBmfduEj3Ys2FyGDEpQZ7C"
(public-keys->address public-spend-subkey public-view-subkey :subaddress t))))
(let* ((public-spend-key (hex-string->bytes "2c124acc92d2bc5999156bae00f552167a396080cd4100e4d5107bb2d102cd49"))
(secret-view-key (hex-string->bytes "777cd85ce14d5be04de46f348144e78fdccc79fb0599864f867cb02ce389450b"))
(public-spend-subkey (derive-public-spend-subkey secret-view-key public-spend-key 1 0))
(public-view-subkey (public-spend-subkey->public-view-subkey secret-view-key public-spend-subkey)))
(is (string= "82WabaG7VAXJsdWGkiUJ3u7LkvQ5aR8rqhr1zBWdwdZN2RbjHLYi6mVAZqjucfX5soBngKiQLMt5FFE4VrXA9tE1Lv2ahZf"
(public-keys->address public-spend-subkey public-view-subkey :subaddress t))))
(let* ((public-spend-key (hex-string->bytes "2c124acc92d2bc5999156bae00f552167a396080cd4100e4d5107bb2d102cd49"))
(secret-view-key (hex-string->bytes "777cd85ce14d5be04de46f348144e78fdccc79fb0599864f867cb02ce389450b"))
(public-spend-subkey (derive-public-spend-subkey secret-view-key public-spend-key 1 1))
(public-view-subkey (public-spend-subkey->public-view-subkey secret-view-key public-spend-subkey)))
(is (string= "876NP7hhudXT5wkGMzD2AA58gpzPtcJwDfUYoRijK54iBgNTha9uhQj5jNCHLwQfRjdi4V8RpAeTBUJptbe3FK3V49mr3CW"
(public-keys->address public-spend-subkey public-view-subkey :subaddress t)))))
(test decode-subaddress
(let* ((public-spend-key (hex-string->bytes "2c124acc92d2bc5999156bae00f552167a396080cd4100e4d5107bb2d102cd49"))
(secret-view-key (hex-string->bytes "777cd85ce14d5be04de46f348144e78fdccc79fb0599864f867cb02ce389450b"))
(public-spend-subkey (derive-public-spend-subkey secret-view-key public-spend-key 0 1))
(public-view-subkey (public-spend-subkey->public-view-subkey secret-view-key public-spend-subkey))
(keys (decode-address "841P6Q51rJJcTR9PgCFNtP6gq2oAJpKtiNh9hQ9AcJ8jabzZRpy8acqHoriBmqCFBPVRBsAseVBmfduEj3Ys2FyGDEpQZ7C")))
(is-true (geta keys :subaddress))
(is (equalp public-spend-subkey (geta keys :public-spend-key)))
(is (equalp public-view-subkey (geta keys :public-view-key))))
(let* ((public-spend-key (hex-string->bytes "2c124acc92d2bc5999156bae00f552167a396080cd4100e4d5107bb2d102cd49"))
(secret-view-key (hex-string->bytes "777cd85ce14d5be04de46f348144e78fdccc79fb0599864f867cb02ce389450b"))
(public-spend-subkey (derive-public-spend-subkey secret-view-key public-spend-key 1 0))
(public-view-subkey (public-spend-subkey->public-view-subkey secret-view-key public-spend-subkey))
(keys (decode-address "82WabaG7VAXJsdWGkiUJ3u7LkvQ5aR8rqhr1zBWdwdZN2RbjHLYi6mVAZqjucfX5soBngKiQLMt5FFE4VrXA9tE1Lv2ahZf")))
(is-true (geta keys :subaddress))
(is (equalp public-spend-subkey (geta keys :public-spend-key)))
(is (equalp public-view-subkey (geta keys :public-view-key))))
(let* ((public-spend-key (hex-string->bytes "2c124acc92d2bc5999156bae00f552167a396080cd4100e4d5107bb2d102cd49"))
(secret-view-key (hex-string->bytes "777cd85ce14d5be04de46f348144e78fdccc79fb0599864f867cb02ce389450b"))
(public-spend-subkey (derive-public-spend-subkey secret-view-key public-spend-key 1 1))
(public-view-subkey (public-spend-subkey->public-view-subkey secret-view-key public-spend-subkey))
(keys (decode-address "876NP7hhudXT5wkGMzD2AA58gpzPtcJwDfUYoRijK54iBgNTha9uhQj5jNCHLwQfRjdi4V8RpAeTBUJptbe3FK3V49mr3CW")))
(is-true (geta keys :subaddress))
(is (equalp public-spend-subkey (geta keys :public-spend-key)))
(is (equalp public-view-subkey (geta keys :public-view-key)))))
(test public-keys->subaddress
(flet ((public-keys->subaddress/hex (public-spend-key secret-view-key major-index minor-index &key chain)
(public-keys->subaddress (hex-string->bytes public-spend-key)
(hex-string->bytes secret-view-key)
major-index
minor-index
:chain chain)))
(is (string= "841P6Q51rJJcTR9PgCFNtP6gq2oAJpKtiNh9hQ9AcJ8jabzZRpy8acqHoriBmqCFBPVRBsAseVBmfduEj3Ys2FyGDEpQZ7C"
(public-keys->subaddress/hex "2c124acc92d2bc5999156bae00f552167a396080cd4100e4d5107bb2d102cd49"
"777cd85ce14d5be04de46f348144e78fdccc79fb0599864f867cb02ce389450b"
0 1)))
(is (string= "82WabaG7VAXJsdWGkiUJ3u7LkvQ5aR8rqhr1zBWdwdZN2RbjHLYi6mVAZqjucfX5soBngKiQLMt5FFE4VrXA9tE1Lv2ahZf"
(public-keys->subaddress/hex "2c124acc92d2bc5999156bae00f552167a396080cd4100e4d5107bb2d102cd49"
"777cd85ce14d5be04de46f348144e78fdccc79fb0599864f867cb02ce389450b"
1 0)))
(is (string= "876NP7hhudXT5wkGMzD2AA58gpzPtcJwDfUYoRijK54iBgNTha9uhQj5jNCHLwQfRjdi4V8RpAeTBUJptbe3FK3V49mr3CW"
(public-keys->subaddress/hex "2c124acc92d2bc5999156bae00f552167a396080cd4100e4d5107bb2d102cd49"
"777cd85ce14d5be04de46f348144e78fdccc79fb0599864f867cb02ce389450b"
1 1)))))
(test secret-spend-key->subaddress
(flet ((secret-spend-key->subaddress/hex (secret-spend-key major-index minor-index &key chain)
(secret-spend-key->subaddress (hex-string->bytes secret-spend-key)
major-index
minor-index
:chain chain)))
(is (string= "841P6Q51rJJcTR9PgCFNtP6gq2oAJpKtiNh9hQ9AcJ8jabzZRpy8acqHoriBmqCFBPVRBsAseVBmfduEj3Ys2FyGDEpQZ7C"
(secret-spend-key->subaddress/hex "f61b1df1b8bc17126ebd95587494fb128a39217dd468e6bea57f2263626c1306"
0 1)))
(is (string= "82WabaG7VAXJsdWGkiUJ3u7LkvQ5aR8rqhr1zBWdwdZN2RbjHLYi6mVAZqjucfX5soBngKiQLMt5FFE4VrXA9tE1Lv2ahZf"
(secret-spend-key->subaddress/hex "f61b1df1b8bc17126ebd95587494fb128a39217dd468e6bea57f2263626c1306"
1 0)))
(is (string= "876NP7hhudXT5wkGMzD2AA58gpzPtcJwDfUYoRijK54iBgNTha9uhQj5jNCHLwQfRjdi4V8RpAeTBUJptbe3FK3V49mr3CW"
(secret-spend-key->subaddress/hex "f61b1df1b8bc17126ebd95587494fb128a39217dd468e6bea57f2263626c1306"
1 1)))))
(test valid-message-signature-p
(let ((address "9trf6E3P7r3asxsaoRFpW3RYJXBC4DWKKN9EN4oAif48SH4u4V57zKQMERtJ2KRxTpDJMnpkSKGs29PsoHMb8zgKLPfF1NQ"))
(is-true (valid-message-signature-p "Abcdefg" address "SigV1d75gTEYVHbHYr6WH9LxDEvVRafCL6va1tTnqJhZXXhnhUau6cfijjTF68ntbjZE94uHA3odbfGuviHaY3hwHmWQc"))
(is-true (valid-message-signature-p "This is a message" address "SigV1VsTCdRMjsTKDRcFEBdEcn9EMMuwCqavDr1XtyhTE53mW2Wc6yZyAag5epx68yAq3LibpLQocmAXZyMa6yewZdDjv"))
(is-true (valid-message-signature-p "a1b2c3d4e5f6g7h8i9" address "SigV164c36GEuQRYEg3RwEBD4wtLi7yPqi8i3a38BQAJvUupod51m38URzX14simDHYTC5EdUK9ePB51T4UEaSJwVBwCX"))
(is-true (valid-message-signature-p "Private Digital Currency" address "SigV1QV7kHxJPjVQQqqD192Z6BBF2AxaknFNTxYDc5RXhjFdHGYdHpEigkM45FxdmXTJ537aXSKDAvNP3ZeXRETKmur5U"))
(is-true (valid-message-signature-p "Monero is a secure, private, untraceable currency." address "SigV1a47xuvk2AwvCVZJNbLtjNiXSg8kMyezrLTck5Jufpa57HmpSiPcZqJKCbUUw4QB2MaWRqkwKvJ3nLXQ8fCDSdVCq"))))
(test sign-message
(let ((secret-spend-key (hex-string->bytes "d551999169b794459b4c8dc7da177067213a0eb2dd75cacf19e0fbc27dfc320e"))
(address "9trf6E3P7r3asxsaoRFpW3RYJXBC4DWKKN9EN4oAif48SH4u4V57zKQMERtJ2KRxTpDJMnpkSKGs29PsoHMb8zgKLPfF1NQ"))
(dotimes (i 10)
(let ((message (base58-encode (ironclad:random-data 100))))
(is-true (valid-message-signature-p message address (sign-message message secret-spend-key)))))))
(test valid-file-signature-p
(let ((address "9trf6E3P7r3asxsaoRFpW3RYJXBC4DWKKN9EN4oAif48SH4u4V57zKQMERtJ2KRxTpDJMnpkSKGs29PsoHMb8zgKLPfF1NQ")
(file-1 (data-file-path "message-1.dat"))
(file-2 (data-file-path "message-2.dat")))
(is-true (valid-file-signature-p file-1 address "SigV1Nh4zdYvLpH4Q8Mgi9CAnf5FgK5ExjEmS1S8cQVAt4Qgs8Jx4GohCV9z8qSgfK1CzymMsCYuBELjjkLGUa6n6tBit"))
(is-true (valid-file-signature-p file-2 address "SigV1bcxztfKHU3hRaYrEiWjh3s5KCzDwL7bWKDTWzger6dSUD8pSjtkn7G8SpWjK7obDyJMe7JEx7okYYe23JFXWDhm6"))))
(test sign-file
(let ((secret-spend-key (hex-string->bytes "d551999169b794459b4c8dc7da177067213a0eb2dd75cacf19e0fbc27dfc320e"))
(address "9trf6E3P7r3asxsaoRFpW3RYJXBC4DWKKN9EN4oAif48SH4u4V57zKQMERtJ2KRxTpDJMnpkSKGs29PsoHMb8zgKLPfF1NQ")
(file-1 (data-file-path "message-1.dat"))
(file-2 (data-file-path "message-2.dat")))
(is-true (valid-file-signature-p file-1 address (sign-file file-1 secret-spend-key)))
(is-true (valid-file-signature-p file-2 address (sign-file file-2 secret-spend-key)))))
(test valid-payment-proof-p
(let ((address "9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao")
(transaction-hash "8d245fc820dac077a32db250074c50f995f93630bd374ba3566f5e1d3fde3d4a")
(transaction-public-key "5dd5e0faabe08ccf904a45e486d19ae8e67cb5a17e7e03104070dce80dd26f08")
(proof "ProofV1XnFfDiZjLCDGPYhB26pLUr5yKxhmpAFP1gjM7z58GBpaN5USEd5EfVd272Dogct48o69HnwiyKJspBDDCDV6KzuZeeSzFXQFPhhe5Hq9mAGjqp6XTDTXK6TKWTD4zNi2jT6y"))
(is-true (valid-payment-proof-p (hex-string->bytes transaction-hash)
address
(hex-string->bytes transaction-public-key)
proof))))
(test encrypt-payment-id
(let ((payment-id "1122334455667788")
(public-view-key "68c55751c35ec5347064aac50c5368e6f9dea74cb540646f762c39bf4044b804")
(transaction-secret-key "e00408cc0e3f5b435c1e10c70757ace784d3f732b268ec94ba7d48388c223e0b"))
(is (equalp "833ddb809b9c21dd"
(bytes->hex-string (encrypt-payment-id (hex-string->bytes payment-id)
(hex-string->bytes public-view-key)
(hex-string->bytes transaction-secret-key)))))))
(test decrypt-payment-id
(let ((encrypted-payment-id "833ddb809b9c21dd")
(secret-view-key "fabfcc6b35389437dd69ace7d3280f794f4e27e993e1ada5726a3fd84c9bbb00")
(transaction-public-key "c0156f605aa27e302041a2f18a1954ce7cf4535211a5beaa5d6b9fd55317c850"))
(is (equalp "1122334455667788"
(bytes->hex-string (decrypt-payment-id (hex-string->bytes encrypted-payment-id)
(hex-string->bytes transaction-public-key)
(hex-string->bytes secret-view-key)))))))
(test output-for-address-p
(let ((address "9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao")
(secret-view-key "fabfcc6b35389437dd69ace7d3280f794f4e27e993e1ada5726a3fd84c9bbb00")
(output-key "49b37a01ae9f4864776fef678bdbdbde0d07825f70e9e0c45e02d38fc1e615d7")
(output-index 0)
(transaction-public-key "cebcf16a2a1e44a3204f502a6a979ba0d77b1be39859cab283df052c8f99da99"))
(is-true (output-for-address-p (hex-string->bytes output-key)
output-index
(hex-string->bytes transaction-public-key)
nil
address
(hex-string->bytes secret-view-key))))
(let ((address "9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao")
(subaddress "Bcni4ZAM42o4QcYG7fCFwX8GijijG43d5YnafUhSp7D8iXZ5K4Qxbr4SEKZiHqfFFnDbn6Eq5MDY6iMPhtDJb6sSEqxHNSV")
(secret-view-key "fabfcc6b35389437dd69ace7d3280f794f4e27e993e1ada5726a3fd84c9bbb00")
(output-key-0 "b859088a9a09c0ff760b399282510b20a9c53069efc725627b6bc1ba9648d7ad")
(output-key-1 "563ddb372ed3863a841f9300f025b77ea6dc35dc3b677951d36b0bbc4e90bab1")
(transaction-public-key "70f715b5d256790f9625676a1319d4a2030f3294f34d5306277b12f4d83072ec"))
(is-true (output-for-address-p (hex-string->bytes output-key-0)
0
(hex-string->bytes transaction-public-key)
nil
subaddress
(hex-string->bytes secret-view-key)))
(is-true (output-for-address-p (hex-string->bytes output-key-1)
1
(hex-string->bytes transaction-public-key)
nil
address
(hex-string->bytes secret-view-key))))
(let ((address "9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao")
(subaddress-1 "Bcni4ZAM42o4QcYG7fCFwX8GijijG43d5YnafUhSp7D8iXZ5K4Qxbr4SEKZiHqfFFnDbn6Eq5MDY6iMPhtDJb6sSEqxHNSV")
(subaddress-2 "BfZQpPkqnQkTJCmge6mpLjdQ4DRsjd2MiTAnXEywr8XRR1NbDoKgKqsFsUDZrABqJv6TZrQKnMwfTJApGMoHREXLRJJsLHT")
(secret-view-key "fabfcc6b35389437dd69ace7d3280f794f4e27e993e1ada5726a3fd84c9bbb00")
(output-key-0 "18ce6685a1d0c85ca59bbe4053f0693ecd9c2b8fd0de4b33d0056b6d65962fb0")
(output-key-1 "a95289fcab4c8f962154dab54f14806f3e0d4097884ea71eb5ee1e1bb03bc7cb")
(output-key-2 "c28e0c02e533d7d4b7605900d51f7824d186ec870f794eb0fdcd89daf3af5ca4")
(transaction-public-key "4bc8b6926a1676c657e0ddc97910676ec5aa456fddda2b20b3f6e9a728dc7914")
(additional-public-keys (map 'vector
#'hex-string->bytes
#("274d8feba5237579c6e39294aed39ed00ffc46b34e4f9a9b50056123f10f4b0a"
"fcfc267e421edaa27f85a811fa08232b1fd6fbd683938857467cdaefb756327d"
"3c300a6a9852f2ac7d0b6264076e57f7df9825c34fcea52e6346cba9a9c2405a"))))
(is-true (output-for-address-p (hex-string->bytes output-key-0)
0
(hex-string->bytes transaction-public-key)
additional-public-keys
subaddress-1
(hex-string->bytes secret-view-key)))
(is-true (output-for-address-p (hex-string->bytes output-key-1)
1
(hex-string->bytes transaction-public-key)
additional-public-keys
subaddress-2
(hex-string->bytes secret-view-key)))
(is-true (output-for-address-p (hex-string->bytes output-key-2)
2
(hex-string->bytes transaction-public-key)
additional-public-keys
address
(hex-string->bytes secret-view-key)))))
(test output-destination-address
(let* ((address "9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao")
(address-info (decode-address address))
(public-spend-key (geta address-info :public-spend-key))
(chain (geta address-info :chain))
(secret-view-key "fabfcc6b35389437dd69ace7d3280f794f4e27e993e1ada5726a3fd84c9bbb00")
(indexes-table (compute-subaddress-indexes-table (hex-string->bytes secret-view-key)
public-spend-key
5
10))
(output-key "49b37a01ae9f4864776fef678bdbdbde0d07825f70e9e0c45e02d38fc1e615d7")
(output-index 0)
(transaction-public-key "cebcf16a2a1e44a3204f502a6a979ba0d77b1be39859cab283df052c8f99da99"))
(multiple-value-bind (addr indexes)
(output-destination-address (hex-string->bytes output-key)
output-index
(hex-string->bytes transaction-public-key)
nil
indexes-table
(hex-string->bytes secret-view-key)
:chain chain)
(is (string= address addr))
(is (equalp '(0 0) indexes))))
(let* ((address "9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao")
(address-info (decode-address address))
(public-spend-key (geta address-info :public-spend-key))
(chain (geta address-info :chain))
(subaddress "Bcni4ZAM42o4QcYG7fCFwX8GijijG43d5YnafUhSp7D8iXZ5K4Qxbr4SEKZiHqfFFnDbn6Eq5MDY6iMPhtDJb6sSEqxHNSV")
(secret-view-key "fabfcc6b35389437dd69ace7d3280f794f4e27e993e1ada5726a3fd84c9bbb00")
(indexes-table (compute-subaddress-indexes-table (hex-string->bytes secret-view-key)
public-spend-key
5
10))
(output-key-0 "b859088a9a09c0ff760b399282510b20a9c53069efc725627b6bc1ba9648d7ad")
(output-key-1 "563ddb372ed3863a841f9300f025b77ea6dc35dc3b677951d36b0bbc4e90bab1")
(transaction-public-key "70f715b5d256790f9625676a1319d4a2030f3294f34d5306277b12f4d83072ec"))
(multiple-value-bind (addr indexes)
(output-destination-address (hex-string->bytes output-key-0)
0
(hex-string->bytes transaction-public-key)
nil
indexes-table
(hex-string->bytes secret-view-key)
:chain chain)
(is (string= subaddress addr))
(is (equalp '(1 0) indexes)))
(multiple-value-bind (addr indexes)
(output-destination-address (hex-string->bytes output-key-1)
1
(hex-string->bytes transaction-public-key)
nil
indexes-table
(hex-string->bytes secret-view-key)
:chain chain)
(is (string= address addr))
(is (equalp '(0 0) indexes))))
(let* ((address "9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao")
(address-info (decode-address address))
(public-spend-key (geta address-info :public-spend-key))
(chain (geta address-info :chain))
(subaddress-1 "Bcni4ZAM42o4QcYG7fCFwX8GijijG43d5YnafUhSp7D8iXZ5K4Qxbr4SEKZiHqfFFnDbn6Eq5MDY6iMPhtDJb6sSEqxHNSV")
(subaddress-2 "BfZQpPkqnQkTJCmge6mpLjdQ4DRsjd2MiTAnXEywr8XRR1NbDoKgKqsFsUDZrABqJv6TZrQKnMwfTJApGMoHREXLRJJsLHT")
(secret-view-key "fabfcc6b35389437dd69ace7d3280f794f4e27e993e1ada5726a3fd84c9bbb00")
(indexes-table (compute-subaddress-indexes-table (hex-string->bytes secret-view-key)
public-spend-key
5
10))
(output-key-0 "18ce6685a1d0c85ca59bbe4053f0693ecd9c2b8fd0de4b33d0056b6d65962fb0")
(output-key-1 "a95289fcab4c8f962154dab54f14806f3e0d4097884ea71eb5ee1e1bb03bc7cb")
(output-key-2 "c28e0c02e533d7d4b7605900d51f7824d186ec870f794eb0fdcd89daf3af5ca4")
(transaction-public-key "4bc8b6926a1676c657e0ddc97910676ec5aa456fddda2b20b3f6e9a728dc7914")
(additional-public-keys (map 'vector
#'hex-string->bytes
#("274d8feba5237579c6e39294aed39ed00ffc46b34e4f9a9b50056123f10f4b0a"
"fcfc267e421edaa27f85a811fa08232b1fd6fbd683938857467cdaefb756327d"
"3c300a6a9852f2ac7d0b6264076e57f7df9825c34fcea52e6346cba9a9c2405a"))))
(multiple-value-bind (addr indexes)
(output-destination-address (hex-string->bytes output-key-0)
0
(hex-string->bytes transaction-public-key)
additional-public-keys
indexes-table
(hex-string->bytes secret-view-key)
:chain chain)
(is (string= subaddress-1 addr))
(is (equalp '(1 0) indexes)))
(multiple-value-bind (addr indexes)
(output-destination-address (hex-string->bytes output-key-1)
1
(hex-string->bytes transaction-public-key)
additional-public-keys
indexes-table
(hex-string->bytes secret-view-key)
:chain chain)
(is (string= subaddress-2 addr))
(is (equalp '(1 1) indexes)))
(multiple-value-bind (addr indexes)
(output-destination-address (hex-string->bytes output-key-2)
2
(hex-string->bytes transaction-public-key)
additional-public-keys
indexes-table
(hex-string->bytes secret-view-key)
:chain chain)
(is (string= address addr))
(is (equalp '(0 0) indexes)))))
(test decrypt-amount
(let ((encrypted-amount "3d09a2bf7867c9b90be6789f2a694b854fb8f014a4cb347ab7996389516c4d00")
(output-index 0)
(transaction-public-key "5dd5e0faabe08ccf904a45e486d19ae8e67cb5a17e7e03104070dce80dd26f08")
(secret-view-key "fabfcc6b35389437dd69ace7d3280f794f4e27e993e1ada5726a3fd84c9bbb00"))
(is (= 3783303208739
(decrypt-amount (hex-string->bytes encrypted-amount)
output-index
(hex-string->bytes transaction-public-key)
(hex-string->bytes secret-view-key)))))
(let ((encrypted-amount "5474d0b5fe10b407a880713ed78f2118e9928b2a170fe0878e0671c3d860ae0e")
(output-index 1)
(transaction-public-key "5dd5e0faabe08ccf904a45e486d19ae8e67cb5a17e7e03104070dce80dd26f08")
(secret-view-key "fabfcc6b35389437dd69ace7d3280f794f4e27e993e1ada5726a3fd84c9bbb00"))
(is (= 30000000000000
(decrypt-amount (hex-string->bytes encrypted-amount)
output-index
(hex-string->bytes transaction-public-key)
(hex-string->bytes secret-view-key)))))
(let ((encrypted-amount-0 "5b8b146d95fab3372a0491eee3aa488d896ea917fc4af064cf1606e9c8dec509")
(encrypted-amount-1 "dced18217899c0f4f652a427563ccbbdbbe14b5b649dc7d1749cec22d6c3c208")
(encrypted-amount-2 "a61e4526d0874608bf7dc58f42a89fb93294931f270cb6d5d1c4820b6a3e8f0f")
(transaction-public-key "4bc8b6926a1676c657e0ddc97910676ec5aa456fddda2b20b3f6e9a728dc7914")
(additional-public-keys (map 'vector
#'hex-string->bytes
#("274d8feba5237579c6e39294aed39ed00ffc46b34e4f9a9b50056123f10f4b0a"
"fcfc267e421edaa27f85a811fa08232b1fd6fbd683938857467cdaefb756327d"
"3c300a6a9852f2ac7d0b6264076e57f7df9825c34fcea52e6346cba9a9c2405a")))
(secret-view-key "fabfcc6b35389437dd69ace7d3280f794f4e27e993e1ada5726a3fd84c9bbb00"))
(is (= 11000000000000
(decrypt-amount (hex-string->bytes encrypted-amount-0)
0
(aref additional-public-keys 0) ; subaddress
(hex-string->bytes secret-view-key))))
(is (= 17000000000000
(decrypt-amount (hex-string->bytes encrypted-amount-1)
1
(aref additional-public-keys 1) ; subaddress
(hex-string->bytes secret-view-key))))
(is (= 338997666200000
(decrypt-amount (hex-string->bytes encrypted-amount-2)
2
(hex-string->bytes transaction-public-key) ; main address
(hex-string->bytes secret-view-key))))))
(test received-amount
(let* ((address "9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao")
(subaddress-1 "Bcni4ZAM42o4QcYG7fCFwX8GijijG43d5YnafUhSp7D8iXZ5K4Qxbr4SEKZiHqfFFnDbn6Eq5MDY6iMPhtDJb6sSEqxHNSV")
(subaddress-2 "BfZQpPkqnQkTJCmge6mpLjdQ4DRsjd2MiTAnXEywr8XRR1NbDoKgKqsFsUDZrABqJv6TZrQKnMwfTJApGMoHREXLRJJsLHT")
(secret-view-key "fabfcc6b35389437dd69ace7d3280f794f4e27e993e1ada5726a3fd84c9bbb00")
(transaction-data (load-hex-data "txn-55b0833a74d6b933d3c97a74bebd2b2d0926e8a091a51e170fa5e7ae26019a9b.hex"))
(transaction (deserialize-transaction (hex-string->bytes transaction-data) 0)))
(is (= 11000000000000
(received-amount transaction subaddress-1 (hex-string->bytes secret-view-key))))
(is (= 17000000000000
(received-amount transaction subaddress-2 (hex-string->bytes secret-view-key))))
(is (= 11603063785325
(received-amount transaction address (hex-string->bytes secret-view-key))))))
(test prove-payment
(let ((address "9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao")
(transaction-hash "8d245fc820dac077a32db250074c50f995f93630bd374ba3566f5e1d3fde3d4a")
(transaction-public-key "5dd5e0faabe08ccf904a45e486d19ae8e67cb5a17e7e03104070dce80dd26f08")
(transaction-secret-key "5404868a109869804a2e45f6797c250e68d9c5afe9cb9c1fd1ed8108082ac909"))
(is-true (valid-payment-proof-p (hex-string->bytes transaction-hash)
address
(hex-string->bytes transaction-public-key)
(prove-payment (hex-string->bytes transaction-hash)
address
(hex-string->bytes transaction-secret-key))))))
(test valid-inbound-transaction-proof-p
(let ((address "9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao")
(transaction-hash "ae4671480fa0c139bfeea2913210dcb8130ae3eef688a707d91923528fee1c14")
(message "message")
(transaction-public-key "cebcf16a2a1e44a3204f502a6a979ba0d77b1be39859cab283df052c8f99da99")
(secret-view-key "fabfcc6b35389437dd69ace7d3280f794f4e27e993e1ada5726a3fd84c9bbb00")
(proof "InProofV11MFcTEcRh6rZf9boPNaShJDfYwGVeMNSjfNz9zFh8aVrBHBA94GbBcq35o2cVj1cUFEsAZ1HL59XK3PQtpgUePps6654CweyYaYKjVqhG7MAxDTa3A7Wx9T3gM3siXYrgFj2"))
(is-true (valid-inbound-transaction-proof-p (hex-string->bytes transaction-hash)
address
(string->bytes message)
(hex-string->bytes transaction-public-key)
proof
(hex-string->bytes secret-view-key))))
(let ((address "Bcni4ZAM42o4QcYG7fCFwX8GijijG43d5YnafUhSp7D8iXZ5K4Qxbr4SEKZiHqfFFnDbn6Eq5MDY6iMPhtDJb6sSEqxHNSV")
(transaction-hash "55b0833a74d6b933d3c97a74bebd2b2d0926e8a091a51e170fa5e7ae26019a9b")
(message "message")
(transaction-public-key "1d48faf3fd43351899103a192f617399777cbfd768a227efdfce9626e8dd675b39fef5b2ba92189413022274eabb80ae24e4fad30903faf52253c129f9ab7cb263dd76e8cb0b300cecc3166670715d7889eb209f2d3cf29bb355ea6c10570e579b33ff048a765f9c2147d8294b9423a49cca0481c1d160760c5dbfefaf3b7618")
(secret-view-key "fabfcc6b35389437dd69ace7d3280f794f4e27e993e1ada5726a3fd84c9bbb00")
(proof "InProofV2PmQpopZjo16YzqZtkQWaVFiUyQYm24JjJKpDimG9MUXdBjiJBpNWohiDSvmNg5htxQSErX4GdqhDhUAEHpBpSWvUC62w4QcLamm6wkRQa4YNwpPqK5xyhuibmNYnm7yNbjXxLNAqzp2T7pJhYvxNe4skYoBSztbxnEnME6MwUodJQYbh7xh3c6Demwo1CYsMnr9swaJp39hbTeXko9SzZ9F7QNLHcu7LYAHF1V7LCgh5r4kKR7NfENBCMuGSEQC6TzPuEDYCUQEevQKpMrca4UKgwsZqUPhhShAYLb5MngyGg1eXwmELj3Lqaz5T82EemNiVCfKhwzYSkduMoJb1sJZHdVKVZY45Pixqun2Jc8Z1d7uFY3Yh5o3pv8ytr877s1MLcPpVxro8A6DgeK7wbm7gCvDiHKJPNi3ax8hNKVg733CZNcU9BeKXf2iTzr1PC4tgopZ3J5CP9iZmwa5mZpgKvNMauuTrySRA6gcqf6fNrvvhsvB6Su9YjufKhnG33DqRpbFNJKSsmmKZ"))
(is-true (valid-inbound-transaction-proof-p (hex-string->bytes transaction-hash)
address
(string->bytes message)
(hex-string->bytes transaction-public-key)
proof
(hex-string->bytes secret-view-key)))))
(test prove-inbound-transaction
(let* ((address "9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao")
(transaction-hash "ae4671480fa0c139bfeea2913210dcb8130ae3eef688a707d91923528fee1c14")
(message "message")
(transaction-public-key "cebcf16a2a1e44a3204f502a6a979ba0d77b1be39859cab283df052c8f99da99")
(secret-view-key "fabfcc6b35389437dd69ace7d3280f794f4e27e993e1ada5726a3fd84c9bbb00")
(proof (prove-inbound-transaction (hex-string->bytes transaction-hash)
address
(string->bytes message)
(hex-string->bytes transaction-public-key)
(hex-string->bytes secret-view-key))))
(is-true (valid-inbound-transaction-proof-p (hex-string->bytes transaction-hash)
address
(string->bytes message)
(hex-string->bytes transaction-public-key)
proof
(hex-string->bytes secret-view-key)))))
(test valid-outbound-transaction-proof-p
(let ((address "9trf6E3P7r3asxsaoRFpW3RYJXBC4DWKKN9EN4oAif48SH4u4V57zKQMERtJ2KRxTpDJMnpkSKGs29PsoHMb8zgKLPfF1NQ")
(transaction-hash "6761c0560ba5fab0ce37b51782cc6e03cd1f3ed8442faba726b444594b384baf")
(message "message")
(transaction-public-key "fe34e8abd3d1c39686f25f8b5975fa160ae77fda33e3a6183007cc4abaf5ec36")
(secret-view-key "6abd4dace0e11638d9a87ebd2e1b926d58716229691961515f4d4ba92c0dbc43")
(proof "OutProofV12CsdHk19Joa4cWq2Romg32T9pRrMKYzEBK73rais2m9xKoqPftMzMCqP51pAd6nCJjKH7faHiTTJPL3r4VgpszVGdmLz5eCykuWJ1KfSCsgFbCfHuqDYykSN7YMgFYSZ9BXw"))
(is-true (valid-outbound-transaction-proof-p (hex-string->bytes transaction-hash)
address
(string->bytes message)
(hex-string->bytes transaction-public-key)
proof
(hex-string->bytes secret-view-key))))
(let ((address "9trf6E3P7r3asxsaoRFpW3RYJXBC4DWKKN9EN4oAif48SH4u4V57zKQMERtJ2KRxTpDJMnpkSKGs29PsoHMb8zgKLPfF1NQ")
(transaction-hash "6761c0560ba5fab0ce37b51782cc6e03cd1f3ed8442faba726b444594b384baf")
(message "message")
(transaction-public-key "fe34e8abd3d1c39686f25f8b5975fa160ae77fda33e3a6183007cc4abaf5ec36")
(secret-view-key "6abd4dace0e11638d9a87ebd2e1b926d58716229691961515f4d4ba92c0dbc43")
(proof "OutProofV22CsdHk19Joa4cWq2Romg32T9pRrMKYzEBK73rais2m9xZLvwUJ4ip52Hx1CiW1a8wsAmFWZk1q2AQASdhECn29poAK2q2iibWR88TLgkQMv6BSU9vg845fgZEQz7Jn68R47x"))
(is-true (valid-outbound-transaction-proof-p (hex-string->bytes transaction-hash)
address
(string->bytes message)
(hex-string->bytes transaction-public-key)
proof
(hex-string->bytes secret-view-key)))))
(test prove-outbound-transaction
(let* ((address "9trf6E3P7r3asxsaoRFpW3RYJXBC4DWKKN9EN4oAif48SH4u4V57zKQMERtJ2KRxTpDJMnpkSKGs29PsoHMb8zgKLPfF1NQ")
(transaction-hash "6761c0560ba5fab0ce37b51782cc6e03cd1f3ed8442faba726b444594b384baf")
(message "message")
(transaction-public-key "fe34e8abd3d1c39686f25f8b5975fa160ae77fda33e3a6183007cc4abaf5ec36")
(transaction-secret-key "6f7b540ee4423231136603e4918aa8afcf96eda25156d3d2e96519a9406e0a0c")
(secret-view-key "6abd4dace0e11638d9a87ebd2e1b926d58716229691961515f4d4ba92c0dbc43")
(proof (prove-outbound-transaction (hex-string->bytes transaction-hash)
address
(string->bytes message)
(hex-string->bytes transaction-secret-key))))
(is-true (valid-outbound-transaction-proof-p (hex-string->bytes transaction-hash)
address
(string->bytes message)
(hex-string->bytes transaction-public-key)
proof
(hex-string->bytes secret-view-key)))))
(test make-uri
(let ((address "9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao")
(payment-id (hex-string->bytes "8a17098fde6a8fa13087089bcddf8d49d2a8522c15870ab0a07ce4b162d4a7d5"))
(recipient-name "Alice MONERO")
(amount (read-float "12.3456789012"))
(description "A payment to Alice"))
(is (string= "monero:9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao"
(make-uri address)))
(is (string= "monero:9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao?tx_payment_id=8a17098fde6a8fa13087089bcddf8d49d2a8522c15870ab0a07ce4b162d4a7d5"
(make-uri address :payment-id payment-id)))
(is (string= "monero:9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao?tx_payment_id=8a17098fde6a8fa13087089bcddf8d49d2a8522c15870ab0a07ce4b162d4a7d5&tx_amount=12.3456789012"
(make-uri address :payment-id payment-id
:amount amount)))
(is (string= "monero:9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao?tx_payment_id=8a17098fde6a8fa13087089bcddf8d49d2a8522c15870ab0a07ce4b162d4a7d5&tx_amount=12.3456789012&tx_description=A%20payment%20to%20Alice"
(make-uri address :payment-id payment-id
:amount amount
:description description)))
(is (string= "monero:9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao?tx_payment_id=8a17098fde6a8fa13087089bcddf8d49d2a8522c15870ab0a07ce4b162d4a7d5&recipient_name=Alice%20MONERO&tx_amount=12.3456789012&tx_description=A%20payment%20to%20Alice"
(make-uri address :payment-id payment-id
:amount amount
:recipient-name recipient-name
:description description)))))
(test decode-uri
(let ((address "9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao")
(payment-id "8a17098fde6a8fa13087089bcddf8d49d2a8522c15870ab0a07ce4b162d4a7d5")
(recipient-name "Alice MONERO")
(amount (read-float "12.3456789012"))
(description "A payment to Alice"))
(let ((result (decode-uri "monero:9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao")))
(is (string= address (geta result :address))))
(let ((result (decode-uri "monero:9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao?tx_payment_id=8a17098fde6a8fa13087089bcddf8d49d2a8522c15870ab0a07ce4b162d4a7d5")))
(is (string= address (geta result :address)))
(is (string= payment-id (bytes->hex-string (geta result :payment-id)))))
(let ((result (decode-uri "monero:9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao?tx_payment_id=8a17098fde6a8fa13087089bcddf8d49d2a8522c15870ab0a07ce4b162d4a7d5&tx_amount=12.3456789012")))
(is (string= address (geta result :address)))
(is (string= payment-id (bytes->hex-string (geta result :payment-id))))
(is (= amount (geta result :amount))))
(let ((result (decode-uri "monero:9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao?tx_payment_id=8a17098fde6a8fa13087089bcddf8d49d2a8522c15870ab0a07ce4b162d4a7d5&tx_amount=12.3456789012&tx_description=A%20payment%20to%20Alice")))
(is (string= address (geta result :address)))
(is (string= payment-id (bytes->hex-string (geta result :payment-id))))
(is (= amount (geta result :amount)))
(is (string= description (geta result :description))))
(let ((result (decode-uri "monero:9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao?tx_payment_id=8a17098fde6a8fa13087089bcddf8d49d2a8522c15870ab0a07ce4b162d4a7d5&tx_amount=12.3456789012&tx_description=A%20payment%20to%20Alice&recipient_name=Alice%20MONERO")))
(is (string= address (geta result :address)))
(is (string= payment-id (bytes->hex-string (geta result :payment-id))))
(is (string= recipient-name (geta result :recipient-name)))
(is (= amount (geta result :amount)))
(is (string= description (geta result :description))))))
(test decode-qr-code
(let ((address "9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao")
(payment-id "8a17098fde6a8fa13087089bcddf8d49d2a8522c15870ab0a07ce4b162d4a7d5")
(recipient-name "Alice MONERO")
(description "A payment to Alice")
(file1 (data-file-path "qr1.png"))
(file2 (data-file-path "qr2.png"))
(file3 (data-file-path "qr3.png"))
(file4 (data-file-path "qr4.png")))
(let ((amount 3)
(result (decode-qr-code file1)))
(is (string= address (geta result :address)))
(is (string= payment-id (bytes->hex-string (geta result :payment-id))))
(is (= amount (geta result :amount))))
(let ((amount (read-float "12.3456789012"))
(result (decode-qr-code file2)))
(is (string= address (geta result :address)))
(is (string= payment-id (bytes->hex-string (geta result :payment-id))))
(is (string= recipient-name (geta result :recipient-name)))
(is (= amount (geta result :amount)))
(is (string= description (geta result :description))))
(is (equalp (decode-qr-code file2) (decode-qr-code file3)))
(is (equalp (decode-qr-code file2) (decode-qr-code file4)))))
(test make-qr-code
(let ((address "9zmzEX3Ux4wMWTHesGg7jW8J6y7T5vb45RH3DZk7yHRk8G8CqtirBpY9mj1fx9RFnXfdkuj87qoF1KeKQGe2Up311XbV1ao")
(recipient-name "Alice MONERO")
(description "A payment to Alice")
(file (data-file-path "qr0.png")))
(dotimes (i 3)
(let ((amount (ironclad:strong-random 100))
(payment-id (ironclad:random-data 32)))
(make-qr-code file address
:payment-id payment-id
:amount amount
:recipient-name recipient-name
:description description)
(let ((result (decode-qr-code file)))
(is (string= address (geta result :address)))
(is (equalp payment-id (geta result :payment-id)))
(is (string= recipient-name (geta result :recipient-name)))
(is (= amount (geta result :amount)))
(is (string= description (geta result :description))))))
(uiop:delete-file-if-exists file)))
(test make-multisig-info
(flet ((string=-no-sig (x y)
(string= x y :end1 (- (length x) 128) :end2 (- (length y) 128))))
(let ((secret-view-key "6f5631bfa0a7a4719cd2ddf3acf9ab26a93c88dc5560ebf8e426a544ccad8803")
(secret-spend-key "ddf53de98c2cde52a5daac71a7464dc4f46d7d54afad4259952ae3c97f663305"))
(is (string=-no-sig "MultisigV1ACtQwqtBN6x74iS7stvtsWhqcLBXBvy71VCy1WVGE9UGgJdkYqo47wXLAyBkxpieFRA4GWgDAGtNh6BH5ZZenvRTGUVMMQKszEjAPnL2A5hyxVTymHoMaPE2nj82hnS2evNaSXj4yh8LKfa2o1zE9QMaNp2PtGvm6TUdwjb2bzjoBrhg"
(make-multisig-info (hex-string->bytes secret-view-key)
(hex-string->bytes secret-spend-key)))))
(let ((secret-view-key "8bc2f1c91767c32404b5fc906122ee5a22efb8c5c8e229477850069fda334c04")
(secret-spend-key "88a82e356a24ec0ec1dd497a3264c1c28741905781aecf051f89ec3dc962d101"))
(is (string=-no-sig "MultisigV1VEkbitipY51HQUH56z8Pu9cx6ATQD4Cvk7XPkwqkDbfU57N5FsBRiN5Gu9ikLqv44qgkAUxAmw739GAnaLS1MAzMa3kjv1m72PwfVM1z3JEeBpdSWRsSXHpEHbXwSiPywurujVYitznC8aRgqnHu7W1Zs8fbpirY1bFH4CqtBx4iedJe"
(make-multisig-info (hex-string->bytes secret-view-key)
(hex-string->bytes secret-spend-key)))))
(let ((secret-view-key "64bf5bdbbb82c6d084b1ae8eff4b0710b372e53465c0c9d90db1bbc8dcbb9c06")
(secret-spend-key "02dea042ab01454d9ca369a454cb0613c6f2c35d9009c3daf959b3d839570b02"))
(is (string=-no-sig "MultisigV1QMNubqf2Zp8HwjCr8qVT32Y1onHiaatCYbxWam4oCdm7DDGqwJDdmzFZT4Xim7nEvDdy422avHWMqMqZ3MH8BCGqGbg2f3xo8YoDvX4kEFYyb9Jd6H5z7DGToJBnLrtpZoqfXzryyUwpGzWEZ2qkVtKipgQ94RWETo1z6QDEtu8SDVN3"
(make-multisig-info (hex-string->bytes secret-view-key)
(hex-string->bytes secret-spend-key)))))
(let ((secret-view-key "5e41a1e789066174019f1c82fab08cb7b7ca96965d972849c06258b79224b704")
(secret-spend-key "16f065708dc3f9bf6095ade6867dbd68da2968a668e67d05f14b9dcd2986f90b"))
(is (string=-no-sig "MultisigV1iQbqPBYtGQ6daPFHgoANND5EAfofFeaivJEfuRpabfDybWmLZJ5cKU6WYKLxzEaPwLGKhuDaB6qUQhLbJ8yTypx7FXx47Zc4uwgaouaxniTnbuaY7rv9mCAA9KVy7Q7UPiarSTn2exrQPti3TPSPmwQu89MTCfkpxGq7pR6bA4KwDZpe"
(make-multisig-info (hex-string->bytes secret-view-key)
(hex-string->bytes secret-spend-key)))))
(let ((secret-view-key "0724632717bc4d9195c7d0b8c19565adaa88b8e8d62df899559eeef1d74d3e0c")
(secret-spend-key "6919108e1aa3f4402c670aa762e4554400fc3db0c26c12cc31f9e89b1b93a506"))
(is (string=-no-sig "MultisigV1X6H2P2QJ8Y92b8FrCQ2Nk43GMS47gHy5UfEC1eEBm9Jp4asf3n68DeYeGx5d4pnk77VFte1eXtwTVBHcaudJktXnfTxL4mA4G3baHFn9ncRvQSXACjyyLriJgbtWeai6kdoiRxx7F6p42AqjSJLoaExLhrRwTjbKrDkdejLj2s4SyadG"
(make-multisig-info (hex-string->bytes secret-view-key)
(hex-string->bytes secret-spend-key)))))))
(test decode-multisig-info
(let ((multisig-info (decode-multisig-info "MultisigV1ACtQwqtBN6x74iS7stvtsWhqcLBXBvy71VCy1WVGE9UGgJdkYqo47wXLAyBkxpieFRA4GWgDAGtNh6BH5ZZenvRTGUVMMQKszEjAPnL2A5hyxVTymHoMaPE2nj82hnS2evNaSXj4yh8LKfa2o1zE9QMaNp2PtGvm6TUdwjb2bzjoBrhg")))
(is (string-equal "37086110d56edb0d244128eee6980255f427acca9b965fe4a8a26d17ff8be005"
(bytes->hex-string (geta multisig-info :secret-view-key))))
(is (string-equal "eafbc2265dca6fca729f038d00a408f03624f039ea10a9be1ef3d19aaed4e856"
(bytes->hex-string (geta multisig-info :public-signer-key)))))
(let ((multisig-info (decode-multisig-info "MultisigV1VEkbitipY51HQUH56z8Pu9cx6ATQD4Cvk7XPkwqkDbfU57N5FsBRiN5Gu9ikLqv44qgkAUxAmw739GAnaLS1MAzMa3kjv1m72PwfVM1z3JEeBpdSWRsSXHpEHbXwSiPywurujVYitznC8aRgqnHu7W1Zs8fbpirY1bFH4CqtBx4iedJe")))
(is (string-equal "a8d18e7ce2e4de4c6213b9e883280ab0d6ee0c4640942151270125ffa71b500f"
(bytes->hex-string (geta multisig-info :secret-view-key))))
(is (string-equal "1892038bd30631aa5f0e056ae47f87b2ed9d72e32dc20b645ab0171d52884f42"
(bytes->hex-string (geta multisig-info :public-signer-key)))))
(let ((multisig-info (decode-multisig-info "MultisigV1QMNubqf2Zp8HwjCr8qVT32Y1onHiaatCYbxWam4oCdm7DDGqwJDdmzFZT4Xim7nEvDdy422avHWMqMqZ3MH8BCGqGbg2f3xo8YoDvX4kEFYyb9Jd6H5z7DGToJBnLrtpZoqfXzryyUwpGzWEZ2qkVtKipgQ94RWETo1z6QDEtu8SDVN3")))
(is (string-equal "8b9bc92fc3849735654c8e6be3fea89db96b8724b90cec21d0fea2485b062506"
(bytes->hex-string (geta multisig-info :secret-view-key))))
(is (string-equal "49022814b64909a8c20078877610d80add01fbf6ef9f55fc7c93b2b2f9029122"
(bytes->hex-string (geta multisig-info :public-signer-key)))))
(let ((multisig-info (decode-multisig-info "MultisigV1iQbqPBYtGQ6daPFHgoANND5EAfofFeaivJEfuRpabfDybWmLZJ5cKU6WYKLxzEaPwLGKhuDaB6qUQhLbJ8yTypx7FXx47Zc4uwgaouaxniTnbuaY7rv9mCAA9KVy7Q7UPiarSTn2exrQPti3TPSPmwQu89MTCfkpxGq7pR6bA4KwDZpe")))
(is (string-equal "f78e43b21da28affdaabcd00189c7f6a19458b2a695fe90b670ba8197c628b08"
(bytes->hex-string (geta multisig-info :secret-view-key))))
(is (string-equal "ce57400743c11f83b09b94ac3be9b23f5b9b756a3472d0fdf129f12475a8ebb8"
(bytes->hex-string (geta multisig-info :public-signer-key)))))
(let ((multisig-info (decode-multisig-info "MultisigV1X6H2P2QJ8Y92b8FrCQ2Nk43GMS47gHy5UfEC1eEBm9Jp4asf3n68DeYeGx5d4pnk77VFte1eXtwTVBHcaudJktXnfTxL4mA4G3baHFn9ncRvQSXACjyyLriJgbtWeai6kdoiRxx7F6p42AqjSJLoaExLhrRwTjbKrDkdejLj2s4SyadG")))
(is (string-equal "b3e6f3b9b75b5fc2097f076c54cbd66d0d8a2b4c01723dd3e48bf85c1b38e409"
(bytes->hex-string (geta multisig-info :secret-view-key))))
(is (string-equal "156d6f3561c4ff39deda45d6ef841246a8ef9a4836e4fd103d7fa4bb7feb7ced"
(bytes->hex-string (geta multisig-info :public-signer-key))))))
(test make-multisig-extra-info
(flet ((string=-no-sig (x y)
(string= x y :end1 (- (length x) 128) :end2 (- (length y) 128))))
(let ((multisig-keys (map 'vector
#'hex-string->bytes
#("ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302"
"f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07"))))
(is (string=-no-sig "MultisigxV1B2HV6651uKBCHqqUYg3aQwaKrpm8Vdbu1ApYBeyxcEnSV163PF3KF4HjEegBM9Y36iQJtbd5W4BDJ1BhyGCuhE3AiDf6VpWP5gE4QcwTTjEbCTgS1xpWwhYs9gh6oJdTrFBPVbdRfcf9EC6XTrT4UwDtfNchktG4LErSCHxrq2tZtirCFED5B41YoxtcoVJjUoaFdWDk9DCW3BXXZUzqQZeLLriK"
(make-multisig-extra-info multisig-keys))))
(let ((multisig-keys (map 'vector
#'hex-string->bytes
#("ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302"
"b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08"))))
(is (string=-no-sig "MultisigxV1dKNJHKg34Yja8Mef3fkswXAszjskHbs7PVAReAG74PMDV163PF3KF4HjEegBM9Y36iQJtbd5W4BDJ1BhyGCuhE3A1p1sHTeyeHGb4pu6x9ScKvAjuEzwgAe8D8hMyhWjQyQE1YJed5NXQWpji7S4cAHq53cEtkVjydF1ALHYzMs1F2gYd2whUWuFJf4ZPonVdg4hb1hc8k4u79WA1PpS9y37nco6"
(make-multisig-extra-info multisig-keys))))
(let ((multisig-keys (map 'vector
#'hex-string->bytes
#("f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07"
"b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08"))))
(is (string=-no-sig "MultisigxV1gwsG1Ys15VfFQRNUd1LeNfYXzC9XtmTvJLcpxPzhRBF1iDf6VpWP5gE4QcwTTjEbCTgS1xpWwhYs9gh6oJdTrFBP1p1sHTeyeHGb4pu6x9ScKvAjuEzwgAe8D8hMyhWjQyQEb9VH6YrT69raSwU7fjnQuyMD5vPeKn9Hqe4VEGz2qdaNWvMx3cXuzqF7xNfbSAZG4JVqesLiFNRc52hV1pDt5JML"
(make-multisig-extra-info multisig-keys))))))
(test decode-multisig-extra-info
(let ((multisig-extra-info (decode-multisig-extra-info "MultisigxV1B2HV6651uKBCHqqUYg3aQwaKrpm8Vdbu1ApYBeyxcEnSV163PF3KF4HjEegBM9Y36iQJtbd5W4BDJ1BhyGCuhE3AiDf6VpWP5gE4QcwTTjEbCTgS1xpWwhYs9gh6oJdTrFBPVbdRfcf9EC6XTrT4UwDtfNchktG4LErSCHxrq2tZtirCFED5B41YoxtcoVJjUoaFdWDk9DCW3BXXZUzqQZeLLriK")))
(is (string-equal "3beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47"
(bytes->hex-string (geta multisig-extra-info :public-signer-key))))
(is (equalp #("a768f72c3d0c4be6fc82329c99d1d66b8b5a2103c8ffd4f9011a860da6e5ac71"
"f66d79e30d769593145edae7e2aa0ac8ebbe951a827ddab8ed4c9b9a593d185a")
(map 'vector #'bytes->hex-string (geta multisig-extra-info :multisig-public-keys)))))
(let ((multisig-extra-info (decode-multisig-extra-info "MultisigxV1dKNJHKg34Yja8Mef3fkswXAszjskHbs7PVAReAG74PMDV163PF3KF4HjEegBM9Y36iQJtbd5W4BDJ1BhyGCuhE3A1p1sHTeyeHGb4pu6x9ScKvAjuEzwgAe8D8hMyhWjQyQE1YJed5NXQWpji7S4cAHq53cEtkVjydF1ALHYzMs1F2gYd2whUWuFJf4ZPonVdg4hb1hc8k4u79WA1PpS9y37nco6")))
(is (string-equal "d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a4"
(bytes->hex-string (geta multisig-extra-info :public-signer-key))))
(is (equalp #("a768f72c3d0c4be6fc82329c99d1d66b8b5a2103c8ffd4f9011a860da6e5ac71"
"04d8a58ac5eb2f33cbaac5faf350523d3a3acb77fa05092e2e02bef831993c7b")
(map 'vector #'bytes->hex-string (geta multisig-extra-info :multisig-public-keys)))))
(let ((multisig-extra-info (decode-multisig-extra-info "MultisigxV1gwsG1Ys15VfFQRNUd1LeNfYXzC9XtmTvJLcpxPzhRBF1iDf6VpWP5gE4QcwTTjEbCTgS1xpWwhYs9gh6oJdTrFBP1p1sHTeyeHGb4pu6x9ScKvAjuEzwgAe8D8hMyhWjQyQEb9VH6YrT69raSwU7fjnQuyMD5vPeKn9Hqe4VEGz2qdaNWvMx3cXuzqF7xNfbSAZG4JVqesLiFNRc52hV1pDt5JML")))
(is (string-equal "eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb4974"
(bytes->hex-string (geta multisig-extra-info :public-signer-key))))
(is (equalp #("f66d79e30d769593145edae7e2aa0ac8ebbe951a827ddab8ed4c9b9a593d185a"
"04d8a58ac5eb2f33cbaac5faf350523d3a3acb77fa05092e2e02bef831993c7b")
(map 'vector #'bytes->hex-string (geta multisig-extra-info :multisig-public-keys))))))
(test make-multisig-seed
(let ((threshold 2)
(total 3)
(secret-spend-key (hex-string->bytes "a0e1217efc88057244e140eeea8d3279582bd540e9d895417e23d47869e29f09"))
(public-spend-key (hex-string->bytes "aeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb9373"))
(secret-view-key (hex-string->bytes "7da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b"))
(public-view-key (hex-string->bytes "2d90d31aa9903d3e45b17fbc849b6c95e4d08c3694b721219f1a08208bd7af61"))
(multisig-keys (map 'vector
#'hex-string->bytes
#("ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302"
"f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07")))
(signers (map 'vector
#'hex-string->bytes
#("3beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47"
"eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb4974"
"d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a4"))))
(is (string-equal "0200000003000000a0e1217efc88057244e140eeea8d3279582bd540e9d895417e23d47869e29f09aeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb93737da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b2d90d31aa9903d3e45b17fbc849b6c95e4d08c3694b721219f1a08208bd7af61ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c073beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb4974d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a4"
(bytes->hex-string (make-multisig-seed threshold
total
secret-spend-key
public-spend-key
secret-view-key
public-view-key
multisig-keys
signers)))))
(let ((threshold 2)
(total 3)
(secret-spend-key (hex-string->bytes "627716ec18a622171e639cdc8349be9e85c24a124f0ab301c763838b0db4400b"))
(public-spend-key (hex-string->bytes "aeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb9373"))
(secret-view-key (hex-string->bytes "7da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b"))
(public-view-key (hex-string->bytes "2d90d31aa9903d3e45b17fbc849b6c95e4d08c3694b721219f1a08208bd7af61"))
(multisig-keys (map 'vector
#'hex-string->bytes
#("ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302"
"b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08")))
(signers (map 'vector
#'hex-string->bytes
#("d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a4"
"eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb4974"
"3beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47"))))
(is (string-equal "0200000003000000627716ec18a622171e639cdc8349be9e85c24a124f0ab301c763838b0db4400baeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb93737da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b2d90d31aa9903d3e45b17fbc849b6c95e4d08c3694b721219f1a08208bd7af61ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a4eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb49743beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47"
(bytes->hex-string (make-multisig-seed threshold
total
secret-spend-key
public-spend-key
secret-view-key
public-view-key
multisig-keys
signers)))))
(let ((threshold 2)
(total 3)
(secret-spend-key (hex-string->bytes "a80d07f8df835312b683fc491b5042a42db171e26e4453ba0ad8b2142453ba0f"))
(public-spend-key (hex-string->bytes "aeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb9373"))
(secret-view-key (hex-string->bytes "7da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b"))
(public-view-key (hex-string->bytes "2d90d31aa9903d3e45b17fbc849b6c95e4d08c3694b721219f1a08208bd7af61"))
(multisig-keys (map 'vector
#'hex-string->bytes
#("f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07"
"b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08")))
(signers (map 'vector
#'hex-string->bytes
#("eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb4974"
"d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a4"
"3beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47"))))
(is (string-equal "0200000003000000a80d07f8df835312b683fc491b5042a42db171e26e4453ba0ad8b2142453ba0faeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb93737da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b2d90d31aa9903d3e45b17fbc849b6c95e4d08c3694b721219f1a08208bd7af61f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb4974d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a43beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47"
(bytes->hex-string (make-multisig-seed threshold
total
secret-spend-key
public-spend-key
secret-view-key
public-view-key
multisig-keys
signers)))))
(let ((threshold 2)
(total 2)
(secret-spend-key (hex-string->bytes "367c0246bc866ac8e559cecd9f7890a9d96ec790b336347c5f56f99c00796900"))
(public-spend-key (hex-string->bytes "2297d23c0c69d8cf76464277ceb31e6b0777750308ecfbc49667fd2ebea67bf0"))
(secret-view-key (hex-string->bytes "bda1410fbb9ad7690e8eddc98d6d77c326cfb6766ad126df4b97a076979a6f02"))
(public-view-key (hex-string->bytes "deba7c0440e2e7f7da4fa77470e98f339089d3fe0c609209b4a388266451d1c9"))
(multisig-keys (map 'vector
#'hex-string->bytes
#("367c0246bc866ac8e559cecd9f7890a9d96ec790b336347c5f56f99c00796900")))
(signers (map 'vector
#'hex-string->bytes
#("156d6f3561c4ff39deda45d6ef841246a8ef9a4836e4fd103d7fa4bb7feb7ced"
"ce57400743c11f83b09b94ac3be9b23f5b9b756a3472d0fdf129f12475a8ebb8"))))
(is (string-equal "0200000002000000367c0246bc866ac8e559cecd9f7890a9d96ec790b336347c5f56f99c007969002297d23c0c69d8cf76464277ceb31e6b0777750308ecfbc49667fd2ebea67bf0bda1410fbb9ad7690e8eddc98d6d77c326cfb6766ad126df4b97a076979a6f02deba7c0440e2e7f7da4fa77470e98f339089d3fe0c609209b4a388266451d1c9367c0246bc866ac8e559cecd9f7890a9d96ec790b336347c5f56f99c00796900156d6f3561c4ff39deda45d6ef841246a8ef9a4836e4fd103d7fa4bb7feb7cedce57400743c11f83b09b94ac3be9b23f5b9b756a3472d0fdf129f12475a8ebb8"
(bytes->hex-string (make-multisig-seed threshold
total
secret-spend-key
public-spend-key
secret-view-key
public-view-key
multisig-keys
signers)))))
(let ((threshold 2)
(total 2)
(secret-spend-key (hex-string->bytes "5b84e7b1469852fe1bf19f6057cfd72f22a84381d259f522d7f573112517750c"))
(public-spend-key (hex-string->bytes "2297d23c0c69d8cf76464277ceb31e6b0777750308ecfbc49667fd2ebea67bf0"))
(secret-view-key (hex-string->bytes "bda1410fbb9ad7690e8eddc98d6d77c326cfb6766ad126df4b97a076979a6f02"))
(public-view-key (hex-string->bytes "deba7c0440e2e7f7da4fa77470e98f339089d3fe0c609209b4a388266451d1c9"))
(multisig-keys (map 'vector
#'hex-string->bytes
#("5b84e7b1469852fe1bf19f6057cfd72f22a84381d259f522d7f573112517750c")))
(signers (map 'vector
#'hex-string->bytes
#("ce57400743c11f83b09b94ac3be9b23f5b9b756a3472d0fdf129f12475a8ebb8"
"156d6f3561c4ff39deda45d6ef841246a8ef9a4836e4fd103d7fa4bb7feb7ced"))))
(is (string-equal "02000000020000005b84e7b1469852fe1bf19f6057cfd72f22a84381d259f522d7f573112517750c2297d23c0c69d8cf76464277ceb31e6b0777750308ecfbc49667fd2ebea67bf0bda1410fbb9ad7690e8eddc98d6d77c326cfb6766ad126df4b97a076979a6f02deba7c0440e2e7f7da4fa77470e98f339089d3fe0c609209b4a388266451d1c95b84e7b1469852fe1bf19f6057cfd72f22a84381d259f522d7f573112517750cce57400743c11f83b09b94ac3be9b23f5b9b756a3472d0fdf129f12475a8ebb8156d6f3561c4ff39deda45d6ef841246a8ef9a4836e4fd103d7fa4bb7feb7ced"
(bytes->hex-string (make-multisig-seed threshold
total
secret-spend-key
public-spend-key
secret-view-key
public-view-key
multisig-keys
signers))))))
(test decode-multisig-seed
(let* ((info (decode-multisig-seed "0200000003000000a0e1217efc88057244e140eeea8d3279582bd540e9d895417e23d47869e29f09aeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb93737da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b2d90d31aa9903d3e45b17fbc849b6c95e4d08c3694b721219f1a08208bd7af61ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c073beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb4974d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a4"))
(threshold (geta info :threshold))
(total (geta info :total))
(secret-spend-key (bytes->hex-string (geta info :secret-spend-key)))
(public-spend-key (bytes->hex-string (geta info :public-spend-key)))
(secret-view-key (bytes->hex-string (geta info :secret-view-key)))
(public-view-key (bytes->hex-string (geta info :public-view-key)))
(multisig-keys (map 'vector #'bytes->hex-string (geta info :multisig-keys)))
(signers (map 'vector #'bytes->hex-string (geta info :signers))))
(is (= 2 threshold))
(is (= 3 total))
(is (string-equal "a0e1217efc88057244e140eeea8d3279582bd540e9d895417e23d47869e29f09"
secret-spend-key))
(is (string-equal "aeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb9373"
public-spend-key))
(is (string-equal "7da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b"
secret-view-key))
(is (string-equal "2d90d31aa9903d3e45b17fbc849b6c95e4d08c3694b721219f1a08208bd7af61"
public-view-key))
(is (equalp #("ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302"
"f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07")
multisig-keys))
(is (equalp #("3beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47"
"eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb4974"
"d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a4")
signers)))
(let* ((info (decode-multisig-seed "0200000003000000627716ec18a622171e639cdc8349be9e85c24a124f0ab301c763838b0db4400baeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb93737da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b2d90d31aa9903d3e45b17fbc849b6c95e4d08c3694b721219f1a08208bd7af61ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a4eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb49743beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47"))
(threshold (geta info :threshold))
(total (geta info :total))
(secret-spend-key (bytes->hex-string (geta info :secret-spend-key)))
(public-spend-key (bytes->hex-string (geta info :public-spend-key)))
(secret-view-key (bytes->hex-string (geta info :secret-view-key)))
(public-view-key (bytes->hex-string (geta info :public-view-key)))
(multisig-keys (map 'vector #'bytes->hex-string (geta info :multisig-keys)))
(signers (map 'vector #'bytes->hex-string (geta info :signers))))
(is (= 2 threshold))
(is (= 3 total))
(is (string-equal "627716ec18a622171e639cdc8349be9e85c24a124f0ab301c763838b0db4400b"
secret-spend-key))
(is (string-equal "aeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb9373"
public-spend-key))
(is (string-equal "7da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b"
secret-view-key))
(is (string-equal "2d90d31aa9903d3e45b17fbc849b6c95e4d08c3694b721219f1a08208bd7af61"
public-view-key))
(is (equalp #("ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302"
"b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08")
multisig-keys))
(is (equalp #("d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a4"
"eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb4974"
"3beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47")
signers)))
(let* ((info (decode-multisig-seed "0200000003000000a80d07f8df835312b683fc491b5042a42db171e26e4453ba0ad8b2142453ba0faeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb93737da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b2d90d31aa9903d3e45b17fbc849b6c95e4d08c3694b721219f1a08208bd7af61f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb4974d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a43beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47"))
(threshold (geta info :threshold))
(total (geta info :total))
(secret-spend-key (bytes->hex-string (geta info :secret-spend-key)))
(public-spend-key (bytes->hex-string (geta info :public-spend-key)))
(secret-view-key (bytes->hex-string (geta info :secret-view-key)))
(public-view-key (bytes->hex-string (geta info :public-view-key)))
(multisig-keys (map 'vector #'bytes->hex-string (geta info :multisig-keys)))
(signers (map 'vector #'bytes->hex-string (geta info :signers))))
(is (= 2 threshold))
(is (= 3 total))
(is (string-equal "a80d07f8df835312b683fc491b5042a42db171e26e4453ba0ad8b2142453ba0f"
secret-spend-key))
(is (string-equal "aeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb9373"
public-spend-key))
(is (string-equal "7da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b"
secret-view-key))
(is (string-equal "2d90d31aa9903d3e45b17fbc849b6c95e4d08c3694b721219f1a08208bd7af61"
public-view-key))
(is (equalp #("f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07"
"b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08")
multisig-keys))
(is (equalp #("eed245dba37aae0e561d5b0ecd5f11d4bc87ea454eb8aa0b75495dc2a5fb4974"
"d91f8b4ba3bed51cc60d67ba59611dba3b1067264432812aa85f60bc784b95a4"
"3beb20d20b3dc70e4380324667fd63f0c73cf34ea1a1c6d03ab527e86aa8ab47")
signers)))
(let* ((info (decode-multisig-seed "0200000002000000367c0246bc866ac8e559cecd9f7890a9d96ec790b336347c5f56f99c007969002297d23c0c69d8cf76464277ceb31e6b0777750308ecfbc49667fd2ebea67bf0bda1410fbb9ad7690e8eddc98d6d77c326cfb6766ad126df4b97a076979a6f02deba7c0440e2e7f7da4fa77470e98f339089d3fe0c609209b4a388266451d1c9367c0246bc866ac8e559cecd9f7890a9d96ec790b336347c5f56f99c00796900156d6f3561c4ff39deda45d6ef841246a8ef9a4836e4fd103d7fa4bb7feb7cedce57400743c11f83b09b94ac3be9b23f5b9b756a3472d0fdf129f12475a8ebb8"))
(threshold (geta info :threshold))
(total (geta info :total))
(secret-spend-key (bytes->hex-string (geta info :secret-spend-key)))
(public-spend-key (bytes->hex-string (geta info :public-spend-key)))
(secret-view-key (bytes->hex-string (geta info :secret-view-key)))
(public-view-key (bytes->hex-string (geta info :public-view-key)))
(multisig-keys (map 'vector #'bytes->hex-string (geta info :multisig-keys)))
(signers (map 'vector #'bytes->hex-string (geta info :signers))))
(is (= 2 threshold))
(is (= 2 total))
(is (string-equal "367c0246bc866ac8e559cecd9f7890a9d96ec790b336347c5f56f99c00796900"
secret-spend-key))
(is (string-equal "2297d23c0c69d8cf76464277ceb31e6b0777750308ecfbc49667fd2ebea67bf0"
public-spend-key))
(is (string-equal "bda1410fbb9ad7690e8eddc98d6d77c326cfb6766ad126df4b97a076979a6f02"
secret-view-key))
(is (string-equal "deba7c0440e2e7f7da4fa77470e98f339089d3fe0c609209b4a388266451d1c9"
public-view-key))
(is (equalp #("367c0246bc866ac8e559cecd9f7890a9d96ec790b336347c5f56f99c00796900")
multisig-keys))
(is (equalp #("156d6f3561c4ff39deda45d6ef841246a8ef9a4836e4fd103d7fa4bb7feb7ced"
"ce57400743c11f83b09b94ac3be9b23f5b9b756a3472d0fdf129f12475a8ebb8")
signers)))
(let* ((info (decode-multisig-seed "02000000020000005b84e7b1469852fe1bf19f6057cfd72f22a84381d259f522d7f573112517750c2297d23c0c69d8cf76464277ceb31e6b0777750308ecfbc49667fd2ebea67bf0bda1410fbb9ad7690e8eddc98d6d77c326cfb6766ad126df4b97a076979a6f02deba7c0440e2e7f7da4fa77470e98f339089d3fe0c609209b4a388266451d1c95b84e7b1469852fe1bf19f6057cfd72f22a84381d259f522d7f573112517750cce57400743c11f83b09b94ac3be9b23f5b9b756a3472d0fdf129f12475a8ebb8156d6f3561c4ff39deda45d6ef841246a8ef9a4836e4fd103d7fa4bb7feb7ced"))
(threshold (geta info :threshold))
(total (geta info :total))
(secret-spend-key (bytes->hex-string (geta info :secret-spend-key)))
(public-spend-key (bytes->hex-string (geta info :public-spend-key)))
(secret-view-key (bytes->hex-string (geta info :secret-view-key)))
(public-view-key (bytes->hex-string (geta info :public-view-key)))
(multisig-keys (map 'vector #'bytes->hex-string (geta info :multisig-keys)))
(signers (map 'vector #'bytes->hex-string (geta info :signers))))
(is (= 2 threshold))
(is (= 2 total))
(is (string-equal "5b84e7b1469852fe1bf19f6057cfd72f22a84381d259f522d7f573112517750c"
secret-spend-key))
(is (string-equal "2297d23c0c69d8cf76464277ceb31e6b0777750308ecfbc49667fd2ebea67bf0"
public-spend-key))
(is (string-equal "bda1410fbb9ad7690e8eddc98d6d77c326cfb6766ad126df4b97a076979a6f02"
secret-view-key))
(is (string-equal "deba7c0440e2e7f7da4fa77470e98f339089d3fe0c609209b4a388266451d1c9"
public-view-key))
(is (equalp #("5b84e7b1469852fe1bf19f6057cfd72f22a84381d259f522d7f573112517750c")
multisig-keys))
(is (equalp #("ce57400743c11f83b09b94ac3be9b23f5b9b756a3472d0fdf129f12475a8ebb8"
"156d6f3561c4ff39deda45d6ef841246a8ef9a4836e4fd103d7fa4bb7feb7ced")
signers))))
| 95,434 | Common Lisp | .lisp | 1,127 | 68.382431 | 633 | 0.719563 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 573a9677fdf60e9d0488619f0d9cd0d375eb792f43c506f5cb65f50065389ce2 | 8,033 | [
-1
] |
8,034 | mine.lisp | glv2_cl-monero-tools/tests/mine.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2018 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-tools-tests)
(def-suite mine-tests
:description "Unit tests for mining functions."
:in monero-tools-tests)
(in-suite mine-tests)
#+sbcl
(test miner
(let ((template-1 "0100d186c49a05418015bb9ae982a1975da7d79277c2705727a56894ba0fb246adaabb1f4632e300000000013d01ff0109c0a710025f391ad90e8b64ef432a0a28d0d9d699189b9c1322248ddbdb699c101a3cd9c3c0a8a5040233b81ac838467f7c59079e80517be1a45de51248a9bd841bf783e0aca7b2d5e2808ece1c023dc61a8cab11504ef1a36c51affeb7eed222cd09c98bf5045e489c23b409c9bc80c2d72f022caa4a9af327b36df136599a104278cf44342b0732bb5ad8c4c3582531add94b80a8d6b90702f9edf7d361176a29d1ce53e890e6ebc1e721d9719d273b69f1eb15d96025c6348088aca3cf02022e5ba472765cb2297f51f1a47aaf5f358cf48e16593c25bfc1880578014a65ed8090cad2c60e021b82a36cde1c9a6103d99ea6ebfb9f82b2547cef8934d8e87cf5e20c098ede9c80e08d84ddcb0102b37974cac8678446a230fb3e1b0ec06d56666bf0bf43dd64ff096a01f5aa2fda80c0caf384a30202a0c492751cb53389c9228f68b1ec1be831fb774a285f06c4ee02053858486e8221012a9fca96074c5216f9622c58c5c95024e53ff579d128913548363cb14d7f637400")
(difficulty-1 1)
(template-3 "0100d186c49a05e2914694b698fb417eebaebad3fed4d13e8f670119c95c6e3fa83c1d4531152000000000013f01ff0309efc02b029c0988ea47eafe15303fe7b37e8f4e15a51273681ecaf2b678745d5161d875a3c096b102021b1c293db480f77f6cfa676bc648cbc9dc41c8721fd2c9a16829d5efd75b884a8087a70e02e17ecb617676a95153fa9dd5fcfdb8bb94bb9eb494025c2575633318c9ad6dbb80c2d72f02109215edd47b2a7994315a3079a03c72ec5a8ab20df0cc5e7a44b6143d85cbc980a8d6b907029537e0e736baa6c8c9890e73a2d01e0194f627ae51619c138729441fa046d6f08088aca3cf0202de5f602b8c1da008da4692d017b1955e5cd41655d13e037e8e40cc61edecbca58090cad2c60e021ef910e155d7216724158f1a6cce3ce9f0e25216b7c0f064328dde2fbabd63e480e08d84ddcb010274450959e6dcce686e7fdb8e319cfca01360a93be70eb91ab6b870384366ba1e80c0caf384a30202bca1c2f25f636a8fa5ce5a9fc7c10e5a29aa9ee5d9c42ada34a1a3fc3ec95bc121010c39712ea3adf6e6fe08ebc970ef277e48b80867208ed2e60e862417a715ba7700")
(difficulty-3 60))
(flet ((miner/hex (template difficulty)
(miner (hex-string->bytes template) 0 0 difficulty)))
(is-true (acceptable-hash-p (compute-block-hash-from-data (miner/hex template-1 difficulty-1) t) difficulty-1))
(is-true (acceptable-hash-p (compute-block-hash-from-data (miner/hex template-3 difficulty-3) t) difficulty-3)))))
| 2,531 | Common Lisp | .lisp | 19 | 128.789474 | 877 | 0.902634 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 4891f66a03875574e67417997e9691fb6d4e21423ef158c7fadda6a2765422c1 | 8,034 | [
-1
] |
8,035 | serialization.lisp | glv2_cl-monero-tools/tests/serialization.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-tools-tests)
(def-suite serialization-tests
:description "Unit tests for (de)serialization functions."
:in monero-tools-tests)
(in-suite serialization-tests)
(test transaction
(let ((non-rct-1 (load-hex-data "txn-c52bfd4006951d18be6f68bc3fd5da8ba982b8f26fa459545a7e13c9299e5cb3.hex"))
(non-rct-2 (load-hex-data "txn-9df4b07f8d8f5f0a90b44d87576491d7ec69a282ed36fe36c27e9c67c46974df.hex"))
(non-rct-several-ring-sizes (load-hex-data "txn-7ccdb8992b73d5fa9b284fef2387a4c8d599dc743685041093194be8187d3787.hex"))
(rct-null (load-hex-data "txn-b2e4dc3ce1951e96310c8bc7dc2a76cac471b3ad6858ef8c6b864062c257518b.hex"))
(rct-full (load-hex-data "txn-140564273396a16135ba0867ded6b7981fdc28bda45c62f993dc51ff26cfb2e5.hex"))
(rct-simple (load-hex-data "txn-467f1914b3f5f4eb52dda02bfd0b70b89722b88063f40889bfba46d3ec78de80.hex"))
(rct-payment-id (load-hex-data "txn-0a989c65415dac7840cd890dd5c514b7bfaadf4041a9144e734aef30e3ffa5ec.hex"))
(rct-encrypted-payment-id (load-hex-data "txn-dcf6d169682f243ab25a627d5540882c39fe376526184fa356ee086a68ae164e.hex"))
(rct-bulletproof-1 (load-hex-data "txn-dced075926833171dd9bd9684949aef89451a54dece9e29a84bd843bf86f09dd.hex"))
(rct-bulletproof-2 (load-hex-data "txn-cf43b200852e0691161e01448e1bcef9595d113b25a9e21342854a4cd7682676.hex"))
(rct-bulletproof-3 (load-hex-data "txn-3c24dc3ec70015789d965a8e516383bf7866e9a46e7665c962ff990e216f51b2.hex"))
(rct-clsag (load-hex-data "txn-5fce7d00cac0b6ca9e9c7d741f8b0fdee6efbd45557cd21c0bd78749193be02f.hex")))
(flet ((reserialize/hex (transaction)
(let ((deserialized (deserialize-transaction (hex-string->bytes transaction) 0)))
(bytes->hex-string (serialize-transaction nil deserialized)))))
(is (string-equal non-rct-1 (reserialize/hex non-rct-1)))
(is (string-equal non-rct-2 (reserialize/hex non-rct-2)))
(is (string-equal non-rct-several-ring-sizes (reserialize/hex non-rct-several-ring-sizes)))
(is (string-equal rct-null (reserialize/hex rct-null)))
(is (string-equal rct-full (reserialize/hex rct-full)))
(is (string-equal rct-simple (reserialize/hex rct-simple)))
(is (string-equal rct-payment-id (reserialize/hex rct-payment-id)))
(is (string-equal rct-encrypted-payment-id (reserialize/hex rct-encrypted-payment-id)))
(is (string-equal rct-bulletproof-1 (reserialize/hex rct-bulletproof-1)))
(is (string-equal rct-bulletproof-2 (reserialize/hex rct-bulletproof-2)))
(is (string-equal rct-bulletproof-3 (reserialize/hex rct-bulletproof-3)))
(is (string-equal rct-clsag (reserialize/hex rct-clsag))))))
(test block
(let ((block-400000 (load-hex-data "blk-400000.hex"))
(block-1000000 (load-hex-data "blk-1000000.hex"))
(block-1300000 (load-hex-data "blk-1300000.hex")))
(flet ((reserialize/hex (block)
(let ((deserialized (deserialize-block (hex-string->bytes block) 0)))
(bytes->hex-string (serialize-block nil deserialized)))))
(is (string-equal block-400000 (reserialize/hex block-400000)))
(is (string-equal block-1000000 (reserialize/hex block-1000000)))
(is (string-equal block-1300000 (reserialize/hex block-1300000))))))
(test binary-storage
(let ((block-400000 (load-hex-data "blk-400000.hex"))
(block-1000000 (load-hex-data "blk-1000000.hex"))
(block-1300000 (load-hex-data "blk-1300000.hex"))
(transaction-hashes-1300000 #("140564273396a16135ba0867ded6b7981fdc28bda45c62f993dc51ff26cfb2e5"
"a32087d20f25e45097da9c899d8ec17df1d7563abe19047b3d115fe894bbf383"
"4d2996d78485bd41980c79a7573e91fb06960a96884eda6b47877be8bc0e4eb4"))
(get-blocks-by-height-bin-answer (load-hex-data "get-blocks-by-height-bin-400000+1000000+1300000.hex")))
(let* ((info (deserialize-from-binary-storage (hex-string->bytes get-blocks-by-height-bin-answer) 0))
(blk-400000 (string->bytes (geta (aref (geta info :blocks) 0) :block)))
(blk-1000000 (string->bytes (geta (aref (geta info :blocks) 1) :block)))
(blk-1300000 (string->bytes (geta (aref (geta info :blocks) 2) :block)))
(txs-1300000 (geta (aref (geta info :blocks) 2) :txs))
(txhs-1300000 (map 'vector
(lambda (tx)
(compute-transaction-hash-from-data (string->bytes tx)))
txs-1300000)))
(is (string-equal block-400000 (bytes->hex-string blk-400000)))
(is (string-equal block-1000000 (bytes->hex-string blk-1000000)))
(is (string-equal block-1300000 (bytes->hex-string blk-1300000)))
(dotimes (i (length transaction-hashes-1300000))
(is (string-equal (aref transaction-hashes-1300000 i)
(bytes->hex-string (aref txhs-1300000 i)))))
(is (string-equal get-blocks-by-height-bin-answer
(bytes->hex-string (serialize-to-binary-storage info)))))))
| 5,300 | Common Lisp | .lisp | 72 | 63.958333 | 127 | 0.700383 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 6369b140a03287bdff1c997dce53f12bb3417e4960c07602c077826488f91a1b | 8,035 | [
-1
] |
8,036 | utils.lisp | glv2_cl-monero-tools/tests/utils.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2017 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-tools-tests)
(def-suite utils-tests
:description "Unit tests for utility functions."
:in monero-tools-tests)
(in-suite utils-tests)
(test base58-encode
(flet ((base58-encode/hex (data)
(base58-encode (hex-string->bytes data))))
(is (string= (base58-encode/hex "00")
"11"))
(is (string= (base58-encode/hex "0000")
"111"))
(is (string= (base58-encode/hex "000000")
"11111"))
(is (string= (base58-encode/hex "00000000")
"111111"))
(is (string= (base58-encode/hex "0000000000")
"1111111"))
(is (string= (base58-encode/hex "000000000000")
"111111111"))
(is (string= (base58-encode/hex "00000000000000")
"1111111111"))
(is (string= (base58-encode/hex "0000000000000000")
"11111111111"))
(is (string= (base58-encode/hex "000000000000000000")
"1111111111111"))
(is (string= (base58-encode/hex "00000000000000000000")
"11111111111111"))
(is (string= (base58-encode/hex "0000000000000000000000")
"1111111111111111"))
(is (string= (base58-encode/hex "000000000000000000000000")
"11111111111111111"))
(is (string= (base58-encode/hex "00000000000000000000000000")
"111111111111111111"))
(is (string= (base58-encode/hex "0000000000000000000000000000")
"11111111111111111111"))
(is (string= (base58-encode/hex "000000000000000000000000000000")
"111111111111111111111"))
(is (string= (base58-encode/hex "00000000000000000000000000000000")
"1111111111111111111111"))
(is (string= (base58-encode/hex "06156013762879f7ffffffffff")
"22222222222VtB5VXc"))))
(test base58-decode
(flet ((base58-decode/hex (data)
(bytes->hex-string (base58-decode data))))
(is (string-equal (base58-decode/hex "")
""))
(is (string-equal (base58-decode/hex "5Q")
"ff"))
(is (string-equal (base58-decode/hex "LUv")
"ffff"))
(is (string-equal (base58-decode/hex "2UzHL")
"ffffff"))
(is (string-equal (base58-decode/hex "7YXq9G")
"ffffffff"))
(is (string-equal (base58-decode/hex "VtB5VXc")
"ffffffffff"))
(is (string-equal (base58-decode/hex "3CUsUpv9t")
"ffffffffffff"))
(is (string-equal (base58-decode/hex "Ahg1opVcGW")
"ffffffffffffff"))
(is (string-equal (base58-decode/hex "jpXCZedGfVQ")
"ffffffffffffffff"))
(is (string-equal (base58-decode/hex "jpXCZedGfVQ5Q")
"ffffffffffffffffff"))
(is (string-equal (base58-decode/hex "jpXCZedGfVQLUv")
"ffffffffffffffffffff"))
(is (string-equal (base58-decode/hex "jpXCZedGfVQ2UzHL")
"ffffffffffffffffffffff"))
(is (string-equal (base58-decode/hex "jpXCZedGfVQ7YXq9G")
"ffffffffffffffffffffffff"))
(is (string-equal (base58-decode/hex "jpXCZedGfVQVtB5VXc")
"ffffffffffffffffffffffffff"))
(is (string-equal (base58-decode/hex "jpXCZedGfVQ3CUsUpv9t")
"ffffffffffffffffffffffffffff"))
(is (string-equal (base58-decode/hex "jpXCZedGfVQAhg1opVcGW")
"ffffffffffffffffffffffffffffff"))
(is (string-equal (base58-decode/hex "jpXCZedGfVQjpXCZedGfVQ")
"ffffffffffffffffffffffffffffffff"))))
| 3,834 | Common Lisp | .lisp | 83 | 35.120482 | 71 | 0.598291 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | e7fba9e11c086fe076fb3ed9e9c54b933f6ec5721cf02da24e61412d642dfd38 | 8,036 | [
-1
] |
8,037 | mnemonic.lisp | glv2_cl-monero-tools/tests/mnemonic.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2017 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-tools-tests)
(def-suite mnemonic-tests
:description "Unit tests for mnemonic seed functions."
:in monero-tools-tests)
(in-suite mnemonic-tests)
(test secret-key->mnemonic-seed
(flet ((secret-key->mnemonic-seed/hex (secret-key language)
(secret-key->mnemonic-seed (hex-string->bytes secret-key) language)))
(is (string-equal "dedicated dubbed coexist having damp ember feline inquest september nobody alley binocular lopped moat agreed wayside gotten bays layout nail vixen imagine weird yahoo moat"
(secret-key->mnemonic-seed/hex "f61b1df1b8bc17126ebd95587494fb128a39217dd468e6bea57f2263626c1306" :english)))
(is (string-equal "brave visuel version tango davantage baobab quinze essai peau tellement balcon brevet tasse ordinaire rhume lueur oreille version stock agonie salon scoop rouge seuil peau"
(secret-key->mnemonic-seed/hex "b50710fdc751efdd2602635a0e271d0af6744a2bf58ca15a138dd6ca5ad78d0a" :french)))))
(test mnemonic-seed->secret-key
(flet ((mnemonic-seed->secret-key/hex (mnemonic-seed language)
(bytes->hex-string (mnemonic-seed->secret-key mnemonic-seed language))))
(is (string-equal "f61b1df1b8bc17126ebd95587494fb128a39217dd468e6bea57f2263626c1306"
(mnemonic-seed->secret-key/hex "dedicated dubbed coexist having damp ember feline inquest september nobody alley binocular lopped moat agreed wayside gotten bays layout nail vixen imagine weird yahoo moat" :english)))
(is (string-equal "b50710fdc751efdd2602635a0e271d0af6744a2bf58ca15a138dd6ca5ad78d0a"
(mnemonic-seed->secret-key/hex "brave visuel version tango davantage baobab quinze essai peau tellement balcon brevet tasse ordinaire rhume lueur oreille version stock agonie salon scoop rouge seuil peau" :french)))))
(test encrypt-mnemonic-seed
(is (string-equal "unbending bogeys bowling tender sorry upcoming textbook nozzle shackles vein sneeze cage sensible oaks fitting agreed upstairs onboard reunion obliged punch fifteen emotion firm sorry"
(encrypt-mnemonic-seed "dialect enough negative umbrella gourmet january tissue army sanity nugget against foxes nearby hobby alerts puddle unlikely noodles jolted citadel below vocal dauntless edited hobby"
"SomePassword"
:english)))
(is (string-equal "juerga casero jarra masivo poeta dirigir grúa iris pésimo revés lógica caer lombriz gajo explicar parar emoción minero ceniza oveja olmo lucir mito negar iris"
(encrypt-mnemonic-seed "boca lunes activo padre agua recreo inicio razón pichón gallo este canica curva carro bozal puerta perfil crisis pequeño farsa jungla mueble orilla pasar recreo"
"456uhbzerjkl951"
:spanish)))
(is (string-equal "いけん おどり うれしい うんちん つわり とのさま げこう なわとび こふう ぬくもり せつぶん いやす こうじ うすめる のせる いせかい せんさい おかわり たぶん とおる なっとう どうぐ てんし なふだ いけん"
(encrypt-mnemonic-seed "けまり こんいん ちへいせん おいかける だむる くいず ていねい しむける たまる いきる しゃこ げんぶつ そつえん げつようび あずかる せもたれ あんがい いちりゅう ぬいくぎ とさか あまり てれび てきとう ととのえる だむる"
"キーがテーブルにあります"
:japanese))))
(test decrypt-mnemonic-seed
(is (string-equal "dialect enough negative umbrella gourmet january tissue army sanity nugget against foxes nearby hobby alerts puddle unlikely noodles jolted citadel below vocal dauntless edited hobby"
(decrypt-mnemonic-seed "unbending bogeys bowling tender sorry upcoming textbook nozzle shackles vein sneeze cage sensible oaks fitting agreed upstairs onboard reunion obliged punch fifteen emotion firm sorry"
"SomePassword"
:english)))
(is (string-equal "boca lunes activo padre agua recreo inicio razón pichón gallo este canica curva carro bozal puerta perfil crisis pequeño farsa jungla mueble orilla pasar recreo"
(decrypt-mnemonic-seed "juerga casero jarra masivo poeta dirigir grúa iris pésimo revés lógica caer lombriz gajo explicar parar emoción minero ceniza oveja olmo lucir mito negar iris"
"456uhbzerjkl951"
:spanish)))
(is (string-equal "けまり こんいん ちへいせん おいかける だむる くいず ていねい しむける たまる いきる しゃこ げんぶつ そつえん げつようび あずかる せもたれ あんがい いちりゅう ぬいくぎ とさか あまり てれび てきとう ととのえる だむる"
(decrypt-mnemonic-seed "いけん おどり うれしい うんちん つわり とのさま げこう なわとび こふう ぬくもり せつぶん いやす こうじ うすめる のせる いせかい せんさい おかわり たぶん とおる なっとう どうぐ てんし なふだ いけん"
"キーがテーブルにあります"
:japanese))))
| 5,815 | Common Lisp | .lisp | 49 | 85.428571 | 239 | 0.691626 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 87dfac69c2dd3b435f3505dc3686a969b4c78760672c1840a9d781d9cf70f4c4 | 8,037 | [
-1
] |
8,038 | tests.lisp | glv2_cl-monero-tools/tests/tests.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(defpackage :monero-tools-tests
(:use :cl :fiveam :iterate :monero-tools :monero-utils))
(in-package :monero-tools-tests)
(def-suite monero-tools-tests
:description "Unit tests for monero-tools.")
(in-suite monero-tools-tests)
(defun data-file-path (filename)
(asdf:system-relative-pathname "monero-tools-tests"
(concatenate 'string "tests/data/" filename)))
(defun load-hex-data (filename)
(with-open-file (in (data-file-path filename))
(read-line in)))
| 703 | Common Lisp | .lisp | 16 | 39.625 | 79 | 0.71134 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | eebc4ae7b30c9c8cbbeeea7e7c55b6aa6c5e78589ee361369808b48ca93f1ad6 | 8,038 | [
-1
] |
8,039 | blockchain.lisp | glv2_cl-monero-tools/tests/blockchain.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2018 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-tools-tests)
(def-suite blockchain-tests
:description "Unit tests for blockchain functions."
:in monero-tools-tests)
(in-suite blockchain-tests)
(test compute-transaction-hash-from-data
(let ((non-rct-1 (load-hex-data "txn-c52bfd4006951d18be6f68bc3fd5da8ba982b8f26fa459545a7e13c9299e5cb3.hex"))
(non-rct-2 (load-hex-data "txn-9df4b07f8d8f5f0a90b44d87576491d7ec69a282ed36fe36c27e9c67c46974df.hex"))
(rct-null (load-hex-data "txn-b2e4dc3ce1951e96310c8bc7dc2a76cac471b3ad6858ef8c6b864062c257518b.hex"))
(rct-full (load-hex-data "txn-140564273396a16135ba0867ded6b7981fdc28bda45c62f993dc51ff26cfb2e5.hex"))
(rct-simple (load-hex-data "txn-467f1914b3f5f4eb52dda02bfd0b70b89722b88063f40889bfba46d3ec78de80.hex"))
(rct-bulletproof-1 (load-hex-data "txn-dced075926833171dd9bd9684949aef89451a54dece9e29a84bd843bf86f09dd.hex"))
(rct-bulletproof-2 (load-hex-data "txn-cf43b200852e0691161e01448e1bcef9595d113b25a9e21342854a4cd7682676.hex"))
(rct-bulletproof-3 (load-hex-data "txn-3c24dc3ec70015789d965a8e516383bf7866e9a46e7665c962ff990e216f51b2.hex")))
(flet ((compute-hash/hex (transaction)
(let ((transaction-data (hex-string->bytes transaction)))
(bytes->hex-string (compute-transaction-hash-from-data transaction-data)))))
(is (string-equal "c52bfd4006951d18be6f68bc3fd5da8ba982b8f26fa459545a7e13c9299e5cb3"
(compute-hash/hex non-rct-1)))
(is (string-equal "9df4b07f8d8f5f0a90b44d87576491d7ec69a282ed36fe36c27e9c67c46974df"
(compute-hash/hex non-rct-2)))
(is (string-equal "b2e4dc3ce1951e96310c8bc7dc2a76cac471b3ad6858ef8c6b864062c257518b"
(compute-hash/hex rct-null)))
(is (string-equal "140564273396a16135ba0867ded6b7981fdc28bda45c62f993dc51ff26cfb2e5"
(compute-hash/hex rct-full)))
(is (string-equal "467f1914b3f5f4eb52dda02bfd0b70b89722b88063f40889bfba46d3ec78de80"
(compute-hash/hex rct-simple)))
(is (string-equal "dced075926833171dd9bd9684949aef89451a54dece9e29a84bd843bf86f09dd"
(compute-hash/hex rct-bulletproof-1)))
(is (string-equal "cf43b200852e0691161e01448e1bcef9595d113b25a9e21342854a4cd7682676"
(compute-hash/hex rct-bulletproof-2)))
(is (string-equal "3c24dc3ec70015789d965a8e516383bf7866e9a46e7665c962ff990e216f51b2"
(compute-hash/hex rct-bulletproof-3))))))
(test compute-miner-transaction-hash-from-data
(let ((block-400000 (load-hex-data "blk-400000.hex"))
(block-1000000 (load-hex-data "blk-1000000.hex"))
(block-1300000 (load-hex-data "blk-1300000.hex")))
(flet ((compute-hash/hex (block)
(let ((block-data (hex-string->bytes block)))
(bytes->hex-string (compute-miner-transaction-hash-from-data block-data)))))
(is (string-equal "c52bfd4006951d18be6f68bc3fd5da8ba982b8f26fa459545a7e13c9299e5cb3"
(compute-hash/hex block-400000)))
(is (string-equal "eb4670d141a7474b07426c34f5cd0cb54dfd5bade712abdec5dbd9f8cf0fc958"
(compute-hash/hex block-1000000)))
(is (string-equal "b2e4dc3ce1951e96310c8bc7dc2a76cac471b3ad6858ef8c6b864062c257518b"
(compute-hash/hex block-1300000))))))
(test compute-block-hash-from-data
(let ((block-400000 (load-hex-data "blk-400000.hex"))
(block-1000000 (load-hex-data "blk-1000000.hex"))
(block-1300000 (load-hex-data "blk-1300000.hex")))
(flet ((compute-hash/hex (block)
(let ((block-data (hex-string->bytes block)))
(bytes->hex-string (compute-block-hash-from-data block-data)))))
(is (string-equal "1b2b0e7a30e59691491529a3d506d1ba3d6052d0f6b52198b7330b28a6f1b6ac"
(compute-hash/hex block-400000)))
(is (string-equal "a886ef5149902d8342475fee9bb296341b891ac67c4842f47a833f23c00ed721"
(compute-hash/hex block-1000000)))
(is (string-equal "31b34272343a44a9f4ac7de7a8fcf3b7d8a3124d7d6870affd510d2f37e74cd0"
(compute-hash/hex block-1300000))))))
(test acceptable-hash-p
(let ((block-400000 (load-hex-data "blk-400000.hex"))
(difficulty-400000 778257991)
(block-1000000 (load-hex-data "blk-1000000.hex"))
(difficulty-1000000 897275644)
(block-1300000 (load-hex-data "blk-1300000.hex"))
(difficulty-1300000 7877790006))
(flet ((hash/hex (block)
(compute-block-hash-from-data (hex-string->bytes block) t)))
(is-true (acceptable-hash-p (hash/hex block-400000) difficulty-400000))
(is-true (acceptable-hash-p (hash/hex block-1000000) difficulty-1000000))
(is-true (acceptable-hash-p (hash/hex block-1300000) difficulty-1300000))
(is-false (acceptable-hash-p (hash/hex block-400000) difficulty-1300000)))))
| 5,160 | Common Lisp | .lisp | 76 | 57.605263 | 119 | 0.706601 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 65ca7b332cc043a04d52f91be76b1b6d3703ef4260c06fc87bc29c0aa6f8c7d4 | 8,039 | [
-1
] |
8,040 | openalias.lisp | glv2_cl-monero-tools/tests/openalias.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2018 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-tools-tests)
(def-suite openalias-tests
:description "Unit tests for openalias functions."
:in monero-tools-tests)
(in-suite openalias-tests)
(test get-openalias-info
(multiple-value-bind (info dnssec-validated)
(get-openalias-info "donate.getmonero.org")
(is (string= "44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A"
(geta info :address)))
(is (string= "Monero Development"
(geta info :recipient-name)))
(is (string= "Donation to Monero Core Team"
(geta info :description)))
(is-true dnssec-validated)))
| 849 | Common Lisp | .lisp | 19 | 39.210526 | 114 | 0.717233 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | c04525f8cdab1f8dda7a2fafc5e63aca993e0cb3c4a263dd0c431f5a13d0d246 | 8,040 | [
-1
] |
8,041 | crypto.lisp | glv2_cl-monero-tools/tests/crypto.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-tools-tests)
(def-suite crypto-tests
:description "Unit tests for crypto functions."
:in monero-tools-tests)
(in-suite crypto-tests)
(test fast-hash
(flet ((fast-hash/hex (data)
(bytes->hex-string (fast-hash (hex-string->bytes data)))))
(is (string-equal "7591f4d8ff9d86ea44873e89a5fb6f380f4410be6206030010567ac9d0d4b0e1"
(fast-hash/hex "01009091e4aa05ff5fe4801727ed0c1b8b339e1a0054d75568fec6ba9c4346e88b10d59edbf6858b2b00008a63b2865b65b84d28bb31feb057b16a21e2eda4bf6cc6377e3310af04debe4a01")))
(is (string-equal "5ff8734db3f9977eee9cf5e2cf725c57af09926490c55abd9d00a42e91a8c344"
(fast-hash/hex "36f9f0a65f2ca498d739b944d6eff3da5ebba57e7d9c41598a2b0e4380f3cf4b479ec2348d015ffe6256273511154afcf3b4b4bf09d6c4744fdd0f62d75079d440706b05")))
(is (string-equal "eead6dbfc7340a56caedc044696a168870549a6a7f6f56961e84a54bd9970b8a"
(fast-hash/hex "cc")))
(is (string-equal "a8eaceda4d47b3281a795ad9e1ea2122b407baf9aabcb9e18b5717b7873537d2"
(fast-hash/hex "41fb")))
(is (string-equal "e620d8f2982b24fedaaa3baa9b46c3f9ce204ee356666553ecb35e15c3ff9bf9"
(fast-hash/hex "4a4f202484512526")))
(is (string-equal "d61708bdb3211a9aab28d4df01dfa4b29ed40285844d841042257e97488617b0"
(fast-hash/hex "eaeed5cdffd89dece455f1")))
(is (string-equal "a6d5444cb7aa61f5106cdedb39d5e1dd7d608f102798d7e818ac87289123a1db"
(fast-hash/hex "75683dcb556140c522543bb6e9098b21a21e")))
(is (string-equal "aeef4b4da420834ffced26db291248fb2d01e765e2b0564057f8e6c2030ac37f"
(fast-hash/hex "0f8b2d8fcfd9d68cffc17ccfb117709b53d26462a3f346fb7c79b85e")))
(is (string-equal "9a0c1d50a59dbf657f6713c795ed14e1f23b4eaa137c5540aacdb0a7e32c29fc"
(fast-hash/hex "512a6d292e67ecb2fe486bfe92660953a75484ff4c4f2eca2b0af0edcdd4339c6b2ee4e542")))
(is (string-equal "81147cba0647eee78c4784874c0557621a138ca781fb6f5dcd0d9c609af56f35"
(fast-hash/hex "ec0f99711016c6a2a07ad80d16427506ce6f441059fd269442baaa28c6ca037b22eeac49d5d894c0bf66219f2c08e9d0e8ab21de52")))))
(test slow-hash
(flet ((slow-hash/hex (data)
(bytes->hex-string (slow-hash (hex-string->bytes data)))))
(is (string-equal "a70a96f64a266f0f59e4f67c4a92f24fe8237c1349f377fd2720c9e1f2970400"
(slow-hash/hex "01009091e4aa05ff5fe4801727ed0c1b8b339e1a0054d75568fec6ba9c4346e88b10d59edbf6858b2b00008a63b2865b65b84d28bb31feb057b16a21e2eda4bf6cc6377e3310af04debe4a01")))
(is (string-equal "2f8e3df40bd11f9ac90c743ca8e32bb391da4fb98612aa3b6cdc639ee00b31f5"
(slow-hash/hex "6465206f6d6e69627573206475626974616e64756d")))
(is (string-equal "722fa8ccd594d40e4a41f3822734304c8d5eff7e1b528408e2229da38ba553c4"
(slow-hash/hex "6162756e64616e732063617574656c61206e6f6e206e6f636574")))
(is (string-equal "bbec2cacf69866a8e740380fe7b818fc78f8571221742d729d9d02d7f8989b87"
(slow-hash/hex "63617665617420656d70746f72")))
(is (string-equal "b1257de4efc5ce28c6b40ceb1c6c8f812a64634eb3e81c5220bee9b2b76a6f05"
(slow-hash/hex "6578206e6968696c6f206e6968696c20666974")))
(let ((*slow-hash-variant* :cryptonight-variant-1))
(is (string-equal "b5a7f63abb94d07d1a6445c36c07c7e8327fe61b1647e391b4c7edae5de57a3d"
(slow-hash/hex "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000")))
(is (string-equal "80563c40ed46575a9e44820d93ee095e2851aa22483fd67837118c6cd951ba61"
(slow-hash/hex "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")))
(is (string-equal "5bb40c5880cef2f739bdb6aaaf16161eaae55530e7b10d7ea996b751a299e949"
(slow-hash/hex "8519e039172b0d70e5ca7b3383d6b3167315a422747b73f019cf9528f0fde341fd0f2a63030ba6450525cf6de31837669af6f1df8131faf50aaab8d3a7405589")))
(is (string-equal "613e638505ba1fd05f428d5c9f8e08f8165614342dac419adc6a47dce257eb3e"
(slow-hash/hex "37a636d7dafdf259b7287eddca2f58099e98619d2f99bdb8969d7b14498102cc065201c8be90bd777323f449848b215d2977c92c4c1c2da36ab46b2e389689ed97c18fec08cd3b03235c5e4c62a37ad88c7b67932495a71090e85dd4020a9300")))
(is (string-equal "ed082e49dbd5bbe34a3726a0d1dad981146062b39d36d62c71eb1ed8ab49459b"
(slow-hash/hex "38274c97c45a172cfc97679870422e3a1ab0784960c60514d816271415c306ee3a3ed1a77e31f6a885c3cb"))))
(let ((*slow-hash-variant* :cryptonight-variant-2))
(is (string-equal "353fdc068fd47b03c04b9431e005e00b68c2168a3cc7335c8b9b308156591a4f"
(slow-hash/hex "5468697320697320612074657374205468697320697320612074657374205468697320697320612074657374")))
(is (string-equal "72f134fc50880c330fe65a2cb7896d59b2e708a0221c6a9da3f69b3a702d8682"
(slow-hash/hex "4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e67")))
(is (string-equal "410919660ec540fc49d8695ff01f974226a2a28dbbac82949c12f541b9a62d2f"
(slow-hash/hex "656c69742c2073656420646f20656975736d6f642074656d706f7220696e6369646964756e74207574206c61626f7265")))
(is (string-equal "4472fecfeb371e8b7942ce0378c0ba5e6d0c6361b669c587807365c787ae652d"
(slow-hash/hex "657420646f6c6f7265206d61676e6120616c697175612e20557420656e696d206164206d696e696d2076656e69616d2c")))
(is (string-equal "577568395203f1f1225f2982b637f7d5e61b47a0f546ba16d46020b471b74076"
(slow-hash/hex "71756973206e6f737472756420657865726369746174696f6e20756c6c616d636f206c61626f726973206e697369")))
(is (string-equal "f6fd7efe95a5c6c4bb46d9b429e3faf65b1ce439e116742d42b928e61de52385"
(slow-hash/hex "757420616c697175697020657820656120636f6d6d6f646f20636f6e7365717561742e20447569732061757465")))
(is (string-equal "422f8cfe8060cf6c3d9fd66f68e3c9977adb683aea2788029308bbe9bc50d728"
(slow-hash/hex "697275726520646f6c6f7220696e20726570726568656e646572697420696e20766f6c7570746174652076656c6974")))
(is (string-equal "512e62c8c8c833cfbd9d361442cb00d63c0a3fd8964cfd2fedc17c7c25ec2d4b"
(slow-hash/hex "657373652063696c6c756d20646f6c6f726520657520667567696174206e756c6c612070617269617475722e")))
(is (string-equal "12a794c1aa13d561c9c6111cee631ca9d0a321718d67d3416add9de1693ba41e"
(slow-hash/hex "4578636570746575722073696e74206f6363616563617420637570696461746174206e6f6e2070726f6964656e742c")))
(is (string-equal "2659ff95fc74b6215c1dc741e85b7a9710101b30620212f80eb59c3c55993f9d"
(slow-hash/hex "73756e7420696e2063756c706120717569206f666669636961206465736572756e74206d6f6c6c697420616e696d20696420657374206c61626f72756d2e"))))
(let ((*slow-hash-variant* :cryptonight-r))
(let ((*slow-hash-height* 1806260))
(is (string-equal "f759588ad57e758467295443a9bd71490abff8e9dad1b95b6bf2f5d0d78387bc"
(slow-hash/hex "5468697320697320612074657374205468697320697320612074657374205468697320697320612074657374"))))
(let ((*slow-hash-height* 1806261))
(is (string-equal "5bb833deca2bdd7252a9ccd7b4ce0b6a4854515794b56c207262f7a5b9bdb566"
(slow-hash/hex "4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e67"))))
(let ((*slow-hash-height* 1806262))
(is (string-equal "1ee6728da60fbd8d7d55b2b1ade487a3cf52a2c3ac6f520db12c27d8921f6cab"
(slow-hash/hex "656c69742c2073656420646f20656975736d6f642074656d706f7220696e6369646964756e74207574206c61626f7265"))))
(let ((*slow-hash-height* 1806263))
(is (string-equal "6969fe2ddfb758438d48049f302fc2108a4fcc93e37669170e6db4b0b9b4c4cb"
(slow-hash/hex "657420646f6c6f7265206d61676e6120616c697175612e20557420656e696d206164206d696e696d2076656e69616d2c"))))
(let ((*slow-hash-height* 1806264))
(is (string-equal "7f3048b4e90d0cbe7a57c0394f37338a01fae3adfdc0e5126d863a895eb04e02"
(slow-hash/hex "71756973206e6f737472756420657865726369746174696f6e20756c6c616d636f206c61626f726973206e697369"))))
(let ((*slow-hash-height* 1806265))
(is (string-equal "1d290443a4b542af04a82f6b2494a6ee7f20f2754c58e0849032483a56e8e2ef"
(slow-hash/hex "757420616c697175697020657820656120636f6d6d6f646f20636f6e7365717561742e20447569732061757465"))))
(let ((*slow-hash-height* 1806266))
(is (string-equal "c43cc6567436a86afbd6aa9eaa7c276e9806830334b614b2bee23cc76634f6fd"
(slow-hash/hex "697275726520646f6c6f7220696e20726570726568656e646572697420696e20766f6c7570746174652076656c6974"))))
(let ((*slow-hash-height* 1806267))
(is (string-equal "87be2479c0c4e8edfdfaa5603e93f4265b3f8224c1c5946feb424819d18990a4"
(slow-hash/hex "657373652063696c6c756d20646f6c6f726520657520667567696174206e756c6c612070617269617475722e"))))
(let ((*slow-hash-height* 1806268))
(is (string-equal "dd9d6a6d8e47465cceac0877ef889b93e7eba979557e3935d7f86dce11b070f3"
(slow-hash/hex "4578636570746575722073696e74206f6363616563617420637570696461746174206e6f6e2070726f6964656e742c"))))
(let ((*slow-hash-height* 1806269))
(is (string-equal "75c6f2ae49a20521de97285b431e717125847fb8935ed84a61e7f8d36a2c3d8e"
(slow-hash/hex "73756e7420696e2063756c706120717569206f666669636961206465736572756e74206d6f6c6c697420616e696d20696420657374206c61626f72756d2e")))))
(let ((*slow-hash-variant* :randomx))
(let ((*slow-hash-seed* (hex-string->bytes "154eb7a21cd32a597f985644187297607bad491650091620550877239c4178e1"))) ; Seed height 2031616
;; Block 2033333
(is (string-equal "6d6999673d984343456db0c45d9397696f14fb0e4255effaed3d740500000000"
(slow-hash/hex "0c0cebd599f205091810d1db0cf05c946b5d4201dfb84d39bc490df08c0b3da1afcbcdc454826652190d3968d76c0e37abe6fe996d7725c619b0f0029a72e036d7e34180a294bdd353e02006")))
;; Block 2033334
(is (string-equal "2fe153aa7f180d43e8a60b1f58333c8ac8e1f9e8ab58445149d96a0500000000"
(slow-hash/hex "0c0cb2d699f205d66a0d13b2c006ac8a455b793440802ebf9322a8770f4d1b203348d6ab6771e9ecb60100b5de0362c27369af70bc419fd11a1a09fe2b8a991075db2cd0b953c3cbc1e9e810")))
;; Block 2033335
(is (string-equal "5001dadbb1e3f65a94cb395d49960f95be1cfa06dcee53b844aea90400000000"
(slow-hash/hex "0c0cdad799f205dd2a430a4a433a15e16f81369277269873f8934d906f5f09523409651a4d6a3d4187037a7c2c9a7c34108285a15dab3653b2470b2d11063b1635df6583b34158e79d9ce51f"))))
(let ((*slow-hash-seed* (hex-string->bytes "2ad7b6b5509b48e823a0a3076eb6ed71d403cd717500a0e10719cdf3a7ae1165"))) ; Seed height 2033664
;; Block 2035250
(is (string-equal "7842a365c54121eb2cf0f148de1f82b96e3ff8e71349cd61ca3e4a0600000000"
(slow-hash/hex "0c0cebe9a7f20593ab9ac755786a4982ac0641a3439ff888a8c197cddc011c1cc4ca3111f6b169c7e40700a8883e1da616e90f5d1087154c1531a50e08bc82023d37c670c32ffb86b64f6a08")))
;; Block 2035251
(is (string-equal "fefed055d5d187ec7a5fc66b818828d96de19522c2a7ca72ddc3570500000000"
(slow-hash/hex "0c0cafeaa7f20582aae0b23f4e00e1cc9cf8fa165aa372540588967940271410f1ea2729184d8c62230400f84d3ad4d7747470da40be379d97a4179ac3276959c91ae6e2d387b182ff6d0c0a")))
;; Block 2035252
(is (string-equal "99fc73be6d0c864a52779f3a00a257dca5148e9c44885ea83d47c60200000000"
(slow-hash/hex "0c0cb2eba7f205e7b123381798d2a8e96949dc474fd419e11e2b8fc1d04b7ad6c59717bafdc104d20206008bb8cbd49777a3b4a448893c16215d767a41f964b3f60888925ddb2e2de496480f"))))
(let ((*slow-hash-seed* (hex-string->bytes "5a7f09e485cef6c38ed438c71352ec109d3a0abb429ffc799eb2772e51ae60d3"))) ; Seed height 2035712
;; Block 2035850
(is (string-equal "a81d071b7edcd999ffb2f8a85e4db6c532fda82b81540c6d85bb880200000000"
(slow-hash/hex "0c0cbe84acf205f12c35c0b1b597192aa4e44d9507d61c1ffe3bebe0270c26dd23fcfe02b021dcebce0100cbbc6ec7fcbe51a2492b0194022410d82a736fe561aa4fd5ac29169193d15a8707")))
;; Block 2035851
(is (string-equal "1f4aeadc0ae9663906f7bf947fa3d77c55f7b81a75de40a22838dc0400000000"
(slow-hash/hex "0c0cfa84acf20513d7f2a00b37b3755acb0bd9ccebddc2e39bec67f18e8f5ba3cff4ea7b88e2e44d580500b1ea5eedf4b2e78b428564780a38357cf32aa7b3681602566d543937f9d6594807")))
;; Block 2035851
(is (string-equal "4d77288859efca3c83f9e345acf384caf722a42991423845dc0a710000000000"
(slow-hash/hex "0c0ca385acf2050399815d69b45b889d51ab72e616e220090438a6c5c52d4d0f4c16cf409db29b40ed088b482d11f3e4e8ae84af27ac01ac0c0a21aa01add4894e72fb4200e1b7d7fd5b7e04")))))))
(test tree-hash
(flet ((tree-hash/hex (data)
(bytes->hex-string (tree-hash (hex-string->bytes data) (/ (length data) 64)))))
(is (string-equal "676567f8b1b470207c20d8efbaacfa64b2753301b46139562111636f36304bb8"
(tree-hash/hex "676567f8b1b470207c20d8efbaacfa64b2753301b46139562111636f36304bb8")))
(is (string-equal "5077570fed2363a14fa978218185b914059e23517faf366f08a87cf3c47fd58e"
(tree-hash/hex "3124758667bc8e76e25403eee75a1044175d58fcd3b984e0745d0ab18f473984975ce54240407d80eedba2b395bcad5be99b5c920abc2423865e3066edd4847a")))
(is (string-equal "f8e26aaa7c36523cea4c5202f2df159c62bf70d10670c96aed516dbfd5cb5227"
(tree-hash/hex "decc1e0aa505d7d5fbe8ed823d7f5da55307c4cc7008e306da82dbce492a0576dbcf0c26646d36b36a92408941f5f2539f7715bcb1e2b1309cedb86ae4211554f56f5e6b2fce16536e44c851d473d1f994793873996ba448dd59b3b4b922b183")))
(is (string-equal "45f6e06fc0263e667caddd8fba84c9fb723a961a01a5b115f7cab7fe8f2c7e44"
(tree-hash/hex "53edbbf98d3fa50a85fd2d46c42502aafad3fea30bc25ba4f16ec8bf4a475c4d87da8ad3e5c90aae0b10a559a77a0985608eaa3cc3dd338239be52572c3bdf4ba403d27466991997b3cf4e8d238d002a1451ccc9c4790269d0f0085d9382d60fef37717f59726e4cc8787d5d2d75238ba9adb9627a8f4aeeec8d80465ed3f5fb")))
(is (string-equal "e678fb87749ec082a9f92537716de8e19d8bd5bc4c4d832bd3fcfd42498dac83"
(tree-hash/hex "051a082e670c688e6a0fc2c8fd5b66b7a23cd380c7c49bd0cfffb0e80fb8c2334bb717c5e90db0ac353dfc0750c8b43a07edae0be99d6e820acc6da9f113123ae084c38ccdbf9c6730e228b5d98e7beb9843cfb523747cc32f09f2b16def67f76765cee044883827b9af31c179d3135b16c30f04453943d9676a59b907a6439658f6c98159b8fa1b152f1bcf748740754ca31c918501dbd577faf602c641df59")))
(is (string-equal "7db3258ea536fef652eaaa9ccb158045770900b3c301d727bcb7e60f9831ae2c"
(tree-hash/hex "4231b54cddc617d06e0e311536fa400e5be0a35aab5fec9ec8d98f6c6dad3916fe6cdb1f63be231f95cdc83bb15b0d99d32d9922331b738c423625471fad7f408e60c0773fe78938b054e28b86ac06a194d141c1bde5f3c6f2b11468b43702cb3121b40ccbcb5461fa9321c35c9342e21efd7c1c22f523d78b9d4de28112b6cc51552642ffc126c66f25038f9d3b0cf485cc252215c144d51a139c8ea9a0ecc16e81d8d92dd3660d885deca60070d3d00069d89db1a85acb9c1f18d0c90736a7")))
(is (string-equal "ad56b3e027d78a372adebe839e154668aec5236f7d40296cfdb562fca1dc73c2"
(tree-hash/hex "68e09573a758b75ea8e7d925fe81e3155afecddc4c8aeb3fe70d87411ee53aceac63c0233d172cd49b2708350fd64e2cf4dccb13352e3a159c06647c609429349197163eca2c2dae0c8643fdfe5d346b2ffd45a2d46f38599efbfa587c3ac0c3119e19508e009556fe53e4f78ef30eed649cdc1e090c8cb662eae1863fdc683bbabea966764f550a142dd68e5b8eb1930ff0c7333c9f2555712489a8cf6a5d188a70841510fca540b8c0425123efca47d5a698cf392e3bdbb7226053459fae01fd19ddb9d16d5f5499525feb49ffca9411e7ac48de15256559f3f65f899b80af")))
(is (string-equal "090a95612ed9df6eeb854ae320355889a302498b4f5164a79d8e384a3a0d9748"
(tree-hash/hex "42e7f4058ca80d513c140837dd661acde3fb914779079baccfe188cbce275aed4b515094bb49ab9a825bcc2ac13f84b14a9defeb1b62fc68124b088272a3562696d62ccdfb5d896b2d2b410a2a79f9b1e7849feebc17617ba12a08d4e80affe970ff2fb79917ac13708f79be215bb6484d298b2fe22b4818536e74894db5e0350e1505ca2681da7b7d7171e3d10c89348cab160ff5b2e739d3591443d2af60db5eb36c50a2dfdb79b8ab83b0792161ac4756d9b831f1863188e10c81af5077d0fdb123f66e51670f03a203ff2287dea6827dcd5afd4904736ec4fe9f3b52f7e2bed7beaa1543bd8bfbfff6a8ae8bf1791dc34efa92c6342532fa33a3b72b6c9f")))
(is (string-equal "997ac1178ab7414bab823fbca45b5630df8d1d8263063e6c57da463b85d68a74"
(tree-hash/hex "947fbbc55ad237fc5dbd7d52dddd44bf3f2a09005c78873422f7ef282d8e6fcc554e35c9566febf91cbbcb1d57a7ebd119abb0ad33a006d01623b7b379e966e00be000ae2fe8a45940e99c953d22014bae4932d8493ad4a551a97d437db2939dd53abedc11a63417f76257a5587f382a57d46d63c372182600c7920bcaf74e9e65289e8c45123ac8a54a45a6104dce5b8c065065ff3a3b6f8bf4d86bf96cb56116df4e01eb3153223d5f3a8c0d7de9eb348158e5ca0c363568674215f68b6ff8e54aeb4a2661f1144cb4f1bde7f9e6371d8a5568d4b3ff3382c65e143ae5d3a5834c890559be95b8b80b82c83d70df85c934bf9dd4b0f2b5f60b8553bd1c1e537b7a1f78a89a17a335a06f5d7143dfecff0c10a2e0a524c91ce913ae04501b65")))
(is (string-equal "d7647e967e4f1ad3d5a0b2d231f62c4fe8fea85b845a72aaf57aeea96f2388f2"
(tree-hash/hex "5b0bf1b5c843cc5ea8e907c0d6ea901f1d4259cd61e68895fa1a9df76973ac6c87ee22343802565be146e4fcd768cde3cdd1b1996b8626e53b62648a9fd7f5aee2ce5b4aacb090d1beeaf42d47e7f0e90174af6554e8bd4aea3df45e90537eb7572b9583b3fcedf56ff69c412c4576a1353458292b7a6b10536887da47fb95c999ff1a074dfb52db43cf423e81e02aacb267b5f3b48761de9c3a73efe199d710e09043e4701792d04112d18e33d5f78efe4fbda461b4e0f2f55f07ca04eed04762d956b396ff0471c28f48462bf9b6b47caac50be8dd822198a39366071b18f4d4e8188bd11421b606108e9bbcfb1377e122c36083beca6a2306e48bfdbc64c9e6435ed838eba78e0af101abf79ff9600f6cc1b2b776783491161ae2d1d8df2d436a20c053c9237a7d224016878906352eba550d778e91ba830906b8d0be4e6e")))))
(test hash-to-scalar
(flet ((hash-to-scalar/hex (data)
(bytes->hex-string (monero-tools::hash-to-scalar (hex-string->bytes data)))))
(is (string-equal "7d0b25809fc4032a81dd5b0f721a2b21f7f68157c834374f580876f5d91f7409"
(hash-to-scalar/hex "59d28aeade98016722948bf596af0b7deb5dd641f1aa2a906bd4e1")))
(is (string-equal "b0955682b297dbcae4a5c1b6f21addb211d6180632b538472045b5d592c38109"
(hash-to-scalar/hex "60d9a4b96951481ab458")))
(is (string-equal "7bb1a59783be93ada537801f31ef52b0d2ea135a084c47cbad9a7c6b0d2c990f"
(hash-to-scalar/hex "7d535b4896ddc350a5fdff")))
(is (string-equal "709162ee2552c852ba62d406efd369d65851777152c9df4b61a2c4e19190c408"
(hash-to-scalar/hex "14b5ff33")))
(is (string-equal "36ddbd71a4c19db5ea7022571a52f5a9abe33fc00aafd24b562fb75b7fc0360b"
(hash-to-scalar/hex "383b76f631652889a182f308b18ddc4e405ba9a9cba5c01b")))
(is (string-equal "c381ea27500b61d29e9ad27add0168053cc1a5b7fc58b6960f67c147324acb03"
(hash-to-scalar/hex "3a170545e462830baf")))
(is (string-equal "357f141395a76e2fd5003045b75f3216294eab0524eda1ed16cbe558145a2403"
(hash-to-scalar/hex "190757c55bc7")))
(is (string-equal "b365e89545402d3e7d649987127980ec8339af2e3067ff942e305a9ac0b7390d"
(hash-to-scalar/hex "e1dec4027ccb5bf7d273163b316a86")))
(is (string-equal "24f9167e1a3eaab18119c225577f0ecc7a488a309e54e2721cbaea62c3db3a06"
(hash-to-scalar/hex "0b6a0ae839214674e9b275aa1986c6352ec7ec6c4ae583ab5a62b947a9dee972")))
(is (string-equal "8af86aa2f8739b7d384e8431bd1ec5a75a1e7d1dc67f2f7100aeffbaa516200e"
(hash-to-scalar/hex "232849cfbb61443dcb681b727cdf7a2b84116dfb74a3c1f935")))
(is (string-equal "79b024435100e891c167abd8f96d3f5efc6919e5861f7298b7736f2927276809"
(hash-to-scalar/hex "0bd05745dceb00b2c18080e6cb66d9099e9610d620c188a9")))
(is (string-equal "594cd0a2b135b1c29544b095b8a43e5b3cea1806fdcb9b59cc53829cc62f2000"
(hash-to-scalar/hex "ef2e5ce130838935ed202cd61453ecb860adbb903f0eb950df")))
(is (string-equal "43ff71f4c9544c09e583d3fa4d21297463d029415e236ae758d06f4238b5ef04"
(hash-to-scalar/hex "48c7811fe63d09ceb4e6ad0acd51487496b7108d279078bb")))
(is (string-equal "20a8a23806bfa8ac1e3d7a227bc4c3554a18f5e593e5f8b807767c3f818ebe06"
(hash-to-scalar/hex "854b5522f6a7a50af76e305c65bc65d2ad7603a00e244aabab4b0e419576c7b1")))
(is (string-equal "995f4205c63106243983d2be160a2e17f2ac9b78c8e6a705a4c52d6adf2ada0b"
(hash-to-scalar/hex "3aca21fdffbb7305feed286925")))
(is (string-equal "42138bd241761d92b67db8ef225347b98e10b74f6fb0123da7b44f8d51c37309"
(hash-to-scalar/hex "5cf74e22b8b6d30b90be7e2296f1e89cb76bd7ea3001663256")))))
(test hash-to-point
(flet ((hash-to-point/hex (data)
(bytes->hex-string (monero-tools::hash-to-point (hex-string->bytes data)))))
(is (string-equal "52b3f38753b4e13b74624862e253072cf12f745d43fcfafbe8c217701a6e5875"
(hash-to-point/hex "da66e9ba613919dec28ef367a125bb310d6d83fb9052e71034164b6dc4f392d0")))
(is (string-equal "f055ba2d0d9828ce2e203d9896bfda494d7830e7e3a27fa27d5eaa825a79a19c"
(hash-to-point/hex "a7fbdeeccb597c2d5fdaf2ea2e10cbfcd26b5740903e7f6d46bcbf9a90384fc6")))
(is (string-equal "da3ceda9a2ef6316bf9272566e6dffd785ac71f57855c0202f422bbb86af4ec0"
(hash-to-point/hex "ed6e6579368caba2cc4851672972e949c0ee586fee4d6d6a9476d4a908f64070")))
(is (string-equal "72d8720da66f797f55fbb7fa538af0b4a4f5930c8289c991472c37dc5ec16853"
(hash-to-point/hex "9ae78e5620f1c4e6b29d03da006869465b3b16dae87ab0a51f4e1b74bc8aa48b")))
(is (string-equal "45914ba926a1a22c8146459c7f050a51ef5f560f5b74bae436b93a379866e6b8"
(hash-to-point/hex "ab49eb4834d24db7f479753217b763f70604ecb79ed37e6c788528720f424e5b")))
(is (string-equal "eac991dcbba39cb3bd166906ab48e2c3c3f4cd289a05e1c188486d348ede7c2e"
(hash-to-point/hex "5b79158ef2341180b8327b976efddbf364620b7e88d2e0707fa56f3b902c34b3")))
(is (string-equal "a6bedc5ffcc867d0c13a88a03360c8c83a9e4ddf339851bd3768c53a124378ec"
(hash-to-point/hex "f21daa7896c81d3a7a2e9df721035d3c3902fe546c9d739d0c334ed894fb1d21")))
(is (string-equal "1a442546a35860a4ab697a36b158ded8e001bbfe20aef1c63e2840e87485c613"
(hash-to-point/hex "3dae79aaca1abe6aecea7b0d38646c6b013d40053c7cdde2bed094497d925d2b")))
(is (string-equal "b252922ab64e32968735b8ade861445aa8dc02b763bd249bff121d10829f7c52"
(hash-to-point/hex "3d219463a55c24ac6f55706a6e46ade3fcd1edc87bade7b967129372036aca63")))
(is (string-equal "ae072a43f78a0f29dc9822ae5e70865bbd151236a6d7fe4ae3e8f8961e19b0e5"
(hash-to-point/hex "bc5db69aced2b3197398eaf7cf60fd782379874b5ca27cb21bd23692c3c885cc")))
(is (string-equal "6a99dbfa8ead6228910498cc3ff3fb18cb8627c5735e4b8657da846c16d2dcad"
(hash-to-point/hex "98a6ed760b225976f8ada0579540e35da643089656695b5d0b8c7265a37e2342")))
(is (string-equal "8aa518d091928668f3ca40e71e14b2698f6cae097b8120d7f6ae9afba8fd3d60"
(hash-to-point/hex "e9cdc9fd9425a4a2389a5d60f76a2d839f0afbf66330f079a88fe23d73eae930")))
(is (string-equal "b07433f8df39da2453a1e13fd413123a158feae602d822b724d42ef6c8e443bf"
(hash-to-point/hex "a50c026c0af2f9f9884c2e9b8464724ac83bef546fec2c86b7de0880980d24fb")))
(is (string-equal "9d6454ff69779ce978ea5fb3be88576dc8feaedf151e93b70065f92505f2e800"
(hash-to-point/hex "bf180e20d160fa23ccfa6993febe22b920160efc5a9614245f1a3a360076e87a")))
(is (string-equal "0523b22e7f220c939b604a15780abc5816709b91b81d9ee1541d44bd2586bbd8"
(hash-to-point/hex "b2b64dfeb1d58c6afbf5a56d8c0c42012175ebb4b7df30f26a67b66be8c34614")))
(is (string-equal "daa5fa72e70c4d3af407b8f2f3364708029b2d4863bbdde54bd67bd08db0fcad"
(hash-to-point/hex "463fc877f4279740020d10652c950f088ebdebeae34aa7a366c92c9c8773f63a")))))
(test secret-key->public-key
(flet ((secret-key->public-key/hex (secret-key)
(bytes->hex-string (secret-key->public-key (hex-string->bytes secret-key)))))
(is (string-equal "d764c19d6c14280315d81eb8f2fc777582941047918f52f8dcef8225e9c92c52"
(secret-key->public-key/hex "b2f420097cd63cdbdf834d090b1e604f08acf0af5a3827d0887863aaa4cc4406")))
(is (string-equal "bcb483f075d37658b854d4b9968fafae976e5532ca99879479c85ef5da1deead"
(secret-key->public-key/hex "f264699c939208870fecebc013b773b793dd18ea39dbe1cb712a19a692fdb000")))
(is (string-equal "1dec6cc63ff1984ee46a70a46687877a87fcc1e790562da73b33b1a8fd8cad37"
(secret-key->public-key/hex "bd65eb76171bb9b9542a6e06b9503c09fd4a9290fe51828ed766e5aeb742dc02")))
(is (string-equal "25255c26721758456545bcaea3a99407cd3df7c8208eeb49bd80450627138fab"
(secret-key->public-key/hex "37621ebd8de6ca022419fd083066285da76ada9bae6d2b7c1a3847d78a726b0b")))
(is (string-equal "1be4c7b195156a06ebf6a81acff06c3cbfcc4f869a8f0994e0d98d45f586b02a"
(secret-key->public-key/hex "a44f5cc6e6583394ec1970bc16e9e3b70c09ffb2ebdd515c8f5e6a8c02b5ce04")))
(is (string-equal "577a7b3e1b89089936fa89729855e25ad646057309c21da272b38dd3db5da9bf"
(secret-key->public-key/hex "46ca522f94c1ce7a3755a158234f87872792ca03cfbb0aebc6897bf376d4a009")))
(is (string-equal "f888cdc2cc39194e638587116ad14554a42b52ed13fbdc3410ad888408b6b7d1"
(secret-key->public-key/hex "93f6713bdcfb18984dccef06dd84690ffc054b6eb6f4c75ebdfe9bb0ec1f810e")))
(is (string-equal "345c0c9279ac9686ed7b73648bc3e92e34d513e0d87d390d74250830976757d1"
(secret-key->public-key/hex "e49fa0345748fecd9b1f7a60b3cf2e6d61b47a15a033a390cb0586b7185a7f03")))
(is (string-equal "043f8109c1c406aebfe8581b9d0bb41159a957a91b4d6b08ca18bd7a804bcdaa"
(secret-key->public-key/hex "195917df120eac02087610a7fcae94d61538e9dbbe6773ea45cc7cf3808bbb03")))
(is (string-equal "cc690e16d540108096d73bfc458ed3695a60043fc048877920efc03860014314"
(secret-key->public-key/hex "0f588b029cf8d9b6efccb2fcda1ce33c16c552c11e5286807a74f6f7c7eb1603")))
(is (string-equal "294352ec050ad768e14d2e13f6c588b8499171080106724edfda9b5e3d0b9e21"
(secret-key->public-key/hex "2ab2964c462dfb7abdda7229c91c1b1d217d015b9b429b76e93b7af854ef2200")))
(is (string-equal "a6422d15a124f5e8c0bf9d8269d36df75de108003b5cc984be6863774c0b0021"
(secret-key->public-key/hex "11f4389bb16bcfb02de71b385345eb7593121097cac0a14387090f1a7dbe100f")))
(is (string-equal "0dad7138095b22905f7074c4750fcdcd7ab4fc210ccc41812af50c9b26888afc"
(secret-key->public-key/hex "27a92a4c8ad3de40e5e51c89c20dff6086fff954f574494154ff4f18faf82a0a")))
(is (string-equal "1869ced31a176913f66d77fcb776f1ae51d404004d0efcb18676ef6d9f18764e"
(secret-key->public-key/hex "27926691b86d9bf9bfb575f1325e418b46de258495185a3bc681efb9ee671904")))
(is (string-equal "6d145f7b2454f6d38677cb1650d980a933dea237cb820bd330edcf9111265379"
(secret-key->public-key/hex "d5f7e654389be8829aeb51c4ed8a02474d1f72d0ed62484e9eeb403f0a9ae007")))
(is (string-equal "59f5445dfe7ac2a13f93088caedccaf78b69a3460b70547fa249f2fb7f3dc5e3"
(secret-key->public-key/hex "be82dba0af095ecbd0cda2a1eb29a99ee8db1f30280164bfbb9c2375a884a308")))))
(test derive-key
(flet ((derive-key/hex (public-key secret-key)
(bytes->hex-string (derive-key (hex-string->bytes public-key)
(hex-string->bytes secret-key)))))
(is (string-equal "4e0bd2c41325a1b89a9f7413d4d05e0a5a4936f241dccc3c7d0c539ffe00ef67"
(derive-key/hex "fdfd97d2ea9f1c25df773ff2c973d885653a3ee643157eb0ae2b6dd98f0b6984" "eb2bd1cf0c5e074f9dbf38ebbc99c316f54e21803048c687a3bb359f7a713b02")))
(is (string-equal "72903ec8f9919dfcec6efb5535490527b573b3d77f9890386d373c02bf368934"
(derive-key/hex "1ebf8c3c296bb91708b09d9a8e0639ccfd72556976419c7dc7e6dfd7599218b9" "e49f363fd5c8fc1f8645983647ca33d7ec9db2d255d94cd538a3cc83153c5f04")))
(is (string-equal "9dcac9c9e87dd96a4115d84d587218d8bf165a0527153b1c306e562fe39a46ab"
(derive-key/hex "3e3047a633b1f84250ae11b5c8e8825a3df4729f6cbe4713b887db62f268187d" "6df324e24178d91c640b75ab1c6905f8e6bb275bc2c2a5d9b9ecf446765a5a05")))
(is (string-equal "f5bb6522dea0c40229928766fb7019ac4be3022469c8d825ae965b8af3d3c517"
(derive-key/hex "ba7b73dfa3185875538871e425a4ec8d5f16cac09db14cefd5510568a66eff3e" "c9b52fd93365c57220178996d97cc979c752d56a8199568dd2c882486f7f1d0a")))
(is (string-equal "bcdc1f0c4b6cc6bc1847728630c3060dd1982d51bb06873f53a4a13998510cc1"
(derive-key/hex "45f6f692d8dc545deff096b048e94ee25acd7bf67fb49f7d83107f9969b9bc67" "4451358855fb52b2199db97b33b6d7d47ac2b4067ecdf5ed20bb32162543270a")))
(is (string-equal "7498d5bf0b69e08653f6d420a17f866dd2bd490ab43074f46065cb501fe7e2d8"
(derive-key/hex "71329cf72de45f5b98fdd233707501f87aa4130db40b3570527801d5d24e2be5" "b8bc1ee2987bb7451e90c6e7885ce5f6d2f4ae12e5e724ab8432769af66a2307")))
(is (string-equal "796b938b108654542a27155a760853101aa896eba019c659e0bf357db225603f"
(derive-key/hex "748c56d5104fb888c4143dd3ae13e578100cd87f4af1be562ee8401d2eec81ad" "659f545d8661711e337ce3c4e47770c9f55c25b0c087a3a794403febd3f1600d")))
(is (string-equal "6e9e6dba0861417979f668755c66e09cba4b06d07eca5bcadf6e8dd2f704eef4"
(derive-key/hex "1a2c6c3f4c305b93e6c09604f108d46c988e16bb78a58bbc95da5e148e9ca856" "668b766d1a3b09fc41a7f27ca50a1ffce1f6456b9d3613527f0cb86e1eed6705")))
(is (string-equal "f59b6f915e270452eccdf7172f1cf0fe702beca9067673ea3ef7a4920066a1cc"
(derive-key/hex "6ac060a711ce299a7ee47a74f7b3ab9d53ed8bb19fe3bf5f786745babf22e3c1" "00b5bbef9ad292f0289126a0ece082c9c535324c5ee0fd1534f7801777337f05")))
(is (string-equal "e4ced0d7c6d10f0dd4f55a4d7b69ad17b692179b0038013dc8ac287fd4360cf2"
(derive-key/hex "aa1a5a28ec965d1f4838c2781628cafa9867dda2153990c7fc4d19dbf1cae3b2" "76c1838f52d761c3738500f240b14e48ada3c1e92081d5f60e53d642fffc610b")))))
(test valid-signature-p
(flet ((valid-signature-p/hex (data public-key signature)
(valid-signature-p (hex-string->bytes data)
(hex-string->bytes public-key)
(hex-string->bytes signature))))
(is-true (valid-signature-p/hex "57fd3427123988a99aae02ce20312b61a88a39692f3462769947467c6e4c3961"
"a5e61831eb296ad2b18e4b4b00ec0ff160e30b2834f8d1eda4f28d9656a2ec75"
"cd89c4cbb1697ebc641e77fdcd843ff9b2feaf37cfeee078045ef1bb8f0efe0bb5fd0131fbc314121d9c19e046aea55140165441941906a757e574b8b775c008"))
(is-false (valid-signature-p/hex "92c1259cddde43602eeac1ab825dc12ffc915c9cfe57abcca04c8405df338359"
"9fa6c7fd338517c7d45b3693fbc91d4a28cd8cc226c4217f3e2694ae89a6f3dc"
"b027582f0d05bacb3ebe4e5f12a8a9d65e987cc1e99b759dca3fee84289efa5124ad37550b985ed4f2db0ab6f44d2ebbc195a7123fd39441d3a57e0f70ecf608"))
(is-true (valid-signature-p/hex "f8628174b471912e7b51aceecd9373d22824065cee93ff899968819213d338c3"
"8a7d608934a96ae5f1f141f8aa45a2f0ba5819ad668b22d6a12ad6e366bbc467"
"d7e827fbc168a81b401be58c919b7bcf2d7934fe10da6082970a1eb9d98ca609c660855ae5617aeed466c5fd832daa405ee83aef69f0c2661bfa7edf91ca6201"))
(is-false (valid-signature-p/hex "ec9deeaca9ce8f248337213e1411276b9c41e8d4369fc60981b0385653c0f170"
"df7f028022cb1b960f2bd740d13c9e44d25c344e57f8978459ffa3c384cd541c"
"2c2c8e7c83b662b58e561871f4de4287576946f4e26545ba40e78354c6d0b36f69ea44892f39a46cf3fd5c2813cbc1c525dac199ada6fd5ca8e1e04cff947700"))
(is-false (valid-signature-p/hex "114e8fffb137c2ce87dd59eff7f4b8e6cc167fdd28c3ea77d345d2c8c00989a1"
"d257f46216be34be5589e0b12094e643d1b31bc3c50e006d044d1ea885b5007d"
"9579b6e8dc108633ac8b67004699921aef479b6e7ee9590073fbe1404ee4b3d533dec29fd35540f13ac531c3ae49abb62cbc11d36b0cc3353db77a294d8d3d92"))
(is-true (valid-signature-p/hex "ce03e1fa5476167c3ebce1a400ca1d2d375176b5cb9ed180913efa1a688ddc97"
"a05a3a6776f85c5d04c42fa2c6a731831c3d3a4e3a12f967f9ba0b1ecd1aee98"
"4992de4fec265113710ec3a211e86784581f96241f0305d069a1e4629b504d03b3a1561fd9e73597db89ba00beeb60d2107c1f835176949bd354e8a173d46705"))
(is-false (valid-signature-p/hex "7db838c96a3e1fb14156986aef37b70f932ee79d3cbc8233cdd76997eaa0c0c2"
"306593abefdbe99beec4752ebb135131a93e8361fc35f60a1c56fc4501c6782f"
"5bd47b285d25ede033bc5c2049edf3feb06fe29091e2c90ba25128c6c1a050713f28db1b9106013d22d5e0ba05bbaca43c4d30b6f0bbad8768e6cb89b205c20c"))
(is-false (valid-signature-p/hex "2d96536cad13a409d5a46a6bde1f5cf1d9255e741d5a17309248dd910e02d1c3"
"c2257e5386cdef44b989ce395532b8e03dde166ba26c18759e1c440738242fe4"
"2f5e7a5c690c0d3bb2974e47eaa159d0bb2205a636b8cd09736add9fe8d75bee4249b30f8e1b99c1dea45999842f5709d2ee1d8e450807319723625074c69605"))
(is-true (valid-signature-p/hex "40e0758cd9c9f8f8f7d0fbf351084863973a3622c92dab501ffdee610278f86a"
"f79812b95048683d47eb5435bdd97c5a39532c6693dc8b965af76d7f3ab88e92"
"a9ba1cb8bf2898e21c12bfd23788994fe20d45ef6f775c197ab157d7c2721100f2123c19395f13ff79941e4fc9ac33b2f70077a79c552b4ebc97a4321ae66e09"))))
(test generate-signature
(dotimes (i 10)
(let* ((secret-key (generate-secret-key))
(public-key (secret-key->public-key secret-key))
(data (ironclad:random-data 150)))
(is-true (valid-signature-p data public-key (generate-signature data secret-key))))))
(test valid-ring-signature-p
(flet ((valid-ring-signature-p/hex (data public-keys key-image signature)
(valid-ring-signature-p (hex-string->bytes data)
(map 'vector #'hex-string->bytes public-keys)
(hex-string->bytes key-image)
(hex-string->bytes signature))))
(is-true (valid-ring-signature-p/hex "c70652ca5f06255dc529bc0924491754f5fad28552f4c9cd7e396f1582cecdca"
#("9cc7f48f7a41d634397102d46b71dd46e6accd6465b903cb83e1c2cd0c41744e")
"89d2e649616ccdf1680e0a3f316dcbd59f0c7f20eba96e86500aa68f123f9ecd"
"3e292a748b8814564f4f393b6c4bd2eaaface741b37fd7ac39c06ab41f1b700db548462601351a1226e8247fea67df6f49ea8f7d952a66b9ec9456a99ce7b90b"))
(is-false (valid-ring-signature-p/hex "3da5300a7aca651dc3a85016824b0620a19973eae4af8910cc177faee499358d"
#("7af6983daaecec1bff70b05c7369fe1636270f8dd606d39eba974b8c1d5f6091"
"78c2676d12505b7d5a63ce29f736124b48a02dc78bd0ccd1e9901344811bbd3d"
"957251408e9a8b255adcabc52bf15cb8a05501e2892d7cdda22ce672adc0cd12"
"73e433a1668d056d9b651aead47658476cf23c39cfeb4fd23625ed94af439677"
"f58dd3a46e0a07000ef6e978cff87604c32cd3df487acd220b53b5ccc46d0bd5"
"3480f2437e01073133ee9cad9651665277b09bc0a46618f975a746500f9f34bf"
"0ed796ebd217fcae58272ed7c4c0b058f558961f95a68ea52f59e4e6f0374d73"
"729e5938a034b2f50b583d4ada5541a12de09aa1776653a821da7d6c6b057716"
"1a9855ca5dc19cf11f49a87b182695451e83952f2df4ee9009bf0f72d6e25194"
"c609386fb270c7af8dc4ee102fd33ed3c836e7ea493dc79655c9feb1cfb9c869"
"94ce9f9d3fbe4848aeb59231d749c6c9f7bfaaf99c31e4317c2b5b1b335f20f9"
"9331dabe4d6f230a7c45417dbbb28b0808b4b6bdcba83b774583d784413ddb4b"
"437652a047fe0872b264c094440625cb5cca5cb8d10cda950138c97dd09e5943"
"5c470fa7fc2684336917a626e2dd4a09d68b4ef9499857c11e8ef0aff77a9262"
"df3ccf869b0262bd33952ace2b1320f809e227949ce6a2e89a245ce5da75e250"
"4ec480b685a07d091057e73954c8bd5e4646b2bd0bb0a46a38f74cc44e0c940b")
"8d39d8d877d74cccbd5fad872b8297eec3f4b3f5187486f8c98a2ff27f994800"
"4e7ee4fb45708e2bd97b2ee4e134224714c2fe1c0b679b7de838d715e281f10e4da8a6455bf4683a91e6e56be119fde36ccd61f35aa4867e9725dda7c18bb40afa097778cdcec51fe2d205db00ab9a00dd5f6f0a2a3b8393a7ae2bc03d6ff5073b25f72be8166bdf2e21a4745841bbff68a54d6fa3c77577a6b5c0f0b7ce0a120d07d704e9a30f306a63d5b137534ac4b60953abeb420d526f4b501008bd0a01790d806d86cf96391953e8b630833a3d6a01f023da720e26015287dee5c9b9060f43fa3574626a3673628b6b82c4b0251b5251173b59177fdc8f79974205090da7a3d93d1d274ed39654c348870da21ac66ee7a0e072e504aa01ece4051c3f0c93eb6065ae0e4d05e49144b986b33ee741c406860d39c953062531f2e993140c43aeeef6b144cc42bd13c2aafb10402edddebdfe0b426730163fd530f7b2c3009d4b98d761131c5ccbdcb737b4a1e9fc72c1313fb45eef13ce4d31c40ec94c0466cfcba1771229b0d2e014d716c9a2c10f6191eb67c1bb05e72f291d1d98290c2b4542d196df41410992428e36c62965a2d68f1fb99d6d4058b7e0360dae2c0c56d7980a546f547d2944c3bb6672fdb7d40378d47b0bcd9ca9ce55abce22ee0d94a7906ff1e31d37578a919dd92b4615ee0930fb33cb494548e13b731b33320193bc5b88e5864fe2d5d9a1b2bfb343177ff10d647337205f22a37b5cb385090bd2a050d055cfb9fbe01cc88ffa3fad76eb5b7baa50cf5f379ac6cf2636da8308c945c859cae02e772e432b177238a6e3d75b5cc6e676d1f3989d78493d86440cbb5552586755101dc4dd43bf51cab188fcc919012f7d9b19db5189fad02362059c8b3cacc8f80413e9a43f41cbe154ad55acac98287edef98240b6d8a04fcd0a020c8481164041bd7165a6b90b8560593c8848d29995634392dd22f3e993bd05580e41349091cb125eb2048c53dd230808019482f4b22c83ca678d9b01931b03f84ff3b4a78c138fbe36d013c9a423e0233962be5f278b535b20f05c829624043641b8386f7cd01a77c4077a5a6da0eec912042c60d9b6bcb56cac9713dc7002ab69ee15e0013204f68d6093b158c21f3a09e205b15e627b3fa33d9a0cd0300d9287b5d75ab7dd914ed95c8ed3db0bf05f68792be1492c41854a2e36c123d30427ff0fdf706d5a01f6cf6b1c02e2140f7b165b2259904528f12b527a7de76a0d8f90c3c027bb2f71cb1b345fafee0628b3f15049cb577b780890b9b96c53160b9ec99cea512304c94325b2c894b6dbc926c9b2b8f497a765a180f70425174802033d83980e2b28cfaf767d6a4da871d6adee474fb093e89df7eab67255b1b70821e64bee166892d1e5ea9ff2dae7b65231427e01c63164b5f3f84626511d2f077de2741fb75e3d940646480b595338c6043cdda23f0fb48d875498675e686eaf"))
(is-true (valid-ring-signature-p/hex "90660b84dd3be5705c7766695fec404348af6df58f8c5d58213f3b70b8b67a23"
#("4af96f2c3a70ac1860d48132136989c1d38551367025d43f36aec0ffa8e7f28a"
"376cc178d8ae3a68ce467bfbe719e88b22514617dbd1e764e0b94b4f6bc961af")
"6289b9b151eeb263fc29e4b5e90978db7670f06f408403c8973bbfff2a884dd9"
"4ccadd504d1d03e385ebd25dc51b98c6f3a0e1c1be7e5694e44dc2377898510ca3202d7872294cc04b65d8c109e3a6e843c327b3416ca3a2b1c585fe4152260555441dd7b1543549f749acf5fc9a93a3f3c240425c5f7cadccdef4f06cef0702ae4ad477d0cb60a1a48c1da22f5a8b20c7c5672833c7ae13f78edeb3db1a7b01"))
(is-false (valid-ring-signature-p/hex "d280b24c280daade9d2bcd68c6dfd39d3a13eb1b0645c4f7d2b0613dd4b5af3d"
#("2d4e494897c24b1730f018df65468c2647b2dc19f650d1a9e055b9319045ff13"
"74db9c16b0cb4beb7d48ec77b654c63917529072aa57d381b5e3b8dbb06e0f5b")
"f1b943daa1ef225726215f551dfd85f56a3b429ded8608a09a8310a90b8aa88a"
"8aae0a8523d65b3746c87994e4cffaf437ac147a82efe34389d270a976183006c7de37ef0362e13aab9287a85445748a8e0e1a357c6a0ba090f436937a1878b47b41de38a3737152453ca3c0c6546b65ceaff3298329273b0808d35af376a20c1217c85b153d40bc154108eca199175b3efa3f190740325c734d82cfb054d50f"))
(is-true (valid-ring-signature-p/hex "17e1d8c991803cf0747a66dd16a3c5069afb0f604670b823b675bed5de59d6c5"
#("130f844d2ff629d6374653997afec462eceed08648daff08eac4c58b9006e6e4"
"f92f7aa2bb9273830b966f71c7d7aa0ee8473973d65fa044c74ec4d4628d765c"
"8c1f5b3b71c27ebdfadefed2594ba57b19934eda6fb7b5c7e63dd0ed471b6e2e")
"81abb2291ae3e208665370f4fe07c1d82d3f8f6a6ccafe7e5fb4819ce1d2f113"
"7e799950f135343936af6719ebcedfe6e4a3fceaa86047923f592e1fb69aa909575174936ecf6615813c0a4620aa77161d8309aefffd6d33b8eb31b37aa36109dceafe0b8b49a5a280561b204f71f1c6116053ed1bac94b26fcad0ec947a9b01e4459a956e4644f7a8c39719164a87c93d21971366e66e0409556fc93c4c1d0f7db9b2d221fdf6fae05cca363b5e9ea1a7c9b0c80080b9c825f9bcc0b734030711b981b71f0c193bdf51b41bdca81579144e1d7ea134b93a6ba40bd18bb74f07"))
(is-true (valid-ring-signature-p/hex "f97d4e9c36389eb32dca83903d86e738b412d0e719fac9de9cb1a79deb5c5f87"
#("e360cc0b0d54a051adc6eee4446c516d586d5d3abb484c792e15b69c1376a392"
"b8a788bf7dfcd8f6cab88b156b04dea2bc337c90ff783f75327a7c32368b94c7"
"4ccd4f2d7aee244994139bebf641fada943bce4c7a5fe96b7f1691a033c97b3b"
"024d0d3dcec8858639fcc7d1d711d64d0ecff4c51e86b9f00a31f74b558593fd"
"990bcb241da35a4edd7b67a9595c66053cb6f56a18b28eda8fba2ab1a0c40b3d"
"628450cc2fbbf75ff8a63269bb004089b46b9041ef45f290813a3ead125d3f5f"
"aadbb083008b069c45bd0838cf9dd55597982deada11f1a6f0bbb12db334b984"
"f7e4485473d386ef3f6beec68c0c31ab7902186b4bee28012013307604a14ed5")
"a710922602dd9d7891df50d78c8df1dd244ed7258d43384378212a09623f61eb"
"89e0b6e11d9ed3595834d4448516173fb9bfa69bc350442e82f2ff158c72660dfc4f03ce65c088d5d3a988a9d6cf98d04559e99479f2daa4deb9d156a71e120c109472c1d0f0cdf12df970073acda0db505d4708cbc0a974c83312b1e58fbb0318efdb085296eb51ea81de0bdbe0535c864c83851eabd0df9789e75ac0179a04f9de1ffd04f2f4e3b205750858cf7ed6a5694f90a3d7259582e9fb0e644850054ad2bee7f7c75cfbd32d3bf7f6377437d99f818bf844bcac079579583e5f4401d5c0b79b94bf582b2fd0cb9e4739b74d71f235e1d8041361e53ad85e357a620a0df80e51d66476af588468dcabbd399f5a33d003f62dbc34c73cafceefb64c0d301ae7937538a1817e33030c11133029ae10e05b4d89bdc22e65aa73b29ee4004542792c62c62b9faf8c0ad356378b989356c45f8af36d98efde96ebb731b2099058f165a4c15c40182a4b87fe14849d19e9f87ab1bd9f1ec8a24166dda85203ef7e3be56475f20ef58f9a67e9e0ead0f07ac6199825ac7768e4a52add86970dafbb5b8a98ecc0192b074b6da1912a85bd26cd2990fa126a460be05a37187b0e6fe5f20b3466ad71233cda314137910beb7f4a8f92889a1f42b0cf53421cb502d8eeafe6cfdd5c02a9568a45a1db2e1db53451839e39d09dca7426354b3f0904bf941341584735e926e8fe9a139322c2f6bb82bdba106f9e2825ce09a2281407"))
(is-false (valid-ring-signature-p/hex "4b3685c13ee27fa3c7c4949b799a6d61cf3fcf3dcc0b0b5d163bc523bb58f53e"
#("4471da1870dd4b1d670887c52da935b786155ba1f33e4f285f13573c5ef85b5d"
"bc140365276347b7ddb74f1d9709a1dc706b8c4784a8df0614718279c0d5fd5d")
"60e6f33abf3013caf974260f3150460adb67772965a165ea25bbba1ad20f9ffe"
"66caaccdeee7e254a5894090ba8295023384d4c34f65233609829f7dffe83805e18bf2641d51d564d53f5a5604e9f0486b234f2465e35ceae867d57cd9885908887ca45cb91c0cb1f3c061200fc1cfbd576ae5c47265a118880dc96ff44614035ff3c62ed6d37853b081f1b397c2f1ad74e96f87fefd502398b7e1deac4dbe0b"))
(is-false (valid-ring-signature-p/hex "91d5d69145328db2b0456e9137859f9e2ada43794858a0f65060b31186b1733c"
#("d228faef88768e5a51eb5bf1f70bdc1f37abf92fe02dd3b767236a26f6d93f5b"
"ee5caf80b4dcec7d7227ceb6d77fd7e692e19953700e983b671dfc9d38705246"
"3d1286dc5ac990769b7d2ae70d65836fdb19b7927b89c4fc19bb180ab5c4d263"
"bcc29ce010c0a61810fd7ffcae604749577b079b64326f16d86b0f51603c9ff6"
"11150530c271b48dacc42f2ac180e3838005536a5d8d35e9e613fea9c26d625e"
"31b189ca5b0faed14d9d44afd6332371cf39c5787ce63bcea9b2a758859a9d94"
"0f3f6e35b20a11cf37459b579c859fa1e35b92b56f04d1a9b3ee1a0836e51740"
"eb9cc00929d7ff7617631b5f10a15024be3a1e8e3892dfe7e71ef41f391b87fa"
"867509166d2dea7620a036da6430d16b92fb6e1ec1f23a6114595e5a57897976"
"f543b10cd9558098efb7cb077177e311beb27537305139e5e9beb50fad24bd25"
"e8fdce69689a8691abf8c2349e91976217289b573c7af1c848f92ed46013fccc")
"68beeb9ca45266b16dddb8056bdd44a76716dccbc97ef89dc47cdca8c2350cb3"
"3d3f22cf0859853f3954c6f39cdcd0d7338f2baab1a72b32a533ca2d7da50606a2ffe2d032751b2e9f1dd09d165d608895fc9712edfc7fdf49c8c9c0a62b8b083a10098222594efd0760dc5b8ab4761cc4fd32946278c43715f126baed8acc069cbfb6874cb61000b194ea30046c274ecfe7347f9d9f79c8d33f3fb0d5d1cd0fe055a9a0161e676cf18df3ac5722e2984111255926f87e3a768fc237476d5a0fa2161f836223672a098e469f2b37904de7f229fe4d24b30118cb99978a6f3900ebc14a898506224f43394ad166bd692859f015b27286c5fc56705aa8a4d25549eeecf5ee8467bd4287dd6ec922434dc2c87ed567ef9b5e8367db9ab0da1f8602285237ae23be9082ab92d32a41efc6994f228148dbc78537dc97953a6e51e90cda0336f4beff1c166b8a4b9b424e90ecacac60589a466d83d2cd6dd24d8ba4052b9c860df7d53a3cff605b8c21f4bcad637d02e5402fa6d0fcfd23fdcc87029ae17ed35f861a1df56e3c12bf9d48fc80044d09d010c774be0067adf315e53a076e759732fe77eaf82b305185cadcdc01f185be5dac89c5a4e0df908ffe3e2d0a3faa8bef5dfc9c81db165a95e6f98e76ba38a7aaf3a1c4e3445b00b6ba157f09067fe2adfb45328bdcc44c2d77bee5c41760fc8fe14b0ad5d68cc252467df20dfd7dc1825f5aee65f60b082d8391a25ae04511e9a2136856fbe2b863021d1a081c6e1e47f799c9a5195f69264739ac1907f45c4623c49f8b749a105b60ea230f338af872e1928af743297d56177ade12ff67e07ce294f80d13798387b42b07c25c091c580828074dc851be60fddb098fc461cc34ef79cbd57436600d5c58b104556ca5ec3991621dc6dbd79abd387a5c5d75fda3346596599fa1a6cea26c4c09827ff05c304efece79ddb2a2f194cdbddabd54cfb8dea050c72a0dd19af0ed09e99d3069666f4ee33b4a7bbc0c311b9e5d285a5b65d974e38256ededb602ba00"))
(is-true (valid-ring-signature-p/hex "8905840ba2829e2bb6b7f834db939b7ff006140df120170253e73d6a110adf09"
#("7f68e1932829141a4823849121662b5ac7c8c50f0a3ded4359896648875bda84"
"c0bd288abfda7dd2f55ba0580fd0b240f7c202c889bc9de914c759802d05c984"
"aa0dffcb5ab16eae256860de6a14fb6cf2c474b828cab2f25fdfb704fb247517")
"978803e051ac24bfc730d0dd1f746754dce0cf527357883ab71536802e4100c9"
"741e3d899a92965d92bf4dab092f647138e28b4ac06ab729333795872b26b10cfb5bcb8ed397f5f76b185c6d8a541c3a72bb925b3ab797c3f55ccdcd14215c039d0ce5c9284433be61c16a44c5b4555eac61265b346bff52e926b9c7b2f2e40e776b60386568258430d9f4e2034d4e0eb5dbc737058e8665d1d9fe123a06680c6d113440b33b70a0eeb4a625ecacf30b2de1aa86795298aed80108d0a27ff602d689d89ab73d78c4e7a4c2c744a7dc25fc82372e76f1a4df9b34d68425b10708"))
(is-false (valid-ring-signature-p/hex "f9d51e98ec2e48852e71852dd03092e403ae335d6e712c7ce7a135bda5a41833"
#("8271049ee2bb50fb308eb6a0042205494742c4ef105b3b9aa0870f8b334e32cf"
"5c68f45750e9290b069b8860cfa4d0f08f6812989c8f9fa1802f57bedf67c59c"
"cbde7ee9a3b0fd58d04dfa282e9bcba785bdb1dc60ab660676faced58f691189"
"b0b7ccf22728c75f2a5238eb9b677cfc87a34cbaa203ea1845ffefc518b9f449"
"670b179d3efed230f867f3caa7bdb61b4ab8d0cb9ef89d99ade0f58aadc69093")
"856dcd0cedbd4f363b4d8ef3a32588cbd204f2206681f7980d096505a5be2296"
"364ef7f698541b4baf8c939806ca83aec12f1f27ace2d3050da0895fa0574a0ad43c98167ac7a36901f2a2f214b0026e317207068f45de05cc4ea67fbf2b060475c1cd6d24be47b99c4f3050d84488b84064b8d307994a0361453e7b88450c0b7b8131f8a2ee22b9d41d490a45e814b86c10a4ef0b074d5dd0b5df522db111190322c6fa14f31b43577ad9d2dcd29c2d5aee632846b14522a4f722ed4647410f1c59bd0788f12ed2ca64670144c2d2ba3dbd6164a8e71eb68bb5b7a1bcbb22090936524629c736ab57bbae68db652fa719d9d45dd20218e193fbe6bdac195d0d2a73260e2e306cfce06aa220d41677c25da6cc47c21d41efe6cad282169e830d902e636613123ef44fa9c4539808a507d867fec3bc063f2fbf8f66ddeea67c07eeebc52a03ec566050f634a8f6f543b94b357bc2054b04f819c31fa16804c400"))
(is-true (valid-ring-signature-p/hex "a582c951daed8d5934300f4f62dca8cbf4afced14df907723bb998ac90ec12c6"
#("7e777ef0e3d120dd0b333d5535ccd084feff7256857ed69bc5d4a38cb8ef967e"
"7b922b179dbf6c782f5b5ba3deff76f3fed7923be210261fca1315f32eadcfdf"
"6be26c7910b76f1f489b1de8c6c35d33c68cb05e718a87ba6c23f583cefd0223"
"1c01742ccd62789422afd1236a81a1f0bf23fecae14e525a94b97bc4d337c35e"
"58364d0fc67af86879e113189d561386cfeb7d2703698e265f2a72e81c0960d6"
"114e1b802189d26234849e711ae83de1482c9957a1d96da438571da544550837"
"06ca49298a78979be29eea3112e61a7103abb873e31d594b10f2a6a0e86f2962"
"27bdd7e9a8525369473f7226a29c8609ade4548613f4d12567958dc9449245da"
"dfab8a97aac47a260e833c97c99784f105eca2c2b266471588b2caf258e49da1"
"29cd7df8c9f0bf34c0f0d9920498a83fa5b34c9fa5a96391ebbe554a62e2aeb4"
"49dc207555e9acc438336583f3c6c671cd30e955b5d03b84274f95fadb5522e2"
"bbd8d1ae66dd2034330428727878e1b720c8f57ccb33453262c8a55a4554f111"
"66b8f8d8cdc368ad72529a73ef6f6c2ccd48e10e91d78fb411cf6ea2c703211e"
"05c05274fc5d0777a32b94dfe697458f97a29040f712514e25d0541007f301e2"
"f0bbf84dbf3162a783d5bedfaf590d00a4d521a3af7a4fcd9b62acf803aa8951"
"ac6b7380a45753ce46dc4959d8138cc66e5ba88030b8e140650d34fe5cc93b87"
"6208e49329a1d34b7a83e30a5329d989c7a52b382d7ae056ca119a108815bc36"
"f824724e0b7dc12c2c0841fce07a1ecd9c77b0bd8f84c7c9250312db037632de"
"a37293bd8717467542394c42c4b7f200922fd513963c71f62bbf97f63286fd67"
"8a670ca75ac7ca3695a99953fd7e685959b1319e5b17fc3fcf53461ac3e5ae18"
"ee5d487644b9da61ef2e07b111c4028caca3ff4993adfde12540cb0c265bfc60"
"4c53c2913b5e3311968e9b7d147e473022173739c7d2a283f4977b358150a9d7"
"ce60d435e1422499aa9c207ee1cc048af47f1c605c257acb93276341b3ecb310"
"1b71c1d9d02fc8e77469d335d7e04c9b06d477fb0d10b3b0713767356a7f93be"
"2b3fdb85c9ad1028faf36e1e8f82a58ae85a0da04bd4f82a3ef8a035dd83c402"
"43b67114e107da5f5199250067cd9c3e6d2c03ac32ef9f10b94b50b4d89144e7"
"2e65c6a2613b3fe85a12812dac5af331d67470a9ee7254ab63404f30cc735eb9"
"d6699c569cad4cd4f24270477a4722c48c6f7216b6163eac31d6305f7067afb5"
"5a20cac4b501f0813d94c2f90332d45ad4bc89f20ab3825e9b694d26458288a4"
"466602c8797f666114621662a6e56c5094bf7f572bc2efc2f0cfa1515299b7cf"
"73ee2bccca9e8aef60c3759902d8989cf26d47bf4a1f02e78dfa8cbf7719cf23"
"758e7da50e467a485644fa130220ac21ce21206e92abc52b5de4b7b76632633f"
"3a2485a9d6928c4b776b5dfb776e4052089314c794b9629bf5308e8cafdb4257"
"1cbb272cb8f42c6ebfb5ef2cc2cedf29a942a1ab62c2bcf9e04ffe68e23352e8"
"9df54116d6e9da454067a67bd8b596950a25236816a11ed8e3f93d6ef35bd4a2"
"74217360442ac2659fa041595e4fa94436fc39eec0f51a8206569c4860d9ff3b"
"e12ace7aa27e1eadcc982a916c31d004c871353e7dd6a1960997d67c9f7df6ee"
"8c4961aad8ce7626cab6cb536eca3a34570313672674e858dddcf1431ed6526a"
"cabeec41334e621a0647bca137e679996f58d79a6b9f21e7b2fe91ebba7c214f"
"950ea0ed8ca85d2a215bcc940611e74bb8ff45b9a308813d7ccb2ee1c7173702"
"dfff2636aa7ac1d8bedfbe5bfef16c81bc56e71c62bbb0f67a0d4a305c4f2364"
"eb09350043d2693c5710ee8e89469c4a852932b8bc42b6cf812e116c561f176e"
"86801e1ba4f84fdd4f2a37016494e6083079bad1a035919b25645667a8d814ea"
"64ec08f43f4c387fb79e7e2e29d0e20364446db52f24e54b610adeb303b65008"
"4f561a8b4655c5ebf1a24d838457f904e705198850e8b7078a042d4089c032ea"
"9203bd689f05c6b86862be12c5118a689ac4cb97a20b9a47c4534ef8eb8daea1"
"438387551c640b3e93bf2cea525f09c4bdff7232f7aeb8c0d1c8d16b34d1816b"
"a5c0b15550e9d145a7bb651e12f9a6c3d2f7d6ee4ebf649446553b195409e118"
"a8dc6ced103efbc01c54b7c49f50d4317cdbe52f42cc3284bf5f8349ec30f255"
"42428a0d55adc561f0afae568e714581f9150131a26be30f14ca04693cf5cac6"
"b8de18764096df84c8abc3362fdf35d8e1cddb1565535dc9c4129d791d7669f1"
"5a48b75815ecb885fb1e4b26a5424f054b504bd95d04112e9d492993119a2f73"
"5808e7ec9ed1d720f4e0132ad69a3995489a4a5c04d9d6a9d9b2805b43db0575"
"14fa1dabf1b8ee746a30d935babcd4a0d0973320c762f95259b3904a978540d7"
"fceb83981e37d5b8632c248c2aaadf256e8c8e779f6af332943580e5d22cab6b"
"b0e8902ea99f6e207cbe709cc373179693361af152085f52e15dba0d928dabce"
"e3194b10a9ee8fd345bae01e1dbf69a3816acdf95d0ee6401f34540c6c1ee304"
"f89ed083f70a1a71df076746ae63b1b654586c08309578e42bf7db58238b88ed"
"a167ece1891a8888710f783127d8459681ef2b128707a8eca673fc53bdd3f621"
"427e97c7bda0632258cb6d04887226396fd36adf4addc850eb3c31644cd4e2fa"
"bdd318ae0c70b010bb3d9075295f29b46a2734237cedb5fdb814ad9826645a6f"
"4b92c0194000f161831cbfa1a358a5fbc209c9d247e554c4feab5d8947f7c359"
"062e62b52ac8e820e85c66691cc5ea4c5d389b110ede32ea28e438d1cc0b298c"
"49ab49baeeb383bff654b14105b7076dcca3c9328b4686d5ac9482d624fe361e"
"0066eae5047d3a56f8d55028ddd2f560cf8ef1df739c8542d33a57be057848d5"
"06b726f64a494d169b38d1b3b80604058bbe2ed88ba22f85845bb01ae6b6d7d9"
"4ac0793f6fea64c54a1d8c1e1b76887d248dc8e87006a449c0e2a42f7836ce93"
"e007476790e068ce71b954767e6c33af1ee388673df91c7e450964d3ed1ee5ab"
"872c3a9ab8d192ddaaeaade4211dc93b14eabfa59d3a7fc7c8cf99e1b2709293"
"c6b19b41b19a45c9424bb665e1def554052367378925083e7a5e666093fab893"
"7b7bd3121d8a1284dc8d260c4344698af9d90fd5ad93c3012801457547038443"
"ef9753c4715cda8fdfff8f703a6a7d339562fc78a496bbc15a1686576bb2a7c3"
"23eefde0e4701468bc5a0588d30dd20ef1feafd2181441731bde5d62dfc1bdda"
"ddabc1039fda5d3acba6127e2de56d863011ef403e88f6c9efaf4d7e5c1d7bc4"
"c786f77f9d06da2d020a9900f746716584c25ac75e73ea9d77437634c99fac64"
"29facbfa218b579acb3f1c6157980369904dd25c8b9bba3f9b85655b707ce974"
"a1d56bff2b43a3db39538dbfc0a0a030b9457f5ccad059a313ec873587a8e26b"
"4746c8364862d918f7ed56fd24b449e3e58fc72363b41516fad0f7a603cfbc88"
"73a9dcaba1a7fecbed9fef18d7ba61fa94cf133fde4a8c8fc9103bcae075d015"
"a1070caa8c9a71b70f2aa2167641fee3d84b54465dfa613f7d31588ab92591d7"
"cc28051cd8e0cb33fd34c55c41e2e6d58e12226c27ccbc7db8a4bb991ec7a148"
"d6d2ddfd553bb4bc300574d1d622d47f9574562ad9f2b14debbc89540909b6c0"
"13d941cdab477c153e535996ae0c95eaee640c903b57c4b3b018a867389b721d"
"402458941512fc096591e76a957e897831ef55383ed8f61b13fae2725bac8ecc"
"aa1df5777501b688a610c81359851c426de0adf15007923f00d6329b47789b34"
"28ed5fd7b6d2c7de9d011e28694f6b0fed9310c5c258e3f7c7b3e1c0455b4d0b"
"e9157b510bd88a4099af2fb74461d2930a1edd205216b78e3dd7008965a52bbe"
"8813fd003213d80b30f9390b7662bc0fc7483a79eba148949bc2c412c52a4ae2"
"1f10f5f2d4a207142eb48a4c1c06f93ae0a3ffd17a39839cd0a867c6e7c0513d"
"1b18aeaaabb0853e60bf1c08b59b707c1d375c5216a6632b7995014550bebfa0"
"c660572d346863357a6da32995a421b236bee08447a9dccf34a6d9f0033c83a6"
"9254c83a3b926bbedc4a77c5aeed4ff6c395bc53c1cba52189b492883541778a"
"e8e45c363933d25b28500a33fc3477d7034aa935e6deff9421242365d50336ba"
"11036342c257b80f34ae01f74a0511f587de23a14ec7af5ffeaa0c05fbdf2b9f"
"b215ff6f745771c6b5ebe783d7a59ccd3d9ef5fa49e6e5d7fd57116f7d67dbb8"
"8738b2f086398a81cf9fa5f691c4f01757b4ea9706ae18102e14e842d193ff26"
"b5b979f067ffb730ea01994d1fd368cafcc0745fba6f207d1cfa47cb1e31deb9"
"e76150888cabf98de831b1360ae31f92dfe3e023d81d3416696e1a726b79140b"
"4f0e961cf1b7532df4025b74fd9db339fa5a33bc74bddbef5a9612b44411a00d"
"c4e55b8a2ec30acdad6f492866ed64aec035d2d64a4a1b575e21a521855ebfb0"
"7b48df08a10e641ece5949f0375a3b7f2081e7c22931e2dfdd87f41690dae72a"
"e3fdcf909780380b7e6327318d38690e91b4de031b05b73a998e6dde02a3cdc7"
"8a33aa46e3728a78c5981d2cd1a2ac7dbd3c417073343c5a7d273ce119879e32"
"263eef94470be426658d255544839620342824cce0c99931be680468cc8d18a4"
"dd5866c6b98bee83fa4d06cd74100646ceb89255860b060322549638cd68b077"
"cabfcce35916eb6b6ab178d7d4a2237d78a329a205b7cda732965bad88d32641"
"0c28b6490f8c8a0f1447c9af700a6bc72f07f8258f61179325fe2a89827d52c1"
"4317b07c326dd869790dd4dd6fcc4718f99b4c4c3d0f029f2cd70770ed050bc9"
"769b9b3a5b3041f2af835963d1db78f5aee35184f502f3e3b5d879eac31cc4c2"
"445107e823cf3999b83afd38a2cbb6e560583362d8bf7a05c7b48d1778d50239"
"f0f66bd095b53ff80fab934b7f9499e13fcc1ed34292a0ce7a55dcdf42cc3a28"
"81a51f110ad7dff181f0718298114982881cee0f58cd9451a582a9017b1e7216"
"d4e7bc3d880fcb0371db432432562d828867df68ea9a91ddd22aa0152a9af45e"
"e55136b9047cfd2bb63ce4a5dc0baff0a2776cacf12f7da2e9517e736a408e3b"
"03f6e5607ccdb46639cf96af33a6e2ed08bc44114a74ed2c1a12b6654901cc7b"
"7edf02acec618f2e35c57f0b948055084d19ed1608dd176dc7c11028e26da083"
"1d6b6d835484f15e44bbfcc8e9c5889e0bd657e23d90803e084b40566943e9cc"
"1eae0d0fadae3ae260093a9f7d20d3590370bea77c1a30d6792925e3b3e63eb2"
"018b489de6774689d1b75e12a80694279867003175ea9b481704ee40a2443039"
"a0bf7730c7465e230bfea2aa80f19d5279793fadbf88201291871a0bf57fba54"
"3d73b9e5868fc16ca57d3b23567946bec36de5e735071f4d80c987ffbb249d67"
"848218d42e5d95da5f1946d6a3f1dbb60762acbaa94da7a8b5304a6be59c4f6a"
"586bfc8fe9396ebd08cadf8ed1a21a3ebe3db657bfb6310f82ae27c98a7ce0a0"
"b3932c83bf4a1115b20b4e02f392bb5543f84062385c93939449ade29e7c0d01"
"52ababe6202d262d9f0df1ffd29b88ff557902bf18a2da7da67dae2ba34e4720"
"d4cddf9ba86e29ddeb4d39b5a54da08cd181a1a13e1ad171c860eacc9a2a14cc"
"969c6362503b7873b2ac2c5177cb4690bb62a468011dc5363bc4699b641053c8"
"43e0b337c1a50c89ef76544c638d20dcb623274dd4fb771f143ed83781202fa3"
"23811ce42f3c2aab7801496fcda96e2e2ef10f07d82016ebc67e5a08f29a1f29"
"c2bb7bb03758868d1af742d5746bab95364dae502fad8b2f81adb31e66bc046b"
"4534db57eaff6904ed218743847e4272219e2ecd171c604961861ef448934d12"
"036ac2469c261addd54287d94935e0c12194b304d204884f23fdde78896bebe1"
"accb95e018f5030d4ce9ab2003565b0a99e93620f0a493ff28e7e637efd136a5"
"205f1bc7c6081f33add44081d3beee0b40a06adf7b040202696cd51c74b1d89e"
"17d18cf830b2ff3d5bc4cb0b94660020bdbbd307be28a88f9a234e10cdba8af8"
"7ef4ea83c78665ee3fd15ffe8be1ce70d3131fe63c3cc9b6f455412139397fa3"
"fb60752a4e870b898e7c1da122aff9fef8c806ac03d110bb7f20b4b423849005"
"e0fcf678ee4bdbe854949eddd52930d45ad6db460025e92e609de4c7c65cb80f"
"c42ea5c3097dd762915598dccd636fd00cd8326d174e9d76058aa8a169075d02"
"05de71cd2659d352263648b4ed0e3bb3da1b6995c24436153c9f035dc0f53276"
"ab055e5ba753271e3e0802100f0aa47aaeadfbd2d09fe6eafbe4a9b76861ab68"
"a6b8d764bf652b856686bc41353e9d5d25b353dd7563268fdeaac88d5fc0729a"
"22514bc3f06716ab2497d954f4f84cfd1d91ff02a3ea7af56d34ef32326a4ba9"
"56def77b87f9c0be6fa79d52976625f060c6e3858b210fb72a82ed569d5e96b2"
"c2e59b5e646385224a7e7642ee3cff28e3043ea25237920b4eaee43d159b377e"
"5c97cca046ba9457ad7c1007b4fe050d155499cf7a8fec6cf12ea25aabda8f66"
"dd94bc676e43d7b01ebfc5adbeba11fb34340b942b9e192f6171ddfe501b7e87"
"6d1e995ebe50bd4d1f2cd9ab88e985311a0a6637a7aa7b390ddaa72ee3af02bd"
"fd7da877ee9d36e1cef8f6ede184ba029e828ea9562a6adb4b277fd11482e26f"
"a80eb4834232090f3dde34fea84780eb94009a4b9f0cbc179d074d377e51bf83"
"aeed805fd70b1cb0a01e76494d96c07c038fd5a3632425707378582b810fa92f"
"2c4d509ccd0d646aaaff34a3b5471a53687265e3703360a1c40d5fcf9fff0cf7"
"6685e32dc4011c90f0c16e1c60d6d0fd761a372cb4caeaa0e4b9d6b8107082b8"
"c0056c29ec6aa1d91bdfc6446e46c2c2191ced61aac796047f17b0ae8194a55b"
"b40d597762e5c9ccd8cc034230abe7a65022f3bf447e02fe6ac5cb096d0861c9"
"7aea51bdf38d72c5cd982e5d360f4f360b965336d3641b2fc2d46b08526a6526"
"d42c2c15abcb811e69ef2b5ccd4841fb22dc7e9e30b2ed5a6c473c887e54c9c2"
"886abdb44416c9d6d01901886f639028138eecc3f492d6e684e38c9d6fbaf795"
"486c66114fdd7e688c5796c7b035eb8e5b46ada2d9645fbb6400d5bea63b4202"
"3041100d25e70ab6317a23ebb1a5877486300b4f0c850c0d06b01f7f351887ec"
"41ded15ba5471bda06972bef8b289ea41938df158b69f16dabe205c7f3c660ca"
"348f7da4a13a8909ef8a0ebb34418bcf78c384a5032e0806b01b55b943809f7c"
"75975ab8b8b041087f3978b876f57a4eab205939e6a5b97b2b5408deac941e2b"
"6495eed19b590fe2413c107db6b9674d0f19062c6e50b66d40a4749d12395118"
"618de5454c06accbbe39a2adf79dd2a220e544c6f1eaa072416c02ea129053d5"
"5c70eb68affa529603574aad33c9aa2eaa177d4c2c0050c37b8fe37f8de57274"
"60528440e957fff5b2df92f8f29541afdaa9b5f3be156d9e4196468ad83ea7c6"
"78d27cb54d8484c38ee2414806aafc2817f3e0ac41bfe2f0bc656a307dedf3a0"
"754ad4606300333ea68309a72af8e2bda16a5ce9a724afee3aa8c00e9f2bb253"
"2f8c2cf6f78998b7ab6d622a75e7ef594da389d41fc3be026c75643ab0ea5ef5"
"756a7b18cb85d7217b54ec63f21fde6524c610fdbf97381a39d28e67a3698867"
"729b775c84c83458bb8edbe6a6b4850276ba6d2c773e1b8f50bc4849c45b8d32"
"be8446cb0553866f692d9da970c1cf133fb985c636c5401415d2991836114faa"
"55be5bb652d0206e534170610f24345c8024bb6249c70376b59ad1c540fb57e9"
"44f1a4d77204ed76b1f52a4bb5b6701d74b060963508fff4e7bf77548c14e117"
"178f6aefadca48daea6f324db7ee845ecff0ad5235bd52e2fad461608c54a5e6"
"1417f0e49a9660e18720fb5728bd717156e6a0d01ddb4769b02023b2aa46cf21"
"8451aae431dc72b5ec1663eece440e91f66395aa072e0320d4dc367c86b9bae4"
"ae08120263907a46d076791ab4659fdbbe4ee78dd3b2dc13ebf58ac77b50f935"
"1c3736be9370e2276b2dadb6a1d9e7475447e51d251a9fa4d9f562f9c6d06ec7"
"eb07b2d04799ad0b2c5b67052a7adb6ec4b2727328430bd7af11b48729adeff9"
"daa8431c0f322310f524fab93801eef5f555d2b3eaed468932b8e9d99b4c12fb"
"a9502f0345859133e95ea5c1088f0ea30dc77a59fd6dd876302f0f4403cd2ee9"
"881cce607c851c9c3af9be56ed5efeb810610190bd97a5e21cb29b2d99c35880"
"3e756aea2a78b6db924cf264b34995d9814920c680d768d3a588f5729b3e066b"
"6a064f166e48d3f5252eacea19c638f7c82d98f9cfb596fda236874b3c0b6ca3"
"18b4870e1c41af197870b467bc6d9c3637f7023b6072f3eec91b3ccbd91e482a"
"ab5a825f8b3aa69bde3935f6b368974bf589ba0e7169cf008e43e2fca9d4d079"
"5045c147d2ce820ec92e3e0f242a8396b3ca87a7580980818380246f846a5d96"
"698ddac885ebf3a6779c42497eca8b7311052d698847392a1727d14009eb76a2"
"b67c19acf0c557909cc989a41cd7016e59bebb26dd69dc3dcfe14cb3f7758d33"
"3db9bf055459e8f65c80600e1d55c2049c5cada1832fbf7d28df560d98aaf2ae"
"6e9a328dd0d51cd41e7266024796d36b09c704df07c4e1a05a8afa77e725e6d3"
"eb4c727c362dea12b823d7e083b892ef253a7d4a47e5f2a063d80af7bb626a57"
"f935e42e8d15cbf966199c87518799db008d68f2cbdd776f71e1584e779764fb"
"276c5a136f0d601cb23f673381cb94352fa3fd3f17d418ec8311803529d1f5c4"
"c92fc337b78737465212db89ada40b0e3945bf72dc0ec6b7248392defb625440"
"719d06422431c811cc05f5fe4a44d1e78b2fc35d49684820e046ff6525863121"
"af051e0f78a3bf31b09844db1b015beca614903502a4dcd5cb182a77d719b72a"
"f17096eb98eca84a9140777409608f668855c948feea38fbc7dd5b03494b6f9b"
"c439e2c4f328eab3f16a2dbc8811806fdffd6f2a090203f2e4d6d69769c011f7"
"5d91fe161986a644b9834029424fea942738c38f3367b71cf2dfadd5929908c0"
"7f9c640d9ee198f29b878aa3ec222046cb4896175dd8adec8503dee054dabeb9"
"61fbd061f15c4b1a9dddcdbfad6f23c5864dffd69cba15a767bcd76ec4344d8b"
"2f6d03b695c63470dd198ecdc22e497c9aec4655cc4b56ab93290892729e095b"
"5866bf73b926457785303ab0d238f2a2ac7d65960283a5420ad9aa481aa3aae8"
"b5e5bf712c9c334d251d3f6e1d605cc77a27961a89782fdca114aa4ca4727990"
"985c78db864ae7c352d1772e069e308fb1bb5c0ccd84c0912a78324d7ce68e12"
"86f7ecaef27cee2ce9e751519bbf94e50d209cd51d1a5a43f2a0b61babcbb397"
"9e7f2cd1a3179299196f89230660b215355c5a9e6de9f014b1c6c459f09ac66a"
"9e29e28928b7637bba2bcc8dd474430a60c53543ab94ee0b7850322ed8e2121b"
"661f1f9c5c33ba9090f960f0ccef9f9267eec73de53018f84cdd126cba1f3d4b"
"e279e2c7ac9d7016356757b2a0e3bf3987d07d91e6f9838be6fbcb4bcbe57d69"
"bf081d226416a70f885d3213d5c9b727c329aa6f28e3af1ac92136f56be78035"
"c1e23dc3037d3b70fbcebe2adf18a73333fe7782a407059b1d91bd533bc12388"
"7a47c8a805559795dfa2c73d5a87752335a1d456472e9133fea8f40f589c1ac3"
"3211f0978a16a3b589163fc1787099f22f98f76fd5a75a8e331138ee64c6cbb8"
"af0c2286de54908b55e2d6e2a8b3e6416875e97ede7d53eead15a4413891d8a4"
"8d3d65bb52cf50413169a284d41f3aad96e019a3dd2397e9e00833ea6ff986b4"
"70125ac9763d647c33be36d7215abcf3244ae1d1b5f17ebbbc8400ebccb381ac"
"6c101272b368dd7328eb5f04a0f644dadbf2f92d2f972b508b286ae8a453fe28"
"1cc7cb1f04fe18d893dcc632d62edcb69fdba849163efed71da6aea8f056359a"
"8d04551c0e670766a80c552215426cf0c90332b2592f50b84b95048385b7afe5"
"33d5d1c2ab7599da6acb7c0b998128fba233a9bb547859d61193105bb4726d71"
"765980b50cdf49f16883649c1510687265372a1e03055a6f2fb4acfd157e65ac"
"47c46f77f2e1253b1e5776aacf8373de6fe2ec8e62e96fd9cbaddc1bc5e5e5e5"
"bf49253e87a9adc917ccb83071c81201d7b914f41f3ca53b6480de67d8151362"
"fcaaee825f1c8c4c5e4015ae97947f599db355be8929bc9a144e2db453ee8205"
"5f2baf493fd8893e09bb06dd07e58eef4d1642e945e4efeba2fdaef0409546b0"
"b612d4bd57994892e2cd6aaf453e5180d85661a1ef9b178f7531b9b99c7424c4"
"e7285ff2f86e42362dd946c635ed3f88bbfb6420e2a147f2926b457b13d16e57"
"b8411d43b3d19b1662e160fc1d549f2f139556846903ff9e1d2e22c38aec7a6c"
"25c2b81e7ef19e900467c3cdcc044bffd56b83900cb1629caf2fd74b6cc05ff0"
"60ffebb8283a539cfbefdd3c721a4c9f34370617f98e31590be0438697a246e9"
"b7ff6f8a03b15b02a1111e67ed2f8bd13970008ffa4fda4630bdddf504070309"
"c9c433a869678c6adda26e7cadf5cbe7091a44c184aec389b8d33559f5c793dc"
"e4cb03cd5fe163c8bee0f22bd93d4d604b965bb5125f0d637a2d531bf468b846"
"492cf9787bb24ba079c69f179566a4dfef6fa7f6b063fd880a0b3fa50ce7d761"
"47fd32b65edd4274db0f6a6eb324c99de51dbcea2d6960dae52d34b8592bc5ce"
"2f58dd0050af8b9b9c3248f969ab013af43ac9070cffa1c77f80098cf73c2f9e"
"9f06a9325889797f2ac3be70298adeb75534e165cb39a39627ee631dfe555e2a"
"cbbedc42b4d56f8c4af5f2bd446e7053340c4995bec4d40f2799963ec062e348"
"e04a87bd9d07c2b67b52db8908bd2ca3c9b062eaa8b11df80d2c5fe0f5f2d601"
"7dc1f5338c63fdcca6a935a2da04a0f0baeb984d4539a1df81fbb79baa176378"
"fdd920dc465388e08560ff174191b493ce97891b888f3a451ae59c9314db9dff"
"8a25cf6513ede70bf4c5594d927e04bfb9c48c43f7a65c5c73ee9c34e664a294"
"7b780a216daaa053e91d91c6a4ddc2c75d7a535314f1f07aa18561768994d0b2"
"92a027b8b5a143dba20d5e0f5ffd43bba074dad028d268698631ffb9f09da66b"
"dedeb8293a7099838bae80eabe5ecd081b016ad0d63849302eed21471bd315ce"
"3e2f3bd5e3ef44685f2423379dec6510e9f6d14a9d6882039888501e0966c4bd"
"0145be38e28b54ece8b6c00627e45131cca7abf3bfdbc58e6ca496975525ab09"
"56a3babf870725788bd05aef02debd57132cc0445df84c8b450235e8ba1cd4ed")
"238b52edd9a58b056c875871eb4d5091a03c63af2cf923eeef4042f649aa4f3c"
"3bf7e08289beb5ca431d681f5add4339f1496d8b5ce341678e9d3e2cf2ca870f3f52db9ba296b727bee818a26f8ca53c428ffa6f88c9428d2c076178f6ab450821e9c9ef49726f7f4a4a676712c9de91196a4a736e2af91a96aa754999fdc70ac8364c985a47adc06611a6b4888e97b3c68d0bea637d113dcdad613d63ce9c03e69d3f9393cf92dd3d307498cfc5c64b94a69170ed3805aa8baa72a1017f070c438d3b029cec4e0276e8c211c564679b4a2b7206f2d721974930a97f9dba890620c8db7d1286d2813f43ba52ba935eb3cbc5a52a97058be999f774e6512f7c0e1b25f41c1510b398dc29d4ffdf4de7447ecf9e6ada006b660d56521c00f113024090bff8dcc1b05a297d8633c33f89a5fb3865e02874dd9e77ba3a7d138bfa00a2e4b8b3927d35dd11ac6da2a236d658c9ca7e1fd5cefc7cf90d064dc9d1b203e219c7408044ea37822ccc989c0da975a55706759bf8260fd5ea7af53ada460000aa739c3f2f01adddc1a578d35dcd941318b710f5e234e2ae371e890a9e55057ca00ae5b9125cae3e0018b166ccdba9451d619041a969d348694475a3c7ff0c38cc7da2bf7b3e31f289a2e52f74a5dfb8086bb526ba6162ac8a9e2bee6e3e0f7946ceb2891b97a8cb37b689e4688bae7c771c871b8d8d821f9e5c43c2d3bb0ee9b583ea104fda8342282de6266b18bf3f6ca71faa52007478e340c14fcd510c408f4fc9d6c1e43944329c171133b981a60c2b1090b29c801f4b8c810f6d1605fae14bfb14c2ec91c8351db71523a82e0c4579a445a733ac3a72e4490527f60d19227a636bd28dcc4b6712b229fbb78891f096153e5258551282df8ec4f0620a83e53a198c6e891153114f1632d8fce38efb50bc76b36723edd02c6f70b4ba0840b7fc01119c1a2a9e5ac58288e28e453b436f1464aedf252f77862389544e077b4035d152d4fa18e4885abc20c45d28b4e885c3bed5c3dde7e793906ad58c0eb93a5eff8a8fe986a4c865e1926010361b9173476dc6bab8945e9e234ac95e01e1a2c55478e7e9f33e922b83df27bebbd4337cfb3be4401fcd72378c37851c074cc9bf3ca235846289feae7f2fe1a89502da4f0bb705aff1d6c8d8fb32db390236762c5db51045ee163790f333c343ae549e70a8c91045d9647be88460d5af004672a61f7c22bfb30d5bbb43e057d77052ca31fa34712817f0df9a1f9e667d004edc2dfa03871b0a0140ced73f6c2c052cb869fd9db328a9bd75cde31761a80e55477686ce8457846e90400c206231eb9e1b2942ab22eb2091c4b9d21dc7b10a5fc6a413aa8a432e996ce701aa4526c976761a345a1bf3c73639022957ec1b09db641bd28bd400627deec3f565f3bf487c4cd54e16aa2b5f17418cfa99dfcd0fc3dd0821d54eb9944ab68efa95b310dc202b9af900770032ee4c93349caf4b02f236b92fe120e143ac6eef76fff358220b6555937658d5f1bff743105b26120d52deed857a395ce2e596a3b2cd9f43c8e965a0b8625af2e9214623b5a66efc03c29f25e448ae8789780167938b4bc9cbcaba49a84ea29411d5683ac14ba99900f63aeb550951e630e2a41fcc409ea123315eb665695a9cb6a670b61de2919c02545c77a89ea2eb3755fa3cf7bdea6b96d67af7b3ab40a260b49af4c9228dc20b1a36eca9bec55622cbc9d06a31cf06302d1e665411dee147c22198b89b826c0172c33672d438edad8762eb86a86a9d73779c3902f34e01aa9cd7fc09111af20227366dc44451ee5f9996da793192ddd322b890dfb4d6bdfb7c389d6705bd150bc1c563e22aa99bcb61d4f59cff7b1a327b61d18914fa08db04860bee9c13bf0438fb9d50d99dd3f71d3f4fc10395aabbb5caa57f4eca212b402986cda123e30c012b7896a92f2421a57eabb2e6234129f591334c7c05f18a12b9fdd5609b4b0618c310a1aa665428b3c4c6afc1a0de6540f29a3aa61fb2b80f5767a789cf560b0b0a258e949019b22dc00fe624dbf7c12b4c917dad3b69fa370c3fc4013e310b8f8208bce4b1d322a7df5230c2462cd31bc43ffed858fa8ca7e3d08a43f72400cf97f08babcf4e34b2c522843884c53b5550d929258aeb5619c58c8473791d0dae3e341454854595c2316b5db034af4ae8393784108aeec9191ee387b4e76f058b2810727eb5e2072eb26c48c5ddb84b36d5713d8cf8495a0120f459ea41c20e076d9af81dafe4385a7e710f3102f028baaf547fe290dbefb2fefc702cbf2e0596f2d91fea8c4f8a82443b819d5a18377ce9575752989b8aa97f68fd84731505713b3c536bc69ba66b09caf47154c2943a4f66ee97db570e69187567a92c100e21af95b689c837c8761f8d226374a8083edab5d05158b282debbc14bdc076a0f0377aaf6b2cada6af53582469797f1fa1ced4eed4ed444cf01aa2811ec3734030a70fcafe67d4aa893c8c0cb7e2443a220369ec955b18c0c52657b48a363d8048b8ada4f939b468e72943301d956d6ea4cf0db24bca3fb09ec5ee91a8f466f08f33704f17465f3885703726fd293d40780971ae40b68c11ee604f23d9bf86a042aa88b723a5ab778b38b327f00548bd1d4499a9c53338fc8f24a70dc75c85d0409b6207e6d0de4a1a65cc7f2a9636fc135e0ea02967a8e4e821e17619652c20b1910eb9e415cc38b0d1384688e46820fc038229c8dac006815b8d9d82c983b0f2746936700ae5f3ab1ff280639f63f933543b5c510d8f1b367824129f0d6db0c0c89e951311d6014a653b136b4fbe7cdf8bce311f257d310e7d9b8f841d1d20e2748621d1891b637d22c879c985982dac37c1a7f5584fa79489dfa42e430e8045fd43fba05220d47df03c38ec3544f341fbe9f736b2dc3bf610cf9223ce7140e463bea322e4a7ec887685ceca4536c72145aee7fe712b9e1a9425339bddfbf0c7ce15cc1d1a4696485306be99d34f8e62108725b35681809c201e011fa9d5401af7f0da6a7076c28b268359ff7b6368634e3c7ff9d471c2ca68e7c61675a77005292f61fbbabece4e4fd14284067fe8d2929ef6848b9a6672c44598a9f0e4f0862f9744202375b932909dbad831566f57682205f6274cb2d9ddb20cdf9a78e063ac24cab8502a238364527fe0f5c1076d7e06844026563d637863af1e10b03061b224a01275854a9a73a00eddd38f2ee8ee8aaaaf7f15818a281e9f6a21cce0a3d43abf31c8bb3e110b45dbbd232c161365e02cc22a234936d8cf9c373acfa014d6ea5e81e565fefa465df27fe95a78a88b9e3b79b8aabaaa902654594d89608b529366af7356231185c91cead2e68f1248f058b8d00dc48d99e16a77b3be8046efe0ddc393c6dcfffe17c0ed655bc0aadd86add8c1374fbb79cdd7375ff1700c990f2c2b38af14e2802c527da616fd9c111e4c1f902040f8420b91d9dc9220b2d1d6384fa1fcc2c9e61264830b88b0e90ded0c39a84bb7b51158b35c03dc10a67a9eed191d1dc35f3942a259b0e1bf168ef5e50107342785fd1b47a22ccf8037a88da003eb889b52a3ac90996a3a4b711cadf8ab13825703e8fc2ce70b2d70dff64a024fcf1c0a5bd64086765d047da519f48bbf4814bfbd3faafdae32cbd0f8befc44089fa6cf8165584f8e53403333b88d5d5741ede6bbddd4367bec729068390fedcf6705f9453a6b637a10598a7ff4a16485ecdba18c34069e7ceb845060b284e2563a22e9bc275f6cb50a7df2254f0b6153b6ea6382198f8819c4f42025bb625b2509035cac8af075a88a861a10af2d92fa451d267d8c13f178cdad6092ebbe42e4e50a2a72c35fdf8cdcdd342f6424d7e9cd3ed2f0e0093020737b300361e706fe3747fe8269ab346005636f6646b6352962a458a3ce0222ed6535204d2e9d44b0ba1baf0499b6469e6697767eeaddf61b196eafbc0b29706e2515c0b534f9a3947714f4b6525b06880fcb81929830c10f6ac4d1d2457200fd7351c0b130b6fe53b3264a77e4f5d959dbb59619227c24fa6d37ee78ea72b258495030692262f5d33465da66d6a9e7905ccaba4e2a64b1986e6622641227e98590422071c5a597a1a1cfaef73ae10c03a12a501e34a5bb0c056cb541b78d6ee9d2d87057f5a914b09b0e1743789c6c21a6a3659083e1314fd08591152c1ec3530e4ff0f55bc6f3d9429f47f950076dbc4a4bb5b82563c036b0f1512b7f94db74fa1020dfd9ca1be2f2e3500ea0c3277eccfc9af2034ca57c3a76e9a7fe04dfe9610dd0d6c4e52aa8fd48cca8018e66cd45ee24b56d84ef3edcd8d14f78f835001e92d02a638b784c5a4819465d632589c01ba97bef1f3e5b2c28bcb72ac0a962a48f70925cdb445cccdf887347fd7851bc5be9a0c00914c12ca56fb8e69057552650d0428e4dfc694beae1a7e1c7cc294825d4da0e077b5a5e6b9e25c495dc602373e085c874da5079368d1016f1c13fb466ed79e45a96dacd549594bee8687221461021399058c4970a3e432ff56c8375181062a41b28f483e2a43406504cb93de3d038f5f9ae2bb6fd420099a60c5726adbcac553568254b391bc35e95f9079592306283cfa9fc2697f7fba9d4e493ce509bf9b930901233bcafbe8e79c5199e8650ae6236825df5d3a6365f2ea7c2481758df865aa069b3e2d94cd8ce4c0fade3c04c17c008b37b51b97cd8fd8b8d08f2944a443a34cca8dd66c27902b6c0bb03e09363b2acfde3bb8f5274bf57b03c1b5766fb6598ee6a4e98c583760264d7f140ad330e408f75c76c064ab68b81960b5b67805b71a4b075c4c47fc87163c061b00eddd1065213ac1eba09330c07daba241dc37024ff8f6e12e426a97a53c0ed30687e6c1a1558e27f03637580316265a0b998daa5edf5b99895e065c1b9647920f99542f723d2c1e3f0ceaa5b7783e492eae3311fd04a4a7f6295b0436a9ca9f06d478dc754b56629b88d756527bba358ff2cfdde2ce98a6535fb7e2542e8dc103db21cc05fa1c31f3cecccf16386769b3cf741f1cb974ff0f5900fa117f272b0132ae286fe18877f98cb820056797a73e780aa101a3bcf333c4226b01d1983e0e3e8401e2fd594f7975a3cddc673b6146c0274e598cc753b6cd89c079f1ef950f3434c0cb78a67e4c315dac5484624f2b26a58c1d3456a5cb77b79d80fba63b08dff6962488c456584fb3c430bf8644b715cabd707465cb6ae2cf85cdb9caa80870bc9c915b43382198d5e3f23c85cd42d0da4bf54c6c067c0e6d35efd14b040b7f4d3ea5f404b58bf91b2952fdd83b7726a897bd6c431c3f8e12052ae22ea40a7932b41c1dbf956d1d9262f196fae8ea12cbfdb0833cec974a14f954ca4bc507d87a3d10531ad0d9b6ca7379a91e95c285813a983a25120bb61180cbed53910227a7ea0f6c5c175b9198eaf2041c26ae27c54b40cc288650b9389a017cf8a50117367e01a8932b63f4808e153e7f530c50e6535117a48450939f3437f046800978be3f364ef99c212802fdc866d829df1c7d8066e686dd80e01f568492018a027ccf60c8f9234de49548b217277ee30e0772f37d32e5e9ce441f4f4d149430058c8bffa6563f51e8a3e80414a1a0f67a6312ee285f1f9011afaa9b380fa3d70864a7085cac322df9d87b26fc634c46e78c529cf2d8e2a058a10177d0a7a0fc041fa8ed5d68997761071b653da05b36b3cd056aa2d1be3f6fd74b9638f77fea00e0e20cb62ced28446f4197d15d20a63c332d75e7e47b6fa6652bd03cdca5a50e674f596d491400c35230269e16a796eb652daaf7ee938026ed2709f7df3cc70220bd06776fb86b9549e3fc6f91e0f9fe22cefbd8b181126382329f7195275f0ea3124c144c6d0743d9c69d68bf12693daf517a6c5006dc70659e9cb6053f25082023e5089b215c423907c43efb282105db94f95409bab9e2daa287741bf73e07fa18dabdb126af656cf2abe58d7d4347f7eb53ee335c71160189ef7098635e0413bc0af0f06746ae7fa94a8843cf9a246c346500d1efbe728822ab06d49de6093420a69f9c89a42a3d1a66b3d870a3d9cf1ef3887047426602b0777d847ab2059a62d72c832f5008ca5358752cdf83860bc972652f4a39d3f58074df745a420deb53e94cdcfafe794e77df270a05e90ad6712ecd0952b98d0fc5c04b4d42da0673236762a5a53a18eb5c78da44cd6a6d17e21a699eca52631fb09cf00cbf4108362981959477968ff2a8a492aea24c82102f2bf4996a33c297f784ab1f93c1003545213b6c32bac6968af83e5df1f280c4093cc49a8f4105ce2f57ff1e8ea80d91cbc882504ba080caabbb0653a1c29cd670e9f7a7998726871549a903908d02fa465831aa9e36a75c2099f65cc4ebde0788371baf35054fb80e7b6c8805b80e1133bdb22d614e210f9e2427ef025df0e7361a8aec9dfe381c5b351fd0fea00fe4a5def645b2e65443f5324c9d6f31fb3908f9616e9addf7a4e720cf4fbe2d0113f3bc0f0b8a05f5ca03a57efd3214c06b5a021f28e5467438ed8dc383e9ad01a75f33430630326fb552a041f0936a3808e99c72f18698de187f21747d4bce097a3736af7eea13679aeafbb61cea4446531fc011bae4313d2c4807c77a3a0307c89c20813d6939ae0774e4213afac54eafe7a1d192062b902899ee16cb5698092612508caa14cfaa72f85bd443b8c4fb43a37e0c2ceac4d640331e5e9fd4f60f5c410c26d7bb2bf2db6f776645b7a867cf18e37e9d03fab7cff74cf461be9b00b417547ba0368c497139c65de10cc9e09701b4460a20830c7b06f6013a4a530d903f1ebae79a059341826e696ba7d8d979c883c255d269b69a5e75b66154e303d34af0fcfc57212ca9b6d8582b148f6ce8062d3cc4eaccb7d1a5ae98aedf8307306b51b8f9cb5f7aaf4c4b27a63677f497fac65fa049aa856a7eaba520d76c09b37c629e254137e9dbe10db445d7fc9e1a20ec9ea73a4045a55da1c0d939970ec146e38cad95a5e6bb6e8855ecad1fbe65b2c3b2abeff02f52e2544525611c0d7c375559cd0491d12140520dbe24263fc5756d7ecee21b7fe7351d9a41baa70c2132cfff19cab674797ccabe2fffb03c3893308ad7c74995275675cbc441e40544cbf6c70172fee3ce115ee27c30281de5264e9bf4f3fee91b35af45f4eb080e5744fe53d448222957bf013044821cd008d7e9c3cdd30993e9a0c5e9b47d100d65ae60d687779dbdbdff5672f808d24626ef3abb5ca3236abf4d5bf44d9b190219ae329859e39ec99555af51be209f22eff843bd6bb141788522bfde6276cd0106f786872b79afd140d15b9f5e0077c2e27608d8a3dc91f23b7a38f4ae54750c6d9facf4b754d4f71a90d004a02214401e0a0f932b66bd1b9a800a50cc4c870fe5e6f6562949ba4972a99f1556606c2e731b65164584245ce0c1b321bd9edc0783ef3cf00ec9994f1b77ff911bf1d048722a177f2419ba3016f7d26f12941b007fe5da4162b7729e0ec39d39d8cbd6a0ddb2a1336029a834fca7b21fa7cb51057e28b3fce915bc6c3f10aa73531a6e117db8d2e7f432ebebda458a7cda58aa0516e679af69435b8cfa2d25220948eb57970fc6ea1664110accfc81a79b98a401832e03d589992679140b87d9f56906a5df8092da3ef1aadf3af6de87552b1006874e02a63c4befdefb631bd4fb490304f1d0db014cce6895e93a83b86565c00e3a01b39275fff5651f06d137f5530d5423a19d6541509634d05ac3db3518e20c9a77949625e201df1ef317220f137b627397d69806bb68eb496b1c4f4580ab01dd111cd59de5f93918bcc302bde5deb2c1d2e6d2d3c4ced78c9735d0fbccc80517e4a75108c797afcce407dffefeabbde80fd70313771f91b54c0cda90874b0ce1a86d51a5cd7c469675cc71010533a338b7620056116c4450810d9d67c58e02ff06a78b58fe44d1f6b9819d48f56e14ef924bd9f660814a57957f34cb2d58038b804d343b880e4beaa4529082ec56b08334123f229f876972c92bedc1504203677799d7b063ab728965b7c3ceda36cd5fcd16f51e030247155a3229a6e15e0b1306d1e3919399389c10e19120aae49f5598ffb505f9e4442db746b067e67008439144beefb1d1a687714283a9e1ea2fa26365f0e858c6999460708f6789c201a549e6cfd7327a642d72b48a23c18d5e3e8160d5cf78c4a373d795408e8556093c0dbfec80a76a5bc0bd7f06459694767734c47e5bde62c0c2efe9c1e007fe0ee88a277f7949fea8b989c4f60360262ded9b9a739b28b6a30f63f6768696fc0a3cb19bb8c57f520a62ee13476c9a975dedad480033efed154b037e4426ecf1004a3203aa8b631a4658c32267f0e47b600f0fd04a834fc1e7daec465d00b1be06251156c8747d407e851aeee3bb8876a20345c51e7a030bd7c88ba4f5eccee80c372ece2e5ae0533d7a7d36697c1d68321b542d5f9c03ab14a79927188871a60c047a44315d084089ade9616b8a9e690ab9a002c3f3d3dd4f4b3dc9dfecb33508567ff9062a25e5b14272ad76d49838b035714a59524f631402666bd7458c340c6582a86c5c596272ef2c90e09c3e78f4c78e38a6deaf3bedd5a462c2a79dcc08cbfba93ca1c2f99c9f1e7170189ef2ce81de294d321a98fa5995d0c6f4891d0bc6b335b48b7e4f8cda33f55e9f17ee8c842665746ec88e71537c8b7581c4bb02f7c2a6941ac5db1ed9419866c9271bd77c6d626f7a1d32289859a8103ab1d5090998a08c7756f4ee84807a45d2c3a6a51cd8c01604bc600fcaf6a7d752ae10064f8bd3bd2b537469ade7cee2ea0af057c3ab138662e892c77d279ba482c5b806db9d674c4236d103aaba0ed84d775c697ef12b6f46ee56eab8d9ea00e21ecf0bfdc7f180d9f3d55b56dc7d2f388a54d38827a9e1d11cd6d4141c1a1e3374d205112f5ff0280c2ad91253040b1c7e1dccd5c600a0110f064a45c48af38767680693d9e64d036d75a68607f0c7cdd2723a1ab0edc5eb53c318fd524f6432c4ff088f5e6ad692d697fb10eed10fa0709750b18b3eb33073f86eb46ecb4337077b0442529213ee94fd59568efe0e22940a923656a654c48b137b120fb19d5fac81094decdbb3cb3a084c13017782b9762a7d8d39ea6a82c0de8a7317a8072b605b07faea7774a2ac9f634c27e2a6326d3047b4a697e7293eb8463f36fbc69cc1440725ac750196ab11523f206507b29bc7f20b17718d3271c9d57cd0d06b7dd60a00132dae793261a32f438ecda9e1ce653d4739d971e604942802eee20afef0a9008fdffd3abec52df552d3503a806a0e8dbd936fce7205adab9fa933cb76632b00ca668a38289d1d21ca817814e0cb6dfa6ff8e436d061cf305cd563a0f19b3604682fc0e0452100c8d190832cb2db07b4f703b913d282d08b5fd07164c041be00a65a3a6f6ca407bd211a6602b8b284747c3143e5778531fcf7d480e2461a2f0c7af908336cdd817f3c538acd2274ae3d155f8e85cbe86c3b32001db24f6a490d6389ad820fc1d290f687a13a1533ff1d155a7a51aa64f4870931f792b74a220753804abb5fcc8851d9ece737573f76fc9ad39ad3554acfd18d971db4c06e190dc0cefbfefb4b35fcc620fd29ca6b47690803ff8e6fd1458a8eacf60639fcb005f6361c772d73a9411725a1bd2f2bedebd2179c21f30224b5bf9b30b7ffd6350497f6ce201adf6c260c599c01a506265334a6c2480f765605dea20a5f32c8ba04f9f879bcc1e48aa1f4c745796d1cdbb8c77f8116c10c546668db3631d29b910ee45088e4a7cd397a46931e9d2b7bde5288673afd79e64b89f805f100361baa0ceb68ded94cbe062c7c5f7af6ceeecde9a8f2fe85c14a23855ca57d68ab6e97099a2e31c2b8141ca99aaff4409f5f56f1d2f9d6000bcc791d74b55ce9388c52039d82ec32be2639a0b950c2d5a0e5ffcd8bc04d36c3b226b4dfe29ad9da37b3030e6c9e0f2ff9617881d73b2a80db5396c7411f4ac82918b4e15986d4cb6c430bb6f58b473993a2eca4a151b57be8a36f65d4813a139509688074892a54aef901bb3c7b79e8a4272b6075bd1550347cfd48702e5271095326782199089a2ea10a0ea0aa9d82c4769d6e7826e6a462b1ebbe1c2684e6736d8350ed45d1a5f92d091d81859c985c0657ba47cb6508fa544750d62ae4f7f4477b049770bc9f651206ff93071accc81212b1af613593f6e8b7723e9e1eec62296c3de05c5d7d612502eb42570d23aed77e46e47cc0f45d3b7e551adf6cf5cbf2e7fd02565d982100087c6ae17f315c44e8c92e15a857f2eddb4c69c5fe654178a60a96770fd002d10c57fe09512ce9d06498c7d40b16bea1b25c38a9e2ebc82f8e3d53bebd9589bc088556c0715dcb167aa83d19a1c1e2e8dd169cb2c7efd5b83dc340e0829b8c09053b1d40985c1ef909aa2179567b1f010a26112649bb7e1f7ebedbee76c7c1f606107a909f8c85caaef0170877e367eeecc3d9aec5bb55385fb649fa534a797d0c07dfa6e294443bc822646aed3b2ce80f4d2aa67549de9b92bd684bb6ff8ce40ec6163cc6cd91c27d15b9210cbc5a280a7693b37aadb17ad85af1b69d106da60dde45149398e18e493b8638ff8bddd4f34a525302e57a516a94e5ee9e8d7d7a0f2299a26c10e32e59f1b21da69d21182744bc2aa3ecf761bf5159ec4f599ee700fba8365afb0cd4fad3c5020a61fc88f756ad8da83a11a106d5ab70160a0fa201145d0497c4e73acf0b30a91f98cc7ec3eaffe8b6d6812591e1e255c5674b5c07727ef8788dcaff511a0160455faade2a751d0f768ddd1a0f2136669bce4ab70083bfe6c2023f198a0a04021455cb69a0ce7dd71486bc77bdcb3e59734725960718b447b2c4466052a7e11d59a35beb5ca7a843c296af3c06379d8cbbfb46450f0510bb8d377fa0bbb1673d75f61e8acbe1e53e9699d66fac85598562abdd900242075de95618b13d3658ff88ed68ebdd696371ec197d0185ee375f599a04280c63d53c48b7d86c22c6ed8178b04f18905c289a02a5cafc0b380fb97fa07e7d0ed36e469b713dbcca8f8f488debd2c3026eeddaf255d978189d4d4525fcf3d0038d96082264d7df7d14005c70b4d767c9ef599e127ea492a053763e59b6043408f92c28a40746d54ee58f46e21fcb74d425dc113e749e20aef10ceba44c7b050f4dd035d6ac952e78bdd8c462e163b4cdc6be5d3847d12d281aae090763b0aa0b2bc13ad765435eafd2107d8ffdb864196e331155f9db0878ddee747a47e0600b77bd69fc5fc3f12657fdbaa613e1acb6b91a0f6db838c4df23ea4bb494b5550793e4135110d2021b0329dfbfbbeb915ad643f8f12083df6e8f3f061f7faa1b0843529e38c6f98a89ef5ee061cded2c9926839ea52f7391b767cf08e4af4bfa06dfd19be30662f5c2a443bde9569216016ba38138d3bf10ab960c2f47a0f8f10f81535b49a8e9932c2d8c06e22a9e103b6b5c0cd243ab864b52f4e2ded79c040eeb6221d7069514c22d4fd7b58ba9d2854b5ded0caf538b6e364d5f3aacb37d006fe5176a4cf434323282da3b2de40c1a1b49ad8614f8d393c20ba872abac310954a68e549f5e61167015f6a5c80b76f9e4de2429566dfe11d366bff6b7ea340e2b7927dafa02552c46473150cc17e6a601deeb424caa6dbd31d5d337e1c1e70b55c67bd9967b5da0fb8122a1dc79922229e0e7eed8b64f72c7dc6a0cad737001c7b714947c03e7c73b851a5e64d6733f183db8c8f5f9ef0a92bf5a52ec540909dd4d495a09bb04f8c89e11d6fd90c7351dcdb2c5edba228b207bfc6c30571d08c4a78ee277fdbc76866ab091298d82e48beccf3d205caeb9d6227c8be88cfa035d732bd6a885ab8c8ec222002f303511d3560615330887f26645d237f5ac8709342df08e53e03223c5fbe07ece791c3f2df73f47d5bc39e73c3b5bb4cce86b033628b191832c7e98c5a8427384a261cc362f10117705f51a0f0cd00bd352800224dea1cf7af6da04266c11a01d8143173e1dd582a8a52ca2c5b5c4244f289302a9f2dd55490358e872417e5a701c4db1c7d641a3aeee47ea654ab74d625fa9090f5ce59ec92d59d79868c324b9c5d4356330c186948d78c439f4407ff9e1be066408cb50390185af8e55ca9a341d4a5cb0128f2e89a412783c80d590ade60d0731643840b57c74010424b88eb3b55e2f6e1b6b3e489b138627d9e872166a1b0159f19698932f13c51c777ef0685c0c44dd289ab71b0bfaa6cb4f176e230b360815d7812eb1d9a9fc8e69010b4efa624c53932c6ebeb9e867847d3ff4bf6df50e452ac988e53b73abb5269477224423b3e2026673bdf5d6bfdd8bf53005bfa20df6690f30d7376f06db3b61467c4341a52b9bdce9ad0cfee5725cc1c5a990730ab0802effad1c22092546facc96eb3375c45ee8cb502fd85b0fcfb33474304d02d43e091f7fc96a538c799fb35231e141c81361617b40142abfe3bdfbac3ba309db87c86ce09316e9b30929751d1e144d1cd4b577f4843a2ef7398824cd135700f14f8487543e552801284ac0884ebd84aacf05c4b0e002892e705650888bae0c6109ea2b28463585caf9a0c85e8ff6a50a4eae459b75e9e43beafd97bf362204521052a2995fce8e5f047b0db32d99e3da653f39616ab3d2cc01d0b69830920570f5c3bfdd7411d1989f250043eabf69dd46b05001bfcdc344e819d637f7ec038aea948f197f27b9ff764cf3db5590a47a1fee4c9fe37237a93640456da9930fa0fe87c483546b403c261efdf8602a125852b5959afd5569909a5c1d506891081dc923d23f15f125570288287cef161ac124eac0651539b9757d279c3499360299a3e6c92a846ef5332c5c9ee18ff7a72c94d0c86117aede903bbe5d4171030797d0f97abdf8a579e68642305392b9b32903823490b337b4d665fbf0e8a73909808518960308c8f414f9bc284f6220f3b43f07e2eda53a78a864790166c14203aff4b45b0b3665ba59843a504254650a8ec6112efe131931db2cbc83fca30e0a03fc2173622417b4ad08145ed835ab9ed64a77550f20419282b3d98f4d805008ee533dc10f302079c1a44eb9fca5ba28a247d1ed45d5b0a682b87496f925010c040c0619149884bcb30e540b78aabf4aaa670c94d4c2a3989be05aad669a3b042f5a903350ff9db50bb791bd7b22c9d10b929fa224f4d2d971bd9f98e8da520f17d0fa700faca64115f7bda12fdaced172c0a5ca6f0d3c3d9498ebe0feab1808801d3fc024d2551de3ca2e3ebc61e9d0bb3468355fbdc59d18b13bbc95053403254c8a720719be443d2f5e6789ecb21c467787040a49e7d26fe8819f95d67e0577d8be0e483e940d9b5e68e06b70deb79cc3411bc98721e1ce5bdf377da7390fd74b49b4c38a7b991bc6ac259037f92afe82e06b20ff7abbd90cffb02c58a0065de8792cd3c77450f744495944ceac7dcb1dc9abcd2dec4955b816307c116406f7c9524519e6891dece25a375636edb74055ae3290e1ed8ff3d98e6091ab3307a805ce7b753ac9d9a626526e6f0b7932adfab2cad0e1acbf04877582ec935b01f77800e27cd34d59206704e758eadd4e430f04a82264b0752eb778d448ae98054f24d7d98543a79e4b96a36eea021a44d2e35aa1ee96f5655eb5dd1a5076440b7e1b7529fb8a63d3ace684594707cebc30a6d2356c360131aa9d1ad7cfe971078f69a2fe9a63b4a383efdb398087559e66f94aba2aa9bf283472dca9abd0580a9a4f7ff1f85cc2701f8b8a57a6cee0f8d8356a2d063583c2a46d2ed1bcb4930f10f43326d88e9c7fded61b8f874c3db5e0ce74988d1b0c878143f2dde201a70ad447ba53d27516c3f069edae78e21b82d59abbc34b9acd5652beb21e089c67033bbe50ec6ac6cdbbe12ffbdc42932075de680f3cc2ae18e98808d7c083f69e0448e747d8f36b2887c14cc6072e4540b55f05f0fac2b7f794a6040a43ff7a160fbef5998845e31fca23e5bfb22c6fcee3caed163a80fbd5b893b285d2fb6a910f74cb7f2333b6617ce487af4b87a07dfe2db5308446dc2d36a6de2d32fdd1ad0b3cf68e21601ac3bf23fd5effa00cfc2c92787b8edee4b629816626019dadd20e23f9a2dcd0bf9b0feb1abd9cca1583fa3e38204bde0c958cc3528ded8ac7de093f9cf3544ba4dce3a943bb1213b3115b64293fd618deb01aaa7b90ae3dc5f60fcb30a81c0ed0f06937c83a3df75eca6877f0c488db64d1878d32087ed3ef7603ee930700da158569871bc2001242e385703f3cba03c4c966b5f06a5fd398660077200267a4d2fc92b4bc59fa8b05109f9556a964ee01eab2b4269c5e1af1ca04483ea0679231c848370fd0128329b9b0c2fe326addaa21c83be6489d4bc1ac00b41be91efa23ecb150877e15d677d8e469a4dc77a0b5f7cb58565518d1c5640923b94a28ca5c27a3d09e3c9b999913d356327d0fb065ad9b1f1f8e27587875086acad4e603a751a1c697c9a64f8255b27f3ce240930e64ffd071508fa76ee40ed08fd2dd01158c6727a5f3c17143b4f5fa40136d1827c5841de14fe037d38b0181bee1a6029ac3c1416323cabbc3e0a95b85ca7ec8216d3e1f45fc210aada9077c283e37aea921660d721e8e036f4b157016f7ff4c40aae7e0b7a11f4a9e610c5852fcb1d06b000405153fd341fe4f6b0a0c0b7bd5780496ac6b542c440b040ef15d1c1396290e2e9d54609592367511b6077a3427b2561d6af598ed2bd4eb0328232eb644c490c42ff1a245b2b47e71b0685d49f2af0b65cc9f73bb3c85200b711d36af06633265f726afa085d1f661fdf5d2f7924a7d264ad5ec8726b40f020d83b05c65e9b6c5bd455fd0dba69a512d526ca4449cfb36f0eabe174dff180fad3dc10dbbc5a13dda0c46b94c09f4a1b6c47583b72e5e45d282417ba8d23d00bdc200742e410167105563a59c08cd6299eeb74d18e4db32d7dd87cc9f09e20d635dfa6086b2959b60fc9e161b2025d832b788feda1176af5a0bc86bfc9cb6081e1d0ee48b45d95e1467adcf3d5fadb9ffc7ee049066909dadabae16fdaf920c0220fac965a3fa34576f43a5307d55b3949d6d4b34952775bf71ff4e075ab70fa38c63370c35d5c044b13e32c07e5c3db37be9f9279ff87b08b472d2262ebf0a12bda748361624edf05dcea3a02d81e522929183d2cedc3534c8f8f822bad904d95514645249676c427a4ca8fcc2c871304fbd7d28ba92f5014d7338f1571807bac768dab0709357d3da3c59a4a6faf06387cb4dce86ca2429cfb4b3bdfb4404110e382e1c97c91fb1abb519ba4eff23fcc2414abde45ed04d25a63734fa5d000e31628fd4593dd24f2c5dab9b487ef64abe41ec9c3ffb2386e049d864b9580c7fefcc65e8d2103694dc899ed6f7766a033c4d4d2849215c2bbb01f13ba6760b515f067998c8de1ee8df50e604b13483774eb023fe8b004c96cba3e85ce54d0b80858066f2bc0649f25b86a459c7b85d4d8f1bec43a772ccd28b068febf827094385e2b94e0d001925449676bc1899ae463f9c815716d74103203524a896f5067ee0d441641ba8464bc19c1a9aa549ad1fcf6fe85313d6bec97be9b642dd6b058ee7187e4d6c951712965a0aff81701b73f7b86d6c573b6c7bbc334a98aa7b0146ea57ba87550ed6e17577d32030868b5508a1011b508696cb16a29953238d092b7d17dc6b1d1c6c202899535ae91e30735c312c84aea93719c74aae4168a20ef425caf163039e7dd2a22a7774b6f0b71eda2e1ee98dcda2a420ea73f81f160848ca9568944bfe69b5f891a41c736a7bce9e327e3bd94ee8ac532d118c8f0204ade2285a08a36de6815e2b652eb1f770e08d2476bf5afd2b61270b406a54270b47d2ed113b52bbf4a558337bc777f63567c95b184eb83fa09f73a7a994132a0377e569249c794eae99ab0c8726cdc4c8ccc655f4802b38de61d14f3a75f4a20c6e25d919fd08f4a8d3a491db586bd2a267d363669c93bf6427c4550492b60f057aa02477cf20a5f21fcc7dff035ca63e134ad0e0f0e0e5c4878166c6ab204a0a79b120b106e7bdb228b5b0a8fc84e89b1d88e1e8a5812ddc7075476899363c0c60842c01eb7f75f2e2ee6c100a3d0d431d14fe2e8ac9a39a1ee48c65dbf225038143623625a9c06d99a3a1dbf1c9e94b60bcef697088f2ca8126a939d926490792547386d0053e34ba42c9d43fcec593bd879bf857666a7473ad29e5dc7c9c0146a561cbf612cf9b7d8d061aac87c0b68582ade4816b5da4b02de5e242984b0cfaceb082b3437f254e5748daafcc5d53b39039ea6638cca039ba7294faf5400bbd0f326740fc71755986c7964f54c4722a69508400f89494aa0754acaefa2200163b42a71d87454a0c9c9e224971ab4a7f0cf45d998715439566398ae1964d0b9a58af94af2b2e80734249fb36378ec00337c1be82163f9239f5a6a34b85f7003fed671cf50ebbcff41bbe6f9fdd6d02d451c02623adf37b4161601d8711640c2c5ae444c99d89bfbd3137ebd073e50c6fa79dc9ef39395b628b445f5c38a1004b196f5e8634f78db3a70a40b5bc4d08ace83bda4af8692567b4e346e7f8aa0962e36abd80adb6f2792aa2cea06bee39d17191033dec446b737bbec5c9a0580871fb3172a697bba3d041442542568ce649ae191ab33dd4b553691c6f51551009e9fee145cfc0e99aed66a7cb7ac5b24d91f4b3bd21c9031cd012857db2660e0f46a1cffc39f98008af4fe1e0eb52423dcd0553c149bfae7a60655377a23c6e050f459499c9ebee4304f4fd877cb675a12a9a0813defc5e6a09df93d89c08fb0160954081d196b5f0026d9f5e8d625c36ffb1cf9b79c1a257f8548f8dea0c5f083defc48788dee33667b2d650a13de0aabb67c2c73940b740a976b742e98c6c0b9554cdac22b19c4457097efb47ba72fc9c9e826383659e65605d311763820f0b60cd9330d77457a3f0cd8cf7df8ef123c7f60d8d0d121e0dfeb185577b251a0dbc916a97ac3281ad3b0ccfe497dd82c99e870f49b831988a886c1f5ca4141c03e63fe7ee76b5d1286a4daeb2615c88a391b53380f1a5bf1d95e04f22177a83070dd795989af041a670c4dc52c0da4001e09cf340536b96b7711eecbba5c8430f402e258a704325fd0f1e600ec440be0ff7d1838d09c1a2ffed3b457cdadb2f03dadb6d3c8cbd428acaa5e6001e6ea872cf5cde5938141b675c086209f96614074be21a64951857c339b9ecf416eaa8fe8d473d9d9b78bd85670c8e10f2ba5f0759107b57acd33c7405ca1cb1cb1723ffc117e5ba0cd141d5d26a631f79b7210b7ad52ddef3969b696e22133cf3ef2d50e58bc48474dafbf66fa6eafc46e02b070c40ea4790246abb63cc89083ad713c3f0350c7cabff4dd3dfa4754e8c2a5205ee305fdd29f3f5dd7470deb537ada7ea7deaa649e244bef5a8f3b38b304bb006780e83f66dc2bc1423b57ea36843e8dfa6b7e86a2769679018c22d2f9cf6e20649eba72b5ca058582500bc8730e681e202a4aa3b029dabbfd6f435da881b7600fa82a91304805aa83e572f4d8717310c1cb4e9f7f51a5223740acf77dd66f804fcfba94bc5c14dd91a6b73cc4fa10339589a6eca38732b38d9778e446576370f01d9c88115395903008fc03528f2b44398fb4ceefbd9d9414796ced8bbee9405317210e5489eadbaed5c8038cab5b1a8d0ad2a0dd55c8a8750fc2ff2052aaa0e13b5a0335d7fb9146c5edc543c321fc5b5bb0393e48506c82b839765f1bf2503eb0aafa46d22097c10c0b272883b5a1aef32b058b3973a2b643640445cb997048b0ec9fd79cb99dfb344d6c031947473876a00fdf7e734d51c8abf72e49320071a6ad6ff22fbb906eda52fa70084e68bcc4d6e1d3dc2dd5993f0594db87c3e06e383fa9fab4a960caf3ad3b38ca6db2ff1e0d0409b3ceef13fceb699acb8b801fad2c1f950c24225c4a9f6f06f4be8a9128239609b9576052d3f357e40975108f54c41adeba889850c290c4e7d44cfb953053c7f71b793526ac891931798200b25e1154617219644c2c0ad0dd4a29bfa991956f38e461c9bda8ff18699e32d0987223e9d5c5688310a464c684fccff97e3c0f9515f64890f05ac572154041804cd4fca52563118dade866408a8ad7139576e74873ba6ca72deed6313e818ff044941933bd6f4ae53706dbccab257bf0c1e49a169f147edf1e1524f4ac9ca640b83504fc809b1556ed3d24e4d70c081fc77ffa93ba7375980fbe6fbf4d4af8508fac5a51ccea6c9c76f3687310380428c04e553be6c5ab941ac8ac677e1a7d1035c350dadefd2f1639ef79b88451e856f3e0c005fab477ab21cfca271faf07d08c95d7d485007441aada5f7a9750c2a8f8f0979e60955152fdb3701196be0420b3c94ddde2c5324b60ee5eb95532df7c299817c57acdbca0bf1a10c98b3dc140cc5e981d097122da7d1bdcf2636cdea0908173b6a629ea6a37da7549a6a015507b63875dc43feb49b9af19a2878c8497318308443e3206614a2d4f4c7c22eb10ad201f29bc1a55465aa81654c10ffb5ee79a45bbe8ccb1e8e691a17472b252008f6d60a75673b9708903b15158d8de098596bb7a77dd9452479a8c11d4c61cb009cd49e667ef1eab89d193cbab418dadaddff1c5d9a0b5afa7262c1f3f02dcd09f26519c49db069aa7d6626ec79d74ed6e13dea532d006ef6b1b71ebeadeb80031b4d6db4a53a3b68b478e5c15e44a6dc719bdc84bdc5a8b3691cafef66bb060b6b5106d81c44a7f8b2cd0391fc99c2a9a6e3eaf93d1352ec368280104bcb590705db321c98cd4be15cd519a36f40a0cdbe57d4a022039adead487cca2118a40f31dfd594a83ce8b7aaef29fe34ff41e5f3e571372a5873eba186209e0f2ef00f03e96022005078f3576952bbd014f81e6569d854f7446d244ce13d9dde5824035ae71cebd206704ca26406b6e44b9288ed37276341b0b58bde1a0a7f7279140cee7071159b75d3c51ed1224e113fccbe84a0df0ce6d3952ac5917a63cd78f9008253b444e0d6135d7c494ca95ffefc3166e77d968fa8a4e2cdbef009dfcd240425fb5026fc3f858c6368ca16e06cee27b5ea0ed17b2ac4c1b906d6ff24dfe0061bba63c703137c9290b8c155c5dcf0c811ccf3c227bd7a959201afa3acc1ea041353038a5332cce6333aa531817b635764c6432fe454c9fa12d86a599b28db0ce5583b3eda5e1900769c95bffeffe07dfe0372373f23d64f8e967fcf895c3e0a098131029a3d753f51a03716539e9bfb3e3be6a1a65f1a04068f4a43b33a3a0e2f8dc6042c6507b80681b7d7b8754ccf3f399d281e5fe7856b32fcc39db4b6026200d90f7232bcf863ff1255098d476f2befb7456dd7660c7dc25b8e55b0120719ebc9d2a8dcd82ce8be839fe3b2afc615d317f9edd79da22146bffa11813402c3f088a66d99e5cc510ce38f37296ba485c26ea364e3a9b56954ff6ecef00f0c967b3de19a62a251a6cc11c9ff0c98562d0dc98a9919d9007619473c9d8d07088cf86df307d33bbd9b17822418891ab732f31826333d06ec0d0ba74b91f7350752ed98c28c512e98902d1004bd3e4eee7b8bcebd5b992500c25e7c1c1c2ca203ac9d7d5bc3d8a5de0a71e0fa16c5774b2a87655713d6ee1f9fb62998cbf0e306abafb5b5d91f35ac7791f6487b524e95181d203cb4e43d1e5906fea9e91f580c67e01ad955fcccdc925726af6cccd41e98f572613b87f967200563622f07050f8a612fa7ad1e4324b7dbad3b90bf510c57ff29e2a7190fee29d7df3be6bd6000b815eb40321a72c27d5ff64148e1d3803dba0e2cb87eb9ef55382243448d0d00537399bd23e6921f28a8290b37b2604d8521f878851eaacc14738a602fc25a0e457e4b4d5be617c43f98d21dd059b080cab6fb954fe9db8ab8dcd8f4e6d5260651e8f182c61b116011c27515a097d7a39d192e753cea2404271d4357948e440c1583de2a65ac68e20ef0e6f131485049cb083d4799934b92cb2339b84612e400754b157e2bb0a23c0730553dec644a3eed6c63729dbd62abba39058b51479303300d7e05ba7233e5dbc99c3b074de41c839410c8303e505af522b9be3001280e2b860fd4ae9708d40c2bc5987ea23b9d8dde7903deafab8fc2ad315635ec260299ad6242474339d70a1d05816583e64f66b398a71f3f1269c5740d29e5c8f309badc151fc2cdf4f6ef5da4ae5279183a706c70485879359dff348e1981786b032881dd913de1be14c12ce00ca3d6b14bd2d0a0e070a8d383c12dead9e49f980a7da6e5e7e2885e137e72569043c3e1498ef57659033ff85b9aabf37f0418a50bcd483234671653f16aa5c261d4b18e7de6977a4e927699365ad135714925ac038849f6702bf164e91f0b791880aa53fcf711b90d0dec3be3cb9a2641e23b1603990f47e01391232ca798c312e3dd409a6dee88c3666cd41da96145a3ededff0d05e9952ed0b4166f8119dae6d25b37f47d6dfe416ebe2a94079d860f023ca00c63dfc3ded69ba9b290c1d3ea81c2d2fbb449c213230b9ca76ba2be49e3f504053fd262e8d0268d2a8eeb76fa139c876ae05e37e59aff139032ec5ae0cdbfc10b9dfa5716f629d3b0bd93d49f50c73208fe3836ea284501f704343c0875f89c0ea2e2eabf4efaa2abcd00d0eebb77a7cbd33d99000f9d2ef486d50f671d20710cedc134391a9c13d5f4f3537fc02f89ee640c82e4ba52d873b4d92faab8d2d50ca653b96c47604f51fc5c8d2a3ce71da7639f86e6e378aff5bf651b85b335c30f0f692c82904cc1a77f45fb31a0daad87c8202016add2d673c7e04837fb8bba08f362ad489b627f645a7c78601826062b33f19740b6efc8dbeb28ce5947554e0507d53aa01bb37708ce6faf31a1d5b28c2266675ae87b957f00cee51feb974600f540046173ce79f52c837ef9ef5d884a1c440f2919dfca406e6fbc4f61abc80371e523bb913368e84804565be43717cc8735f550d47128b5538fa6ce3911a900e11529a4456980c3fadd4e6e929418e61ef866eb8066c6856e1c0b1de44e260c25c453adf17de255727896b65c2e1e432030eba916961298eea74b84c0ec2c0c9cc8b7809f48985ce096d0df1e9e78995ecf08bf6e05f718d1f9b6ec2be679048cdba58fb1a36fa50b46a4ce5653e18d7ed887bfd66490943b92e01a7e58fb0cb8dbeb379d7847ad1e85a81e2c3166d7d6c0654349fa445914ed096ccd1cec06e379c2301ecdf79f9b5525d95704710350c49e95c24474079a7afc21c448e107bd1cbe5d605adfef366aaa2c91750145416b996b9f07e73098c70147b51cb90d90a628b89b6d4df483c570153e464d7d9498b1abb47fe050f7a814f79a8ef209f8d6fac58f858bd7b5981c70975f231eeeb20f8c69ad33279f43528a8406f80a414a5fe0775aa5f763faffea74c56a6511f81fae9d6f4448f32ddcbaacd61d0345d4a7c98360a323a6d433a7028ad5a6160a770c908cd2600cf3a317b996d90ddb80294c451ddf345d687b02dd75304d2af04b28480c686df56c8a6eff30db011402c9d3cc1c23698b5a4802f8c98d6151594072a7b5c5deaef99a6f91f6ee0f0befd78190fb6b09004e4626499735999dbe9b0fc7b7fb59731757ace030b00b3d57db8d7214bb5556a13a06f851d86b5c5dbd530b93e95613fe7c0087ec9b0f60844ab9da597a202c7e7b1b4fed9508528a1b50acf7d5bb4db5ce78b6dd9e063a4a53b3b06c235bb04e3e37457018676ea86d986cc19d260a88c15b5d338403f8b8cdc91ffa1539874d333922a2b874df6fa682ee989beb19cbe55b2b12f207533a0550554465d891c16fd3042e27ce53fc47edfd8110b841c0a9a796ced4080a1fa0e46c7beb36b96e9060aab9ae09bc7d673ad5e69603b36d2753100cc50ca1fa9ed816fd2f123768e7077a90c97f166fd3f4e89dc72137ae881d04d9e3073b2f1c851f4a85b37801288f67693625a8d412cc5b6986193b10e4c70206d403af1491ffbc9334bde3168adb488101d9cb53116eb8a45c7018d603e6607c0d0b84841145327cdfae6b22bf7a77deccac02eec70806d74dc8c3e4dcd96b772307ecf65ca8b5e2446e67307e3c2bb26bcab4ff9b2104ad6c95245e39890e2f3d0a8efb3bd092150e3c11624c063007f34366c8be3d05bed1d5f697403a3f505b024ec603319da9c690b699cfe9e61783907a7eaeed71bd7af442ab60824527cc0a06d8e7ab2262a8935c69a1ae782f551f3ceb37017faf87747069089f7077c40b6b2fbb3b27392828f42950455ec1f5347f08c8a8612666f8ed6511323615db01860fbd22a0e4bcf30e5eaf944aed804b47b2595c6d72affdbfca165f50bd16058d80e5363cd7522d694f6a057cf7a4ae83b7f897c7c6c2569ed8c3ad4f0d3e098ae5c2a96cc6dd6af19aaaf7235f0727005f727d93999b24a0d91354e6bf2c0e7f46f2ee0154185f2751d0deffb4d7bd10940d305e136a58be79d7cacc57db015438d4d65d3ffa0a238e38ca55649e87e43589a3604be79aebd1292c8528070915ae108a1e861cfda8ff43424eaa3e474793296b2fa53d16957cf58283bc700f7f356355da975a1828150569a1ec3a19f348ac658cdad21cfcf6f596b30ae70a4a25c11b2903ca7cfbc149144bd418ca672dce17eb1caa101799a151553f2107df0b49f578ca8c6bdd10902cdc3e33b6b3fda35e987814fc0bae82233ec84f04c01f825c74b97049cb781734e5a1fb0a813c250be2b2927d53d97df771c32e02"))))
(test generate-ring-signature
(dotimes (i 10)
(let* ((secret-key (generate-secret-key))
(public-key (secret-key->public-key secret-key))
(key-image (compute-key-image secret-key public-key))
(data (ironclad:random-data 32))
(ring-size (+ 3 (ironclad:strong-random 8)))
(secret-index (ironclad:strong-random ring-size))
(public-keys (concatenate 'vector
(iter (repeat secret-index)
(collect (secret-key->public-key (generate-secret-key))))
(vector public-key)
(iter (repeat (- ring-size secret-index 1))
(collect (secret-key->public-key (generate-secret-key)))))))
(is-true (valid-ring-signature-p data public-keys key-image (generate-ring-signature data public-keys secret-key secret-index))))))
(test compute-multisig-blinded-secret
(let ((secret-key (hex-string->bytes "6f5631bfa0a7a4719cd2ddf3acf9ab26a93c88dc5560ebf8e426a544ccad8803")))
(is (string-equal "37086110d56edb0d244128eee6980255f427acca9b965fe4a8a26d17ff8be005"
(bytes->hex-string (compute-multisig-blinded-secret secret-key)))))
(let ((secret-key (hex-string->bytes "ddf53de98c2cde52a5daac71a7464dc4f46d7d54afad4259952ae3c97f663305")))
(is (string-equal "2198d1a8f259eee41ef087eb48559edbd5841cce739709f79767adb3fbd25104"
(bytes->hex-string (compute-multisig-blinded-secret secret-key)))))
(let ((secret-key (hex-string->bytes "8bc2f1c91767c32404b5fc906122ee5a22efb8c5c8e229477850069fda334c04")))
(is (string-equal "a8d18e7ce2e4de4c6213b9e883280ab0d6ee0c4640942151270125ffa71b500f"
(bytes->hex-string (compute-multisig-blinded-secret secret-key)))))
(let ((secret-key (hex-string->bytes "88a82e356a24ec0ec1dd497a3264c1c28741905781aecf051f89ec3dc962d101")))
(is (string-equal "f4d31e959d1dfe34619da70dbecec62fb89c29125f094cc1fcc67fd0d6d60909"
(bytes->hex-string (compute-multisig-blinded-secret secret-key)))))
(let ((secret-key (hex-string->bytes "64bf5bdbbb82c6d084b1ae8eff4b0710b372e53465c0c9d90db1bbc8dcbb9c06")))
(is (string-equal "8b9bc92fc3849735654c8e6be3fea89db96b8724b90cec21d0fea2485b062506"
(bytes->hex-string (compute-multisig-blinded-secret secret-key)))))
(let ((secret-key (hex-string->bytes "02dea042ab01454d9ca369a454cb0613c6f2c35d9009c3daf959b3d839570b02")))
(is (string-equal "aede2ddc27f47417d81832ae44f917c9d33ad3ae5f4cadb2a9b8e8c55e7c9502"
(bytes->hex-string (compute-multisig-blinded-secret secret-key)))))
(let ((secret-key (hex-string->bytes "5e41a1e789066174019f1c82fab08cb7b7ca96965d972849c06258b79224b704")))
(is (string-equal "f78e43b21da28affdaabcd00189c7f6a19458b2a695fe90b670ba8197c628b08"
(bytes->hex-string (compute-multisig-blinded-secret secret-key)))))
(let ((secret-key (hex-string->bytes "16f065708dc3f9bf6095ade6867dbd68da2968a668e67d05f14b9dcd2986f90b")))
(is (string-equal "367c0246bc866ac8e559cecd9f7890a9d96ec790b336347c5f56f99c00796900"
(bytes->hex-string (compute-multisig-blinded-secret secret-key)))))
(let ((secret-key (hex-string->bytes "0724632717bc4d9195c7d0b8c19565adaa88b8e8d62df899559eeef1d74d3e0c")))
(is (string-equal "b3e6f3b9b75b5fc2097f076c54cbd66d0d8a2b4c01723dd3e48bf85c1b38e409"
(bytes->hex-string (compute-multisig-blinded-secret secret-key)))))
(let ((secret-key (hex-string->bytes "6919108e1aa3f4402c670aa762e4554400fc3db0c26c12cc31f9e89b1b93a506")))
(is (string-equal "5b84e7b1469852fe1bf19f6057cfd72f22a84381d259f522d7f573112517750c"
(bytes->hex-string (compute-multisig-blinded-secret secret-key))))))
(test compute-multisig-secret-view-key
(let ((secret-view-keys (map 'vector
#'hex-string->bytes
#("37086110d56edb0d244128eee6980255f427acca9b965fe4a8a26d17ff8be005"
"a8d18e7ce2e4de4c6213b9e883280ab0d6ee0c4640942151270125ffa71b500f"
"8b9bc92fc3849735654c8e6be3fea89db96b8724b90cec21d0fea2485b062506"))))
(is (string-equal "7da1c35f60753f381504789f6fc6d68d8482403595376d57a0a2355f02ae550b"
(bytes->hex-string (compute-multisig-secret-view-key secret-view-keys)))))
(let ((secret-view-keys (map 'vector
#'hex-string->bytes
#("f78e43b21da28affdaabcd00189c7f6a19458b2a695fe90b670ba8197c628b08"
"b3e6f3b9b75b5fc2097f076c54cbd66d0d8a2b4c01723dd3e48bf85c1b38e409"))))
(is (string-equal "bda1410fbb9ad7690e8eddc98d6d77c326cfb6766ad126df4b97a076979a6f02"
(bytes->hex-string (compute-multisig-secret-view-key secret-view-keys))))))
(test compute-multisig-keys-n/n
(let ((secret-spend-key (hex-string->bytes "16f065708dc3f9bf6095ade6867dbd68da2968a668e67d05f14b9dcd2986f90b")))
(is (equalp #("367c0246bc866ac8e559cecd9f7890a9d96ec790b336347c5f56f99c00796900")
(map 'vector
#'bytes->hex-string
(compute-multisig-keys-n/n secret-spend-key)))))
(let ((secret-spend-key (hex-string->bytes "6919108e1aa3f4402c670aa762e4554400fc3db0c26c12cc31f9e89b1b93a506")))
(is (equalp #("5b84e7b1469852fe1bf19f6057cfd72f22a84381d259f522d7f573112517750c")
(map 'vector
#'bytes->hex-string
(compute-multisig-keys-n/n secret-spend-key))))))
(test compute-multisig-keys-m/n
(let ((public-spend-keys (map 'vector
#'hex-string->bytes
#("1892038bd30631aa5f0e056ae47f87b2ed9d72e32dc20b645ab0171d52884f42"
"49022814b64909a8c20078877610d80add01fbf6ef9f55fc7c93b2b2f9029122")))
(secret-spend-key (hex-string->bytes "ddf53de98c2cde52a5daac71a7464dc4f46d7d54afad4259952ae3c97f663305")))
(is (equalp #("ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302"
"f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07")
(map 'vector
#'bytes->hex-string
(compute-multisig-keys-m/n public-spend-keys secret-spend-key)))))
(let ((public-spend-keys (map 'vector
#'hex-string->bytes
#("eafbc2265dca6fca729f038d00a408f03624f039ea10a9be1ef3d19aaed4e856"
"49022814b64909a8c20078877610d80add01fbf6ef9f55fc7c93b2b2f9029122")))
(secret-spend-key (hex-string->bytes "88a82e356a24ec0ec1dd497a3264c1c28741905781aecf051f89ec3dc962d101")))
(is (equalp #("ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302"
"b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08")
(map 'vector
#'bytes->hex-string
(compute-multisig-keys-m/n public-spend-keys secret-spend-key)))))
(let ((public-spend-keys (map 'vector
#'hex-string->bytes
#("eafbc2265dca6fca729f038d00a408f03624f039ea10a9be1ef3d19aaed4e856"
"1892038bd30631aa5f0e056ae47f87b2ed9d72e32dc20b645ab0171d52884f42")))
(secret-spend-key (hex-string->bytes "02dea042ab01454d9ca369a454cb0613c6f2c35d9009c3daf959b3d839570b02")))
(is (equalp #("f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07"
"b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08")
(map 'vector
#'bytes->hex-string
(compute-multisig-keys-m/n public-spend-keys secret-spend-key))))))
(test compute-multisig-secret-spend-key
(let ((multisig-keys (map 'vector
#'hex-string->bytes
#("ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302"
"f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07"))))
(is (string-equal "a0e1217efc88057244e140eeea8d3279582bd540e9d895417e23d47869e29f09"
(bytes->hex-string (compute-multisig-secret-spend-key multisig-keys)))))
(let ((multisig-keys (map 'vector
#'hex-string->bytes
#("ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302"
"b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08"))))
(is (string-equal "627716ec18a622171e639cdc8349be9e85c24a124f0ab301c763838b0db4400b"
(bytes->hex-string (compute-multisig-secret-spend-key multisig-keys)))))
(let ((multisig-keys (map 'vector
#'hex-string->bytes
#("f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07"
"b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08"))))
(is (string-equal "a80d07f8df835312b683fc491b5042a42db171e26e4453ba0ad8b2142453ba0f"
(bytes->hex-string (compute-multisig-secret-spend-key multisig-keys)))))
(let ((multisig-keys (map 'vector
#'hex-string->bytes
#("367c0246bc866ac8e559cecd9f7890a9d96ec790b336347c5f56f99c00796900"))))
(is (string-equal "367c0246bc866ac8e559cecd9f7890a9d96ec790b336347c5f56f99c00796900"
(bytes->hex-string (compute-multisig-secret-spend-key multisig-keys)))))
(let ((multisig-keys (map 'vector
#'hex-string->bytes
#("5b84e7b1469852fe1bf19f6057cfd72f22a84381d259f522d7f573112517750c"))))
(is (string-equal "5b84e7b1469852fe1bf19f6057cfd72f22a84381d259f522d7f573112517750c"
(bytes->hex-string (compute-multisig-secret-spend-key multisig-keys))))))
(test compute-multisig-public-keys
(let ((multisig-keys (map 'vector
#'hex-string->bytes
#("ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302"
"f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07"))))
(is (equalp #("a768f72c3d0c4be6fc82329c99d1d66b8b5a2103c8ffd4f9011a860da6e5ac71"
"f66d79e30d769593145edae7e2aa0ac8ebbe951a827ddab8ed4c9b9a593d185a")
(map 'vector #'bytes->hex-string (compute-multisig-public-keys multisig-keys)))))
(let ((multisig-keys (map 'vector
#'hex-string->bytes
#("ada518b99a556a3b566070c0a943d739581e57b864cf7a449d57d277a9219302"
"b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08"))))
(is (equalp #("a768f72c3d0c4be6fc82329c99d1d66b8b5a2103c8ffd4f9011a860da6e5ac71"
"04d8a58ac5eb2f33cbaac5faf350523d3a3acb77fa05092e2e02bef831993c7b")
(map 'vector #'bytes->hex-string (compute-multisig-public-keys multisig-keys)))))
(let ((multisig-keys (map 'vector
#'hex-string->bytes
#("f33b09c561339b36ee80d02d414a5b3f000d7e8884091bfde0cb0101c0c00c07"
"b5d1fd327e50b8dbc7022c1cda05e7642da4f359ea3a38bd290cb1136492ad08"))))
(is (equalp #("f66d79e30d769593145edae7e2aa0ac8ebbe951a827ddab8ed4c9b9a593d185a"
"04d8a58ac5eb2f33cbaac5faf350523d3a3acb77fa05092e2e02bef831993c7b")
(map 'vector #'bytes->hex-string (compute-multisig-public-keys multisig-keys))))))
(test compute-multisig-public-spend-key
(let ((multisig-public-keys (map 'vector
#'hex-string->bytes
#("a768f72c3d0c4be6fc82329c99d1d66b8b5a2103c8ffd4f9011a860da6e5ac71"
"f66d79e30d769593145edae7e2aa0ac8ebbe951a827ddab8ed4c9b9a593d185a"
"04d8a58ac5eb2f33cbaac5faf350523d3a3acb77fa05092e2e02bef831993c7b"))))
(is (string-equal "aeb37cb931ec04d0fabae0164451f268dce585a98c5110b2dac5efe199eb9373"
(bytes->hex-string (compute-multisig-public-spend-key multisig-public-keys)))))
(let ((multisig-public-keys (map 'vector
#'hex-string->bytes
#("ce57400743c11f83b09b94ac3be9b23f5b9b756a3472d0fdf129f12475a8ebb8"
"156d6f3561c4ff39deda45d6ef841246a8ef9a4836e4fd103d7fa4bb7feb7ced"))))
(is (string-equal "2297d23c0c69d8cf76464277ceb31e6b0777750308ecfbc49667fd2ebea67bf0"
(bytes->hex-string (compute-multisig-public-spend-key multisig-public-keys))))))
| 123,907 | Common Lisp | .lisp | 840 | 121.14881 | 32,303 | 0.78411 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 5276c05181a6ae4cbfb35569fed6832a0df6fc711ae1511e1659a7b7b8b4659b | 8,041 | [
-1
] |
8,042 | miner.lisp | glv2_cl-monero-tools/monero-custom-rpc/miner.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2018-2019 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-custom-rpc)
(defparameter *mine-refresh-delay* 10)
(defun mine-block (address reserve-size &key (threads 1) (rpc-host *rpc-host*) (rpc-port *rpc-port*) (rpc-user *rpc-user*) (rpc-password *rpc-password*))
"Mine a block with several THREADS for an ADDRESS using RESERVE-SIZE
bytes of extra nonce."
(when monero-tools::*mine-lock*
(error "The mining process is already running."))
(unwind-protect
(let ((thread-handles (make-array threads :initial-element nil)))
(setf monero-tools::*mine-lock* (make-lock))
(labels ((stop-threads ()
(when (aref thread-handles 0)
(with-lock-held (monero-tools::*mine-lock*)
(setf monero-tools::*mine-stop* t))
(dotimes (i threads)
(join-thread (aref thread-handles i))
(setf (aref thread-handles i) nil))
(with-lock-held (monero-tools::*mine-lock*)
(setf monero-tools::*mine-stop* nil))))
(update-miners (template reserve-size reserve-offset difficulty)
(stop-threads)
(let ((miner (lambda ()
(miner template reserve-size reserve-offset difficulty))))
(dotimes (i threads)
(setf (aref thread-handles i) (make-thread miner))))))
(let ((data (do ()
(monero-tools::*mine-result* monero-tools::*mine-result*)
(let* ((info (get-block-template address
reserve-size
:rpc-host rpc-host
:rpc-port rpc-port
:rpc-user rpc-user
:rpc-password rpc-password))
(template (hex-string->bytes (geta info :blocktemplate-blob)))
(difficulty (geta info :difficulty))
(reserve-offset (geta info :reserved-offset))
(height (geta info :height)))
(format t "height=~a difficulty=~d~%" height difficulty)
(update-miners template reserve-size reserve-offset difficulty)
(sleep *mine-refresh-delay*)))))
(stop-threads)
(submit-block (bytes->hex-string data)
:rpc-host rpc-host
:rpc-port rpc-port
:rpc-user rpc-user
:rpc-password rpc-password))))
(setf monero-tools::*mine-stop* nil)
(setf monero-tools::*mine-lock* nil)
(setf monero-tools::*mine-result* nil)))
| 3,149 | Common Lisp | .lisp | 53 | 38.226415 | 153 | 0.48932 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 10400bc78af36021af3342a60c8eec27b49f4e1eb6f51fceccb8da36503a1a5a | 8,042 | [
-1
] |
8,043 | package.lisp | glv2_cl-monero-tools/monero-custom-rpc/package.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2019-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(defpackage :monero-custom-rpc
(:use :cl
:iterate
:monero-binary-rpc
:monero-daemon-rpc
:monero-rpc
:monero-tools
:monero-utils)
(:import-from :bordeaux-threads
#:join-thread
#:make-lock
#:make-thread
#:with-lock-held)
(:export
#:mine-block
#:transaction-history))
| 586 | Common Lisp | .lisp | 20 | 22 | 60 | 0.599291 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 78b8a6608166273c6920a628897eee26be36f91a7643a87824c8b778346eed6f | 8,043 | [
-1
] |
8,044 | history.lisp | glv2_cl-monero-tools/monero-custom-rpc/history.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2018-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-custom-rpc)
(defun transaction-history (subaddress-indexes-table secret-view-key &key secret-spend-key key-images (start-height 0) end-height verbose)
(let* ((secret-view-key (hex-string->bytes secret-view-key))
(secret-spend-key (when secret-spend-key (hex-string->bytes secret-spend-key)))
(key-images (or key-images (make-hash-table :test #'equalp)))
(end-height (or end-height (geta (get-block-count) :count)))
(history '()))
(iter (while (<= start-height end-height))
(when verbose
(format t "Block ~d~%" start-height))
(let* ((block-heights (iter (for i from start-height to (min (+ start-height 99) end-height))
(collect i)))
(transaction-ids (apply #'concatenate
'vector
(map 'list
(lambda (block)
(monero-tools::transaction-hashes (deserialize-block (geta block :block) 0)))
(geta (get-blocks-by-height.bin block-heights) :blocks))))
(transactions (map 'vector
(lambda (data)
(deserialize-transaction data 0))
(let ((txs (get-transactions (map 'vector #'bytes->hex-string transaction-ids))))
(map 'vector
(lambda (tx)
(let ((data (geta tx :as-hex)))
(when data
(hex-string->bytes data))))
(geta txs :txs))))))
(incf start-height (length block-heights))
(dotimes (j (length transactions))
(let* ((transaction (aref transactions j))
(prefix (geta transaction :prefix))
(outputs (geta prefix :outputs))
(extra (geta prefix :extra))
(transaction-public-key (monero-tools::find-extra-field extra :transaction-public-key))
(additional-public-keys (monero-tools::find-extra-field extra :additional-public-keys))
(rct-signature (geta transaction :rct-signature))
(received 0))
(dotimes (k (length outputs))
(let* ((output (aref outputs k))
(output-public-key (geta (geta output :target) :key))
(use-additional-key (= (length additional-public-keys) (length outputs)))
(derivation (derive-key (if use-additional-key
(elt additional-public-keys k)
transaction-public-key)
secret-view-key))
(public-spend-key (output-public-key->public-spend-subkey derivation
k
output-public-key))
(indexes (gethash public-spend-key subaddress-indexes-table)))
(when (and use-additional-key (null indexes))
(setf use-additional-key nil)
(setf derivation (derive-key transaction-public-key secret-view-key))
(setf public-spend-key (output-public-key->public-spend-subkey derivation
k
output-public-key))
(setf indexes (gethash public-spend-key subaddress-indexes-table)))
(when indexes
;; (multiple-value-bind (address indexes)
;; (monero-tools:output-destination-address output-public-key
;; k
;; transaction-public-key
;; additional-public-keys
;; subaddress-indexes-table
;; secret-view-key
;; :chain :stagenet)
;; (format t "Address ~a ~d/~d~%" address (first indexes) (second indexes)))
(let* ((major-index (first indexes))
(minor-index (second indexes))
(amount (if (or (null rct-signature)
(eql (geta rct-signature :type) monero-tools::+rct-type-null+))
(geta output :amount)
(let* ((ecdh-info (aref (geta rct-signature :ecdh-info) k))
(encrypted-amount (geta ecdh-info :amount)))
(decrypt-amount encrypted-amount
k
(if use-additional-key
(elt additional-public-keys k)
transaction-public-key)
secret-view-key))))
(output-secret-key (when secret-spend-key
(if (= major-index minor-index 0)
(derive-output-secret-key derivation
k
secret-spend-key)
(derive-output-secret-subkey derivation
k
secret-view-key
secret-spend-key
major-index
minor-index))))
(key-image (when output-secret-key
(compute-key-image output-secret-key output-public-key))))
(when key-image
(setf (gethash key-image key-images) amount))
(incf received amount)))))
(when (plusp received)
(when verbose
(format t "Transaction ~a~%" (bytes->hex-string (elt transaction-ids j))))
(push (list (elt transaction-ids j) received) history))
(dolist (key-image (spent-key-images transaction))
(let ((amount (gethash key-image key-images)))
(when amount
(push (list (elt transaction-ids j) (- amount)) history)
(remhash key-image key-images))))))))
(let ((total (reduce #'+ history :key #'cadr)))
(values (reverse history) total key-images))))
| 7,689 | Common Lisp | .lisp | 111 | 39.369369 | 138 | 0.407182 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 6cbd92d38b02b19fd4b64d894167d881cba9bfe43aa0f054c8a2151e4a6a64ef | 8,044 | [
-1
] |
8,045 | package.lisp | glv2_cl-monero-tools/monero-tools/package.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(defpackage :monero-tools
(:use :cl :iterate :monero-utils)
(:import-from :alexandria
#:define-constant
#:hash-table-keys
#:read-file-into-byte-vector)
(:import-from :bordeaux-threads
#:join-thread
#:make-lock
#:make-thread
#:with-lock-held)
(:import-from :cffi
#:defcstruct
#:define-foreign-library
#:foreign-funcall
#:foreign-library-loaded-p
#:inc-pointer
#:load-foreign-library-error
#:mem-aref
#:mem-ref
#:null-pointer
#:null-pointer-p
#:pointer-eq
#:use-foreign-library
#:with-foreign-object
#:with-foreign-slots)
(:import-from :ironclad
#:digest-sequence
#:encrypt
#:expt-mod
#:integer-to-octets
#:make-cipher
#:make-digest
#:octets-to-integer
#:produce-digest
#:random-data
#:strong-random
#:ub32ref/be
#:ub32ref/le
#:ub64ref/le
#:update-digest
;; Internals
#:+ed25519-b+
#:+ed25519-i+
#:+ed25519-l+
#:+ed25519-q+
#:+ed25519-point-at-infinity+
#:aes-round-keys
#:allocate-round-keys
#:copy-block
#:dotimes-unrolled
#:ec-add
#:ec-decode-point
#:ec-encode-point
#:ec-point-equal
#:ec-scalar-inv
#:ec-scalar-mult
#:ed25519-point
#:first-byte
#:fourth-byte
#:generate-round-keys-for-encryption
#:mod32+
#:mod32-
#:mod32*
#:mod64+
#:mod64-
#:mod64*
#:mod64ash
#:mod64lognot
#:rol32
#:rol64
#:ror32
#:second-byte
#:store-words
#:Te0
#:Te1
#:Te2
#:Te3
#:third-byte
#:with-words
#:xor-block)
(:import-from :octet-streams
#:get-output-stream-octets
#:make-octet-output-stream
#:with-octet-input-stream
#:with-octet-output-stream)
(:import-from :split-sequence
#:split-sequence)
(:export
;; blockchain
#:acceptable-hash-p
#:compute-block-hash #:compute-block-hash-from-data
#:compute-miner-transaction-hash #:compute-miner-transaction-hash-from-data
#:compute-transaction-hash #:compute-transaction-hash-from-data
#:compute-transaction-tree-hash
;; crypto
#:*slow-hash-variant* #:*slow-hash-height* #:*slow-hash-seed*
#:*randomx-service-host* #:*randomx-service-port*
#:fast-hash #:slow-hash #:tree-hash
#:chacha8 #:chacha20 #:generate-chacha-key
#:generate-keys #:generate-secret-key
#:secret-key->public-key #:secret-spend-key->secret-view-key
#:recover-keys
#:derive-key
#:derive-output-public-key #:derive-output-secret-key
#:derive-subkey-secret #:derive-output-secret-subkey
#:derive-secret-spend-subkey #:derive-public-spend-subkey
#:output-public-key->public-spend-subkey
#:public-spend-subkey->public-view-subkey
#:compute-subaddress-indexes-table
#:generate-signature #:valid-signature-p
#:generate-ring-signature #:valid-ring-signature-p
#:compute-key-image
#:compute-multisig-blinded-secret
#:compute-multisig-secret-view-key
#:compute-multisig-keys-n/n
#:compute-multisig-keys-m/n
#:compute-multisig-secret-spend-key
#:compute-multisig-public-keys
#:compute-multisig-public-spend-key
#:randomx-service-info
#:randomx-service-reseed
#:randomx-service-hash
#:randomx-service-hash-batch
#:randomx-seed-height
;; mine
#:modify-block-template
#:miner
#:mining-profitability
;; mnemonic
#:available-mnemonic-seed-languages
#:mnemonic-seed->secret-key #:secret-key->mnemonic-seed
#:encrypt-mnemonic-seed #:decrypt-mnemonic-seed
;; openalias
#:*dns-server*
#:*dnssec-trust-anchors*
#:get-openalias-info
;; serialization
#:serialize-block #:deserialize-block
#:serialize-block-header #:deserialize-block-header
#:serialize-transaction #:deserialize-transaction
#:serialize-transaction-prefix #:deserialize-transaction-prefix
#:serialize-to-binary-storage #:deserialize-from-binary-storage
;; wallet
#:+monero-unit+
#:decode-address #:make-integrated-address
#:public-keys->address #:secret-spend-key->address
#:public-keys->subaddress #:secret-spend-key->subaddress
#:valid-address-p
#:encrypt-payment-id #:decrypt-payment-id
#:output-for-address-p #:output-destination-address
#:decrypt-amount #:received-amount
#:spent-key-images
#:prove-payment #:valid-payment-proof-p
#:prove-inbound-transaction #:valid-inbound-transaction-proof-p
#:prove-outbound-transaction #:valid-outbound-transaction-proof-p
#:decrypt-wallet-keys
#:get-wallet-keys #:bruteforce-wallet-keys
#:sign-message #:valid-message-signature-p
#:sign-file #:valid-file-signature-p
#:make-uri #:decode-uri
#:make-qr-code #:decode-qr-code
#:make-multisig-info #:decode-multisig-info
#:make-multisig-extra-info #:decode-multisig-extra-info
#:make-multisig-seed #:decode-multisig-seed))
(in-package :monero-tools)
(defconstant +monero-unit+ #.(expt 10 12))
(defconstant +block-time+ 120)
| 6,082 | Common Lisp | .lisp | 172 | 25.436047 | 78 | 0.578403 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 2919394c2238e275f6e52b7e7991d336f25bf0f3ce18e6fe7dea52af7169118c | 8,045 | [
-1
] |
8,046 | deserialization.lisp | glv2_cl-monero-tools/monero-tools/serialization/deserialization.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-tools)
(defmacro deserialize (data offset specs)
(let ((result (gensym))
(total-size (gensym))
(object (gensym))
(size (gensym)))
(iter (for spec in specs)
(for name next (car spec))
(for reader next (cadr spec))
(for reader-parameters next (cddr spec))
(collect `(multiple-value-bind (,object ,size)
(apply ,reader ,data (+ ,offset ,total-size) (list ,@reader-parameters))
(push (cons ,(intern (string-upcase (symbol-name name)) :keyword)
,object)
,result)
(incf ,total-size ,size))
into forms)
(finally (return `(let ((,result '())
(,total-size 0))
,@forms
(values (reverse ,result) ,total-size)))))))
(defmacro deserialize-variant (data offset specs)
(let ((type (gensym))
(object (gensym))
(size (gensym)))
(iter (for spec in specs)
(for name next (car spec))
(for tag next (cadr spec))
(for reader next (caddr spec))
(for reader-parameters next (cdddr spec))
(collect `((= ,type ,tag)
(deserialize ,data (+ ,offset 1)
((,name ,reader ,@reader-parameters))))
into forms)
(finally (return `(let ((,type (aref ,data ,offset)))
(multiple-value-bind (,object ,size)
(cond ,@forms)
(if ,object
(values ,object (+ 1 ,size))
(values nil 0)))))))))
;;; Basic types
(defun deserialize-single-byte (data offset)
(values (aref data offset) 1))
(defun deserialize-bytes (data offset size)
(values (subseq data offset (+ offset size)) size))
(defun deserialize-integer (data offset)
(bytes->integer data :start offset :varint t))
(defun deserialize-vector (data offset element-reader &rest element-reader-parameters)
(multiple-value-bind (size s0)
(deserialize-integer data offset)
(let ((total-size s0)
(result (make-array size)))
(dotimes (i size)
(multiple-value-bind (e s)
(apply element-reader data (+ offset total-size) element-reader-parameters)
(setf (aref result i) e)
(incf total-size s)))
(values result total-size))))
(defun deserialize-custom-vector (data offset size element-reader &rest element-reader-parameters)
(let ((result (make-array size))
(total-size 0))
(dotimes (i size)
(multiple-value-bind (e s)
(apply element-reader data (+ offset total-size) element-reader-parameters)
(setf (aref result i) e)
(incf total-size s)))
(values result total-size)))
(defun deserialize-byte-vector (data offset)
(multiple-value-bind (size s0)
(deserialize-integer data offset)
(let ((bytes (subseq data (+ offset s0) (+ offset s0 size))))
(values bytes (+ s0 size)))))
(defun deserialize-key (data offset)
(deserialize-bytes data offset +key-length+))
(defun deserialize-hash (data offset)
(deserialize-bytes data offset +hash-length+))
;;; Transaction outputs
(defun deserialize-transaction-output-to-script (data offset)
(deserialize data offset
((keys #'deserialize-vector #'deserialize-key)
(script #'deserialize-byte-vector))))
(defun deserialize-transaction-output-to-script-hash (data offset)
(deserialize-hash data offset))
(defun deserialize-transaction-output-to-key (data offset)
(deserialize-key data offset))
(defun deserialize-transaction-output-target (data offset)
(deserialize-variant data offset
((script +transaction-output-to-script-tag+
#'deserialize-transaction-output-to-script)
(script-hash +transaction-output-to-script-hash-tag+
#'deserialize-transaction-output-to-script-hash)
(key +transaction-output-to-key-tag+
#'deserialize-transaction-output-to-key))))
(defun deserialize-transaction-output (data offset)
(deserialize data offset
((amount #'deserialize-integer)
(target #'deserialize-transaction-output-target))))
;;; Transaction inputs
(defun deserialize-transaction-input-generation (data offset)
(deserialize data offset
((height #'deserialize-integer))))
(defun deserialize-transaction-input-to-script(data offset)
(deserialize data offset
((prev #'deserialize-hash)
(prevout #'deserialize-integer)
(sigset #'deserialize-byte-vector))))
(defun deserialize-transaction-input-to-script-hash (data offset)
(deserialize data offset
((prev #'deserialize-hash)
(prevout #'deserialize-integer)
(script #'deserialize-transaction-output-to-script)
(sigset #'deserialize-byte-vector))))
(defun deserialize-transaction-input-to-key (data offset)
(deserialize data offset
((amount #'deserialize-integer)
(key-offsets #'deserialize-vector #'deserialize-integer)
(key-image #'deserialize-bytes +key-length+))))
(defun deserialize-transaction-input-target (data offset)
(deserialize-variant data offset
((generation +transaction-input-generation-tag+
#'deserialize-transaction-input-generation)
(script +transaction-input-to-script-tag+
#'deserialize-transaction-input-to-script)
(script-hash +transaction-input-to-script-hash-tag+
#'deserialize-transaction-input-to-script-hash)
(key +transaction-input-to-key-tag+
#'deserialize-transaction-input-to-key))))
;;; Signatures (before ring confidential transaction signatures)
(defun deserialize-signature (data offset ring-sizes inputs-size)
(let ((result (make-array inputs-size))
(total-size 0))
(dotimes (i inputs-size)
(multiple-value-bind (e s)
(deserialize-custom-vector data (+ offset total-size) (aref ring-sizes i)
#'deserialize-bytes (* 2 +key-length+))
(setf (aref result i) e)
(incf total-size s)))
(values result total-size)))
;;; Ring confidential transaction signatures
(defun deserialize-rct-range-proof (data offset ring-sizes inputs-size outputs-size type)
(labels ((deserialize-key64 (data offset)
(deserialize-custom-vector data offset 64 #'deserialize-key))
(deserialize-boromean-signature (data offset)
(deserialize data offset
((s0 #'deserialize-key64)
(s1 #'deserialize-key64)
(ee #'deserialize-key))))
(deserialize-range-proof (data offset)
(deserialize data offset
((boromean-signature #'deserialize-boromean-signature)
(pedersen-commitments #'deserialize-key64))))
(deserialize-multilayered-group-signature (data offset ring-size)
(deserialize data offset
((ss #'deserialize-custom-vector ring-size
#'deserialize-custom-vector
(+ 1 (if (= type +rct-type-simple+) 1 inputs-size))
#'deserialize-key)
(cc #'deserialize-key))))
(deserialize-multilayered-group-signatures (data offset)
(let* ((size (if (= type +rct-type-simple+) inputs-size 1))
(result (make-array size))
(total-size 0))
(dotimes (i size)
(multiple-value-bind (e s)
(deserialize-multilayered-group-signature data (+ offset total-size)
(aref ring-sizes i))
(setf (aref result i) e)
(incf total-size s)))
(values result total-size))))
(deserialize data offset
((range-proofs #'deserialize-custom-vector outputs-size
#'deserialize-range-proof)
(multilayered-group-signatures #'deserialize-multilayered-group-signatures)))))
(defun deserialize-rct-bulletproof (data offset ring-sizes inputs-size type)
(labels ((deserialize-bulletproof (data offset)
(deserialize data offset
((a1 #'deserialize-key)
(s #'deserialize-key)
(t1 #'deserialize-key)
(t2 #'deserialize-key)
(taux #'deserialize-key)
(mu #'deserialize-key)
(l #'deserialize-vector #'deserialize-key)
(r #'deserialize-vector #'deserialize-key)
(a2 #'deserialize-key)
(b #'deserialize-key)
(t #'deserialize-key))))
(deserialize-multilayered-group-signature (data offset ring-size)
(deserialize data offset
((ss #'deserialize-custom-vector ring-size
#'deserialize-custom-vector 2
#'deserialize-key)
(cc #'deserialize-key))))
(deserialize-multilayered-group-signatures (data offset)
(let ((result (make-array inputs-size))
(total-size 0))
(dotimes (i inputs-size)
(multiple-value-bind (e s)
(deserialize-multilayered-group-signature data (+ offset total-size)
(aref ring-sizes i))
(setf (aref result i) e)
(incf total-size s)))
(values result total-size))))
(multiple-value-bind (bulletproofs-size s0)
(if (= type +rct-type-bulletproof-2+)
(deserialize-integer data offset)
(values (bytes->integer data :start offset :end (+ offset 4)) 4))
(multiple-value-bind (rct-signature-prunable s1)
(deserialize data (+ offset s0)
((bulletproofs #'deserialize-custom-vector bulletproofs-size
#'deserialize-bulletproof)
(multilayered-group-signatures #'deserialize-multilayered-group-signatures)
(pseudo-outputs #'deserialize-custom-vector inputs-size
#'deserialize-key)))
(values rct-signature-prunable (+ s0 s1))))))
(defun deserialize-rct-clsag (data offset ring-sizes inputs-size)
(labels ((deserialize-bulletproof (data offset)
(deserialize data offset
((a1 #'deserialize-key)
(s #'deserialize-key)
(t1 #'deserialize-key)
(t2 #'deserialize-key)
(taux #'deserialize-key)
(mu #'deserialize-key)
(l #'deserialize-vector #'deserialize-key)
(r #'deserialize-vector #'deserialize-key)
(a2 #'deserialize-key)
(b #'deserialize-key)
(t #'deserialize-key))))
(deserialize-clsag-signature (data offset ring-size)
(deserialize data offset
((s #'deserialize-custom-vector ring-size
#'deserialize-key)
(c1 #'deserialize-key)
(d #'deserialize-key))))
(deserialize-clsag-signatures (data offset)
(let ((result (make-array inputs-size))
(total-size 0))
(dotimes (i inputs-size)
(multiple-value-bind (e s)
(deserialize-clsag-signature data (+ offset total-size)
(aref ring-sizes i))
(setf (aref result i) e)
(incf total-size s)))
(values result total-size))))
(multiple-value-bind (bulletproofs-size s0)
(deserialize-integer data offset)
(multiple-value-bind (rct-signature-prunable s1)
(deserialize data (+ offset s0)
((bulletproofs #'deserialize-custom-vector bulletproofs-size
#'deserialize-bulletproof)
(clsag-signatures #'deserialize-clsag-signatures)
(pseudo-outputs #'deserialize-custom-vector inputs-size
#'deserialize-key)))
(values rct-signature-prunable (+ s0 s1))))))
(defun deserialize-rct-signature (data offset ring-sizes inputs-size outputs-size)
(flet ((deserialize-pseudo-outputs (data offset type inputs-size)
(if (= type +rct-type-simple+)
(deserialize-custom-vector data offset inputs-size #'deserialize-key)
(values nil 0)))
(deserialize-ecdh-tuple (data offset)
(deserialize data offset
((mask #'deserialize-key)
(amount #'deserialize-key)))))
(let ((type (deserialize-single-byte data offset)))
(ecase type
((#.+rct-type-null+)
(values (list (cons :type type)) 1))
((#.+rct-type-full+ #.+rct-type-simple+)
(multiple-value-bind (signature size)
(deserialize data (+ offset 1)
((fee #'deserialize-integer)
(pseudo-outputs #'deserialize-pseudo-outputs type inputs-size)
(ecdh-info #'deserialize-custom-vector outputs-size
#'deserialize-ecdh-tuple)
(output-public-keys #'deserialize-custom-vector outputs-size
#'deserialize-key)
(rct-signature-prunable #'deserialize-rct-range-proof
ring-sizes inputs-size outputs-size type)))
(values (acons :type type signature)
(+ 1 size))))
((#.+rct-type-bulletproof+)
(multiple-value-bind (signature size)
(deserialize data (+ offset 1)
((fee #'deserialize-integer)
(ecdh-info #'deserialize-custom-vector outputs-size
#'deserialize-ecdh-tuple)
(output-public-keys #'deserialize-custom-vector outputs-size
#'deserialize-key)
(rct-signature-prunable #'deserialize-rct-bulletproof
ring-sizes inputs-size type)))
(values (acons :type type signature)
(+ 1 size))))
((#.+rct-type-bulletproof-2+)
(multiple-value-bind (signature size)
(deserialize data (+ offset 1)
((fee #'deserialize-integer)
(ecdh-info #'deserialize-custom-vector outputs-size
#'deserialize-bytes 8)
(output-public-keys #'deserialize-custom-vector outputs-size
#'deserialize-key)
(rct-signature-prunable #'deserialize-rct-bulletproof
ring-sizes inputs-size type)))
(values (acons :type type signature)
(+ 1 size))))
((#.+rct-type-clsag+)
(multiple-value-bind (signature size)
(deserialize data (+ offset 1)
((fee #'deserialize-integer)
(ecdh-info #'deserialize-custom-vector outputs-size
#'deserialize-bytes 8)
(output-public-keys #'deserialize-custom-vector outputs-size
#'deserialize-key)
(rct-signature-prunable #'deserialize-rct-clsag
ring-sizes inputs-size)))
(values (acons :type type signature)
(+ 1 size))))))))
;;; Transaction extra data
(defun deserialize-transaction-extra-nonce (data offset max-size)
(multiple-value-bind (nonce-size s0)
(deserialize-integer data offset)
(if (< max-size (+ s0 nonce-size))
(values nil 0)
(let ((type (aref data (+ offset s0))))
(multiple-value-bind (nonce s1)
(cond ((and (= type +transaction-extra-nonce-payment-id-tag+)
(= nonce-size 33))
(incf s0)
(deserialize data (+ offset s0)
((payment-id #'deserialize-bytes 32))))
((and (= type +transaction-extra-nonce-encrypted-payment-id-tag+)
(= nonce-size 9))
(incf s0)
(deserialize data (+ offset s0)
((encrypted-payment-id #'deserialize-bytes 8))))
(t
(deserialize data (+ offset s0)
((data #'deserialize-bytes
(min nonce-size +transaction-extra-nonce-max-size+))))))
(values nonce (+ s0 s1)))))))
(defun deserialize-transaction-extra-public-key (data offset max-size)
(if (< max-size +key-length+)
(values nil 0)
(deserialize-key data offset)))
(defun deserialize-transaction-extra-public-keys (data offset max-size)
(multiple-value-bind (vector-size s0)
(deserialize-integer data offset)
(if (< max-size (+ s0 (* vector-size +key-length+)))
(values nil 0)
(deserialize-vector data offset #'deserialize-key))))
(defun deserialize-transaction-extra-data-field (data offset max-size)
(multiple-value-bind (field size)
(handler-case
(deserialize-variant data offset
((padding +transaction-extra-padding-tag+
#'deserialize-bytes (min (- max-size 1) +transaction-extra-padding-max-size+))
(transaction-public-key +transaction-extra-public-key-tag+
#'deserialize-transaction-extra-public-key max-size)
(additional-public-keys +transaction-extra-additional-public-keys-tag+
#'deserialize-transaction-extra-public-keys max-size)
(nonce +transaction-extra-nonce-tag+
#'deserialize-transaction-extra-nonce max-size)))
(t ()
(values nil 0)))
(if (> size 1)
(values field size)
(deserialize data offset
((data #'deserialize-bytes max-size))))))
(defun deserialize-transaction-extra-data (data offset)
(multiple-value-bind (extra-data extra-data-size)
(deserialize-byte-vector data offset)
(do ((fields-size (- extra-data-size (nth-value 1 (deserialize-integer data offset))))
(fields '())
(field-offset 0))
((>= field-offset fields-size) (values (reverse fields) extra-data-size))
(multiple-value-bind (field field-size)
(deserialize-transaction-extra-data-field extra-data field-offset
(- fields-size field-offset))
(push field fields)
(incf field-offset field-size)))))
;;; Transactions
(defun deserialize-transaction-prefix (data offset)
"Return the transaction prefix whose serialization starts at OFFSET
in DATA. The second returned value is the size of the serialized
transaction prefix."
(deserialize data offset
((version #'deserialize-integer)
(unlock-time #'deserialize-integer)
(inputs #'deserialize-vector #'deserialize-transaction-input-target)
(outputs #'deserialize-vector #'deserialize-transaction-output)
(extra #'deserialize-transaction-extra-data))))
(defun deserialize-transaction (data offset)
"Return the transaction whose serialization starts at OFFSET in DATA.
The second returned value is the size of the serialized transaction."
(multiple-value-bind (prefix prefix-size)
(deserialize data offset
((prefix #'deserialize-transaction-prefix)))
(let* ((transaction-prefix (geta prefix :prefix))
(version (geta transaction-prefix :version))
(inputs (geta transaction-prefix :inputs))
(inputs-size (length inputs))
(ring-sizes (map 'vector
(lambda (input)
(length (geta (geta input :key) :key-offsets)))
inputs))
(outputs-size (length (geta transaction-prefix :outputs))))
(multiple-value-bind (signature signature-size)
(case version
((1) (deserialize data (+ offset prefix-size)
((signature #'deserialize-signature ring-sizes inputs-size))))
((2) (deserialize data (+ offset prefix-size)
((rct-signature #'deserialize-rct-signature
ring-sizes inputs-size outputs-size))))
(t (error "Transaction version ~d not supported." version)))
(values (append prefix signature) (+ prefix-size signature-size))))))
;;; Blocks
(defun deserialize-block-header (data offset)
"Return the block header whose serialization starts at OFFSET in
DATA. The second returned value is the size of the serialized block
header."
(deserialize data offset
((major-version #'deserialize-integer)
(minor-version #'deserialize-integer)
(timestamp #'deserialize-integer)
(previous-block-hash #'deserialize-hash)
(nonce #'deserialize-bytes 4))))
(defun deserialize-block (data offset)
"Return the block whose serialization starts at OFFSET in DATA.
The second returned value is the size of the serialized block."
(deserialize data offset
((header #'deserialize-block-header)
(miner-transaction #'deserialize-transaction)
(transaction-hashes #'deserialize-vector #'deserialize-hash))))
| 21,676 | Common Lisp | .lisp | 437 | 36.933638 | 100 | 0.588721 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 596f819e3ce8df632598b70d13fc8083348b813d61def0652691fbd7d0a1839b | 8,046 | [
-1
] |
8,047 | serialization.lisp | glv2_cl-monero-tools/monero-tools/serialization/serialization.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-tools)
(defmacro serialize (stream object specs)
(let ((result (gensym))
(id (gensym)))
(iter (for spec in specs)
(for name next (car spec))
(for writer next (cadr spec))
(for writer-parameters next (cddr spec))
(collect `(let ((,id ,(intern (string-upcase (symbol-name name)) :keyword)))
(apply ,writer ,result (geta ,object ,id) (list ,@writer-parameters)))
into forms)
(finally (return `(let ((,result (or ,stream (make-octet-output-stream))))
,@forms
(unless ,stream
(prog1 (get-output-stream-octets ,result)
(close ,result)))))))))
(defmacro serialize-variant (stream object specs)
(let ((result (gensym))
(type (gensym))
(thing (gensym)))
(iter (for spec in specs)
(for id next (intern (string-upcase (symbol-name (car spec))) :keyword))
(for tag next (cadr spec))
(for writer next (caddr spec))
(for writer-parameters next (cdddr spec))
(collect `((eq ,type ,id)
(write-byte ,tag ,result)
(apply ,writer ,result ,thing (list ,@writer-parameters)))
into forms)
(finally (return `(let ((,result (or ,stream (make-octet-output-stream)))
(,type (caar ,object))
(,thing (cdar object)))
(cond ,@forms)
(unless ,stream
(prog1 (get-output-stream-octets ,result)
(close ,result)))))))))
;;; Basic types
(defun serialize-single-byte (stream object)
(if stream
(write-byte object stream)
(make-array 1 :element-type '(unsigned-byte 8) :initial-element object)))
(defun serialize-bytes (stream object)
(if stream
(write-sequence object stream)
object))
(defun serialize-integer (stream object)
(let ((bytes (integer->bytes object :varint t)))
(if stream
(write-sequence bytes stream)
bytes)))
(defun serialize-vector (stream objects element-writer &rest element-writer-parameters)
(let ((size (length objects))
(result (or stream (make-octet-output-stream))))
(serialize-integer result size)
(dotimes (i size)
(apply element-writer result (aref objects i) element-writer-parameters))
(unless stream
(prog1 (get-output-stream-octets result)
(close result)))))
(defun serialize-custom-vector (stream objects element-writer &rest element-writer-parameters)
(let ((size (length objects))
(result (or stream (make-octet-output-stream))))
(dotimes (i size)
(apply element-writer result (aref objects i) element-writer-parameters))
(unless stream
(prog1 (get-output-stream-octets result)
(close result)))))
(defun serialize-byte-vector (stream object)
(if stream
(progn
(serialize-integer stream (length object))
(write-sequence object stream))
(concatenate 'octet-vector (serialize-integer nil (length object)) object)))
(defun serialize-key (stream object)
(serialize-bytes stream object))
(defun serialize-hash (stream object)
(serialize-bytes stream object))
;;; Transaction outputs
(defun serialize-transaction-output-to-script (stream object)
(serialize stream object
((keys #'serialize-vector #'serialize-key)
(script #'serialize-byte-vector))))
(defun serialize-transaction-output-to-script-hash (stream object)
(serialize-hash stream object))
(defun serialize-transaction-output-to-key (stream object)
(serialize-key stream object))
(defun serialize-transaction-output-target (stream object)
(serialize-variant stream object
((script +transaction-output-to-script-tag+
#'serialize-transaction-output-to-script)
(script-hash +transaction-output-to-script-hash-tag+
#'serialize-transaction-output-to-script-hash)
(key +transaction-output-to-key-tag+
#'serialize-transaction-output-to-key))))
(defun serialize-transaction-output (stream object)
(serialize stream object
((amount #'serialize-integer)
(target #'serialize-transaction-output-target))))
;;; Transaction inputs
(defun serialize-transaction-input-generation (stream object)
(serialize stream object
((height #'serialize-integer))))
(defun serialize-transaction-input-to-script (stream object)
(serialize stream object
((prev #'serialize-hash)
(prevout #'serialize-integer)
(sigset #'serialize-byte-vector))))
(defun serialize-transaction-input-to-script-hash (stream object)
(serialize stream object
((prev #'serialize-hash)
(prevout #'serialize-integer)
(script #'serialize-transaction-output-to-script)
(sigset #'serialize-byte-vector))))
(defun serialize-transaction-input-to-key (stream object)
(serialize stream object
((amount #'serialize-integer)
(key-offsets #'serialize-vector #'serialize-integer)
(key-image #'serialize-bytes))))
(defun serialize-transaction-input-target (stream object)
(serialize-variant stream object
((generation +transaction-input-generation-tag+
#'serialize-transaction-input-generation)
(script +transaction-input-to-script-tag+
#'serialize-transaction-input-to-script)
(script-hash +transaction-input-to-script-hash-tag+
#'serialize-transaction-input-to-script-hash)
(key +transaction-input-to-key-tag+
#'serialize-transaction-input-to-key))))
;;; Signatures (before ring confidential transaction signatures)
(defun serialize-signature (stream object)
(serialize-custom-vector stream object #'serialize-custom-vector #'serialize-bytes))
;;; Ring confidential transaction signatures
(defun serialize-rct-range-proof (stream object)
(labels ((serialize-key64 (stream object)
(serialize-custom-vector stream object #'serialize-key))
(serialize-boromean-signature (stream object)
(serialize stream object
((s0 #'serialize-key64)
(s1 #'serialize-key64)
(ee #'serialize-key))))
(serialize-range-proof (stream object)
(serialize stream object
((boromean-signature #'serialize-boromean-signature)
(pedersen-commitments #'serialize-key64))))
(serialize-multilayered-group-signature (stream object)
(serialize stream object
((ss #'serialize-custom-vector #'serialize-custom-vector #'serialize-key)
(cc #'serialize-key)))))
(when object
(serialize stream object
((range-proofs #'serialize-custom-vector #'serialize-range-proof)
(multilayered-group-signatures #'serialize-custom-vector
#'serialize-multilayered-group-signature))))))
(defun serialize-rct-bulletproof (stream object type)
(flet ((serialize-bulletproof (stream object)
(serialize stream object
((a1 #'serialize-key)
(s #'serialize-key)
(t1 #'serialize-key)
(t2 #'serialize-key)
(taux #'serialize-key)
(mu #'serialize-key)
(l #'serialize-vector #'serialize-key)
(r #'serialize-vector #'serialize-key)
(a2 #'serialize-key)
(b #'serialize-key)
(t #'serialize-key))))
(serialize-multilayered-group-signature (stream object)
(serialize stream object
((ss #'serialize-custom-vector #'serialize-custom-vector #'serialize-key)
(cc #'serialize-key)))))
(when object
(let ((bulletproofs-size (length (geta object :bulletproofs)))
(result (or stream (make-octet-output-stream))))
(if (= type +rct-type-bulletproof-2+)
(serialize-integer result bulletproofs-size)
(write-sequence (integer->bytes bulletproofs-size :size 4) result))
(serialize result object
((bulletproofs #'serialize-custom-vector #'serialize-bulletproof)
(multilayered-group-signatures #'serialize-custom-vector
#'serialize-multilayered-group-signature)
(pseudo-outputs #'serialize-custom-vector #'serialize-key)))
(unless stream
(prog1 (get-output-stream-octets result)
(close result)))))))
(defun serialize-rct-clsag (stream object)
(flet ((serialize-bulletproof (stream object)
(serialize stream object
((a1 #'serialize-key)
(s #'serialize-key)
(t1 #'serialize-key)
(t2 #'serialize-key)
(taux #'serialize-key)
(mu #'serialize-key)
(l #'serialize-vector #'serialize-key)
(r #'serialize-vector #'serialize-key)
(a2 #'serialize-key)
(b #'serialize-key)
(t #'serialize-key))))
(serialize-clsag-signature (stream object)
(serialize stream object
((s #'serialize-custom-vector #'serialize-key)
(c1 #'serialize-key)
(d #'serialize-key)))))
(when object
(let ((bulletproofs-size (length (geta object :bulletproofs)))
(result (or stream (make-octet-output-stream))))
(serialize-integer result bulletproofs-size)
(serialize result object
((bulletproofs #'serialize-custom-vector #'serialize-bulletproof)
(clsag-signatures #'serialize-custom-vector #'serialize-clsag-signature)
(pseudo-outputs #'serialize-custom-vector #'serialize-key)))
(unless stream
(prog1 (get-output-stream-octets result)
(close result)))))))
(defun serialize-rct-signature (stream object)
(flet ((serialize-pseudo-outputs (stream object type)
(when (= type +rct-type-simple+)
(serialize-custom-vector stream object #'serialize-key)))
(serialize-ecdh-tuple (stream object)
(serialize stream object
((mask #'serialize-key)
(amount #'serialize-key)))))
(let ((type (geta object :type))
(result (or stream (make-octet-output-stream))))
(write-byte type result)
(ecase type
((#.+rct-type-null+)
nil)
((#.+rct-type-full+ #.+rct-type-simple+)
(serialize result object
((fee #'serialize-integer)
(pseudo-outputs #'serialize-pseudo-outputs type)
(ecdh-info #'serialize-custom-vector #'serialize-ecdh-tuple)
(output-public-keys #'serialize-custom-vector #'serialize-key)
(rct-signature-prunable #'serialize-rct-range-proof))))
((#.+rct-type-bulletproof+)
(serialize result object
((fee #'serialize-integer)
(ecdh-info #'serialize-custom-vector #'serialize-ecdh-tuple)
(output-public-keys #'serialize-custom-vector #'serialize-key)
(rct-signature-prunable #'serialize-rct-bulletproof type))))
((#.+rct-type-bulletproof-2+)
(serialize result object
((fee #'serialize-integer)
(ecdh-info #'serialize-custom-vector #'serialize-bytes)
(output-public-keys #'serialize-custom-vector #'serialize-key)
(rct-signature-prunable #'serialize-rct-bulletproof type))))
((#.+rct-type-clsag+)
(serialize result object
((fee #'serialize-integer)
(ecdh-info #'serialize-custom-vector #'serialize-bytes)
(output-public-keys #'serialize-custom-vector #'serialize-key)
(rct-signature-prunable #'serialize-rct-clsag)))))
(unless stream
(prog1 (get-output-stream-octets result)
(close result))))))
;;; Transaction extra data
(defun serialize-transaction-extra-nonce (stream object)
(let ((bytes (with-octet-output-stream (result)
(let ((type (caar object))
(data (cdar object)))
(when (> (length data) +transaction-extra-nonce-max-size+)
(error "Too much data in nonce"))
(case type
((:payment-id)
(write-byte +transaction-extra-nonce-payment-id-tag+ result))
((:encrypted-payment-id)
(write-byte +transaction-extra-nonce-encrypted-payment-id-tag+ result)))
(serialize-bytes result data))))
(result (or stream (make-octet-output-stream))))
(serialize-byte-vector result bytes)
(unless stream
(prog1 (get-output-stream-octets result)
(close result)))))
(defun serialize-transaction-extra-data-field (stream object)
(let ((result (serialize-variant nil object
((padding +transaction-extra-padding-tag+
(lambda (stream data)
(if (> (length data) +transaction-extra-padding-max-size+)
(error "Too much data in padding.")
(serialize-bytes stream data))))
(transaction-public-key +transaction-extra-public-key-tag+
#'serialize-key)
(additional-public-keys +transaction-extra-additional-public-keys-tag+
#'serialize-vector #'serialize-key)
(nonce +transaction-extra-nonce-tag+
#'serialize-transaction-extra-nonce)))))
(cond
((zerop (length result)) (serialize stream object
((data #'serialize-bytes))))
(stream (write-sequence result stream))
(t result))))
(defun serialize-transaction-extra-data (stream object)
(serialize-byte-vector stream (with-octet-output-stream (result)
(dolist (field object)
(serialize-transaction-extra-data-field result field)))))
;;; Transactions
(defun serialize-transaction-prefix (stream object)
"Return a transaction prefix OBJECT as a byte vector."
(serialize stream object
((version #'serialize-integer)
(unlock-time #'serialize-integer)
(inputs #'serialize-vector #'serialize-transaction-input-target)
(outputs #'serialize-vector #'serialize-transaction-output)
(extra #'serialize-transaction-extra-data))))
(defun serialize-transaction (stream object)
"Return a transaction OBJECT as a byte vector."
(let ((version (geta (geta object :prefix) :version)))
(case version
((1) (serialize stream object
((prefix #'serialize-transaction-prefix)
(signature #'serialize-signature))))
((2) (serialize stream object
((prefix #'serialize-transaction-prefix)
(rct-signature #'serialize-rct-signature))))
(t (error "Transaction version ~d not supported." version)))))
;;; Blocks
(defun serialize-block-header (stream object)
"Return a block header OBJECT as a byte vector."
(serialize stream object
((major-version #'serialize-integer)
(minor-version #'serialize-integer)
(timestamp #'serialize-integer)
(previous-block-hash #'serialize-hash)
(nonce #'serialize-bytes))))
(defun serialize-block (stream object)
"Return a block OBJECT as a byte vector."
(serialize stream object
((header #'serialize-block-header)
(miner-transaction #'serialize-transaction)
(transaction-hashes #'serialize-vector #'serialize-hash))))
| 15,993 | Common Lisp | .lisp | 336 | 37.041667 | 94 | 0.618492 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 1e87b48d61140bc1ebb1704960dfb998053d7d2bb191458fc6d9184c930aec8c | 8,047 | [
-1
] |
8,048 | constants.lisp | glv2_cl-monero-tools/monero-tools/serialization/constants.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-tools)
;;; Blocks
(defconstant +block-tag+ 187)
;;; Transactions
(defconstant +transaction-tag+ 204)
;; Transaction inputs
(defconstant +transaction-input-generation-tag+ 255)
(defconstant +transaction-input-to-script-tag+ 0)
(defconstant +transaction-input-to-script-hash-tag+ 1)
(defconstant +transaction-input-to-key-tag+ 2)
;; Transaction outputs
(defconstant +transaction-output-to-script-tag+ 0)
(defconstant +transaction-output-to-script-hash-tag+ 1)
(defconstant +transaction-output-to-key-tag+ 2)
;; Ring confidential transaction signatures
(defconstant +rct-type-null+ 0)
(defconstant +rct-type-full+ 1)
(defconstant +rct-type-simple+ 2)
(defconstant +rct-type-bulletproof+ 3)
(defconstant +rct-type-bulletproof-2+ 4)
(defconstant +rct-type-clsag+ 5)
(defconstant +rct-key-tag+ 144)
(defconstant +rct-key64-tag+ 145)
(defconstant +rct-key-vector-tag+ 146)
(defconstant +rct-key-matrix-tag+ 147)
(defconstant +rct-ctkey-tag+ 148)
(defconstant +rct-ctkey-vector-tag+ 149)
(defconstant +rct-ctkey-matrix-tag+ 150)
(defconstant +rct-ecdh-tuple-tag+ 151)
(defconstant +rct-multilayered-group-signature-tag+ 152)
(defconstant +rct-range-proof-tag+ 153)
(defconstant +rct-boromean-signature-tag+ 154)
(defconstant +rct-rct-signature-tag+ 155)
;; Transaction extra data
(defconstant +transaction-extra-padding-tag+ 0)
(defconstant +transaction-extra-public-key-tag+ 1)
(defconstant +transaction-extra-nonce-tag+ 2)
(defconstant +transaction-extra-merge-mining-tag+ 3)
(defconstant +transaction-extra-additional-public-keys-tag+ 4)
(defconstant +transaction-extra-nonce-payment-id-tag+ 0)
(defconstant +transaction-extra-nonce-encrypted-payment-id-tag+ 1)
(defconstant +transaction-extra-padding-max-size+ 254)
(defconstant +transaction-extra-nonce-max-size+ 254)
;;; Portable storage
(define-constant +portable-storage-signature-a+ #(1 17 1 1) :test #'equalp)
(define-constant +portable-storage-signature-b+ #(1 1 2 1) :test #'equalp)
(defconstant +portable-storage-format-version+ 1)
(define-constant +portable-storage-header+
(concatenate 'octet-vector
+portable-storage-signature-a+
+portable-storage-signature-b+
(vector +portable-storage-format-version+))
:test #'equalp)
(defconstant +portable-storage-raw-size-byte+ 0)
(defconstant +portable-storage-raw-size-word+ 1)
(defconstant +portable-storage-raw-size-double-word+ 2)
(defconstant +portable-storage-raw-size-quad-word+ 3)
(defconstant +portable-storage-type-int64+ 1)
(defconstant +portable-storage-type-int32+ 2)
(defconstant +portable-storage-type-int16+ 3)
(defconstant +portable-storage-type-int8+ 4)
(defconstant +portable-storage-type-uint64+ 5)
(defconstant +portable-storage-type-uint32+ 6)
(defconstant +portable-storage-type-uint16+ 7)
(defconstant +portable-storage-type-uint8+ 8)
(defconstant +portable-storage-type-double+ 9)
(defconstant +portable-storage-type-string+ 10)
(defconstant +portable-storage-type-bool+ 11)
(defconstant +portable-storage-type-object+ 12)
(defconstant +portable-storage-type-array+ 13)
(defconstant +portable-storage-array-flag+ 128)
| 3,328 | Common Lisp | .lisp | 75 | 42.413333 | 75 | 0.774552 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | c01fb10650ff46fd23e848986d83a1f58d7d76d65053e24629f4c4b305313fc0 | 8,048 | [
-1
] |
8,049 | storage.lisp | glv2_cl-monero-tools/monero-tools/serialization/storage.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2018 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-tools)
(defun lisp-type->storage-type (type)
(cond
((subtypep type '(signed-byte 8)) +portable-storage-type-int8+)
((subtypep type '(unsigned-byte 8)) +portable-storage-type-uint8+)
((subtypep type '(signed-byte 16)) +portable-storage-type-int16+)
((subtypep type '(unsigned-byte 16)) +portable-storage-type-uint16+)
((subtypep type '(signed-byte 32)) +portable-storage-type-int32+)
((subtypep type '(unsigned-byte 32)) +portable-storage-type-uint32+)
((subtypep type '(signed-byte 64)) +portable-storage-type-int64+)
((subtypep type '(unsigned-byte 64)) +portable-storage-type-uint64+)
((subtypep type 'float) +portable-storage-type-double+)
((subtypep type 'string) +portable-storage-type-string+)
((subtypep type 'boolean) +portable-storage-type-bool+)
((subtypep type 'list) +portable-storage-type-object+)
((subtypep type 'vector) +portable-storage-type-array+)
(t (error "couldn't determine storage type for lisp type: ~a" type))))
(defun storage-type->lisp-type (type)
(ecase type
((#.+portable-storage-type-int64+) '(signed-byte 64))
((#.+portable-storage-type-int32+) '(signed-byte 32))
((#.+portable-storage-type-int16+) '(signed-byte 16))
((#.+portable-storage-type-int8+) '(signed-byte 8))
((#.+portable-storage-type-uint64+) '(unsigned-byte 64))
((#.+portable-storage-type-uint32+) '(unsigned-byte 32))
((#.+portable-storage-type-uint16+) '(unsigned-byte 16))
((#.+portable-storage-type-uint8+) '(unsigned-byte 8))
((#.+portable-storage-type-double+) 'double-float)
((#.+portable-storage-type-string+) 'simple-string)
((#.+portable-storage-type-bool+) 'boolean)
((#.+portable-storage-type-object+) 'list)
((#.+portable-storage-type-array+) 'simple-vector)))
(defun storage-type->serialization-function (type)
(ecase type
((#.+portable-storage-type-int64+) #'storage-serialize-int64)
((#.+portable-storage-type-int32+) #'storage-serialize-int32)
((#.+portable-storage-type-int16+) #'storage-serialize-int16)
((#.+portable-storage-type-int8+) #'storage-serialize-int8)
((#.+portable-storage-type-uint64+) #'storage-serialize-uint64)
((#.+portable-storage-type-uint32+) #'storage-serialize-uint32)
((#.+portable-storage-type-uint16+) #'storage-serialize-uint16)
((#.+portable-storage-type-uint8+) #'storage-serialize-uint8)
((#.+portable-storage-type-double+) #'storage-serialize-double-float)
((#.+portable-storage-type-string+) #'storage-serialize-string)
((#.+portable-storage-type-bool+) #'storage-serialize-boolean)
((#.+portable-storage-type-object+) #'storage-serialize-section)
((#.+portable-storage-type-array+) #'storage-serialize-vector)))
(defun storage-type->deserialization-function (type)
(ecase type
((#.+portable-storage-type-int64+) #'storage-deserialize-int64)
((#.+portable-storage-type-int32+) #'storage-deserialize-int32)
((#.+portable-storage-type-int16+) #'storage-deserialize-int16)
((#.+portable-storage-type-int8+) #'storage-deserialize-int8)
((#.+portable-storage-type-uint64+) #'storage-deserialize-uint64)
((#.+portable-storage-type-uint32+) #'storage-deserialize-uint32)
((#.+portable-storage-type-uint16+) #'storage-deserialize-uint16)
((#.+portable-storage-type-uint8+) #'storage-deserialize-uint8)
((#.+portable-storage-type-double+) #'storage-deserialize-double-float)
((#.+portable-storage-type-string+) #'storage-deserialize-string)
((#.+portable-storage-type-bool+) #'storage-deserialize-boolean)
((#.+portable-storage-type-object+) #'storage-deserialize-section)
((#.+portable-storage-type-array+) #'storage-deserialize-vector)))
(defun storage-serialize-varint (n)
"Return the variable size integer encoding of an integer N."
(cond
((<= n 63)
(integer->bytes (logior (ash n 2) +portable-storage-raw-size-byte+) :size 1))
((<= n 16383)
(integer->bytes (logior (ash n 2) +portable-storage-raw-size-word+) :size 2))
((<= n 1073741823)
(integer->bytes (logior (ash n 2) +portable-storage-raw-size-double-word+) :size 4))
((<= n 4611686018427387903)
(integer->bytes (logior (ash n 2) +portable-storage-raw-size-quad-word+) :size 8))
(t
(error "~d is too big to be serialized." n))))
(defun storage-deserialize-varint (bytes &key (start 0))
"Read the variable size integer encoded in BYTES."
(let* ((n (ash (aref bytes start) -2))
(size (ldb (byte 2 0) (aref bytes start)))
(end (+ start (ecase size
((#.+portable-storage-raw-size-byte+) 1)
((#.+portable-storage-raw-size-word+) 2)
((#.+portable-storage-raw-size-double-word+) 4)
((#.+portable-storage-raw-size-quad-word+) 8))))
(x (bytes->integer bytes :start (+ start 1) :end end)))
(values (logior n (ash x 6)) (- end start))))
(defun storage-serialize-int64 (object &key in-vector)
(let ((n (if (minusp object)
(+ 18446744073709551616 object)
object)))
(concatenate 'octet-vector
(unless in-vector (vector +portable-storage-type-int64+))
(integer->bytes n :size 8))))
(defun storage-deserialize-int64 (data offset)
(let* ((n (bytes->integer data :start offset :end (+ offset 8)))
(negative (logbitp 63 n)))
(values (if negative (- n 18446744073709551616) n)
8)))
(defun storage-serialize-int32 (object &key in-vector)
(let ((n (if (minusp object)
(+ 4294967296 object)
object)))
(concatenate 'octet-vector
(unless in-vector (vector +portable-storage-type-int32+))
(integer->bytes n :size 4))))
(defun storage-deserialize-int32 (data offset)
(let* ((n (bytes->integer data :start offset :end (+ offset 4)))
(negative (logbitp 31 n)))
(values (if negative (- n 4294967296) n)
4)))
(defun storage-serialize-int16 (object &key in-vector)
(let ((n (if (minusp object)
(+ 65536 object)
object)))
(concatenate 'octet-vector
(unless in-vector (vector +portable-storage-type-int8+))
(integer->bytes n :size 2))))
(defun storage-deserialize-int16 (data offset)
(let* ((n (bytes->integer data :start offset :end (+ offset 2)))
(negative (logbitp 15 n)))
(values (if negative (- n 65536) n)
2)))
(defun storage-serialize-int8 (object &key in-vector)
(let ((n (if (minusp object)
(+ 256 object)
object)))
(concatenate 'octet-vector
(unless in-vector (vector +portable-storage-type-int8+))
(integer->bytes n :size 1))))
(defun storage-deserialize-int8 (data offset)
(let* ((n (bytes->integer data :start offset :end (+ offset 1)))
(negative (logbitp 7 n)))
(values (if negative (- n 256) n)
1)))
(defun storage-serialize-uint64 (object &key in-vector)
(concatenate 'octet-vector
(unless in-vector (vector +portable-storage-type-uint64+))
(integer->bytes object :size 8)))
(defun storage-deserialize-uint64 (data offset)
(bytes->integer data :start offset :end (+ offset 8)))
(defun storage-serialize-uint32 (object &key in-vector)
(concatenate 'octet-vector
(unless in-vector (vector +portable-storage-type-uint32+))
(integer->bytes object :size 4)))
(defun storage-deserialize-uint32 (data offset)
(bytes->integer data :start offset :end (+ offset 4)))
(defun storage-serialize-uint16 (object &key in-vector)
(concatenate 'octet-vector
(unless in-vector (vector +portable-storage-type-uint16+))
(integer->bytes object :size 2)))
(defun storage-deserialize-uint16 (data offset)
(bytes->integer data :start offset :end (+ offset 2)))
(defun storage-serialize-uint8 (object &key in-vector)
(concatenate 'octet-vector
(unless in-vector (vector +portable-storage-type-uint8+))
(integer->bytes object :size 1)))
(defun storage-deserialize-uint8 (data offset)
(bytes->integer data :start offset :end (+ offset 1)))
(defun storage-serialize-double-float (object &key in-vector)
(concatenate 'octet-vector
(unless in-vector (vector +portable-storage-type-double+))
(integer->bytes (ieee-floats:encode-float64 object))))
(defun storage-deserialize-double-float (data offset)
(values (ieee-floats:decode-float64 (bytes->integer data :start offset :end (+ offset 8)))
8))
(defun storage-serialize-boolean (object &key in-vector)
(concatenate 'octet-vector
(unless in-vector (vector +portable-storage-type-bool+))
(vector (if object 1 0))))
(defun storage-deserialize-boolean (data offset)
(values (plusp (aref data offset))
1))
(defun storage-serialize-vector (objects &key in-vector)
(with-octet-output-stream (result)
(let* ((size (length objects))
(type (lisp-type->storage-type (let ((type (array-element-type objects)))
(if (eq type 't)
(type-of (aref objects 0))
type))))
(serialization-function (storage-type->serialization-function type)))
(unless in-vector
(write-byte (logior type +portable-storage-array-flag+) result))
(write-sequence (storage-serialize-varint size) result)
(dotimes (i size)
(let ((data (funcall serialization-function (aref objects i) :in-vector t)))
(write-sequence data result))))))
(defun storage-deserialize-vector (data offset type)
(multiple-value-bind (size s0)
(storage-deserialize-varint data :start offset)
(let* ((lisp-type (storage-type->lisp-type type))
(deserialization-function (storage-type->deserialization-function type))
(result (make-array size :element-type lisp-type)))
(dotimes (i size)
(multiple-value-bind (thing s1)
(funcall deserialization-function data (+ offset s0))
(setf (aref result i) thing)
(incf s0 s1)))
(values result s0))))
(defun storage-serialize-string (object &key in-vector)
(let ((data (string->bytes object)))
(concatenate 'octet-vector
(unless in-vector (vector +portable-storage-type-string+))
(storage-serialize-varint (length data))
data)))
(defun storage-deserialize-string (data offset)
(multiple-value-bind (size s0)
(storage-deserialize-varint data :start offset)
(values (bytes->string data :start (+ offset s0) :end (+ offset s0 size))
(+ s0 size))))
(defun storage-serialize-section (object &key in-vector)
(with-octet-output-stream (result)
(let ((size (length object)))
(unless in-vector
(write-byte +portable-storage-type-object+ result))
(write-sequence (storage-serialize-varint size) result)
(dolist (pair object)
(let ((name (string->bytes (if (stringp (car pair))
(car pair)
(lisp-name->json-name (symbol-name (car pair))))))
(thing (cdr pair)))
(when (> (length name) 255)
(error "storage entry name is too long: ~a" name))
(write-byte (length name) result)
(write-sequence name result)
(write-sequence (storage-serialize thing) result))))))
(defun storage-deserialize-section (data offset)
(declare (optimize (debug 3)))
(multiple-value-bind (size s0)
(storage-deserialize-varint data :start offset)
(let ((result '()))
(dotimes (i size)
(let* ((name-size (aref data (+ offset s0)))
(name (intern (json-name->lisp-name (bytes->string (subseq data
(+ offset s0 1)
(+ offset s0 1 name-size))))
:keyword)))
(multiple-value-bind (thing s1)
(storage-deserialize data (+ offset s0 1 name-size))
(push (cons name thing) result)
(incf s0 (+ 1 name-size s1)))))
(values (reverse result) s0))))
(defun storage-serialize (object)
(multiple-value-bind (object lisp-type)
(if (and (consp object) (numberp (car object)))
(values (car object) (cdr object))
(values object (type-of object)))
(funcall (storage-type->serialization-function (lisp-type->storage-type lisp-type)) object)))
(defun storage-deserialize (data offset)
(let ((type (aref data offset)))
(multiple-value-bind (result s0)
(if (zerop (logand type +portable-storage-array-flag+))
(funcall (storage-type->deserialization-function type) data (+ offset 1))
(storage-deserialize-vector data (+ offset 1) (logxor type +portable-storage-array-flag+)))
(values result (+ 1 s0)))))
(defun serialize-to-binary-storage (object)
"Return an OBJECT as a byte vector."
(concatenate 'octet-vector
+portable-storage-header+
(storage-serialize-section object :in-vector t)))
(defun deserialize-from-binary-storage (data offset)
"Return the object whose serialization starts at OFFSET in DATA.
The second returned value is the size of the serialized object."
(let* ((header-length (length +portable-storage-header+))
(header (subseq data offset (+ offset header-length))))
(unless (equalp header +portable-storage-header+)
(error "invalid binary storage header"))
(storage-deserialize-section data (+ offset header-length))))
| 14,086 | Common Lisp | .lisp | 271 | 43.457565 | 103 | 0.633566 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | b696e41a54441d2263247393069ef78700b8d375f9762796ecd467e2401744d0 | 8,049 | [
-1
] |
8,050 | key.lisp | glv2_cl-monero-tools/monero-tools/crypto/key.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2016-2018 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-tools)
(defun generate-secret-key ()
"Generate a new random secret key."
(random-scalar))
(defun secret-key->public-key (secret-key)
"Compute the public key matching a SECRET-KEY."
(check-type secret-key (octet-vector #.+key-length+))
(let* ((x (bytes->integer secret-key))
(r (mod x +l+))
(y (point* +g+ r)))
(point->bytes y)))
(defun secret-spend-key->secret-view-key (secret-spend-key)
"Derive the secret view key from the SECRET-SPEND-KEY."
(check-type secret-spend-key (octet-vector #.+key-length+))
(fast-hash secret-spend-key))
(defun recover-keys (secret-spend-key)
"Compute the public-spend-key, secret-view-key and public-view-key
from the SECRET-SPEND-KEY."
(check-type secret-spend-key (octet-vector #.+key-length+))
(let* ((secret-view-key (secret-spend-key->secret-view-key secret-spend-key))
(public-spend-key (secret-key->public-key secret-spend-key))
(public-view-key (secret-key->public-key secret-view-key)))
(list (cons :public-spend-key public-spend-key)
(cons :public-view-key public-view-key)
(cons :secret-spend-key secret-spend-key)
(cons :secret-view-key secret-view-key))))
(defun generate-keys ()
"Generate a new set of keys."
(let ((secret-spend-key (generate-secret-key)))
(recover-keys secret-spend-key)))
(defun derive-key (public-key secret-key)
"Compute a shared secret from a user's PUBLIC-KEY and your SECRET-KEY."
(check-type public-key (octet-vector #.+key-length+))
(check-type secret-key (octet-vector #.+key-length+))
(let* ((p (bytes->point public-key))
(s (bytes->integer secret-key))
(k (point*8 (point* p s))))
(point->bytes k)))
(defun derivation->scalar (derivation output-index)
"Compute a scalar that can be used for deriving an output's keys
from a key DERIVATION and an OUTPUT-INDEX."
(check-type derivation (octet-vector #.+key-length+))
(check-type output-index (integer 0))
(let ((data (concatenate 'octet-vector derivation (integer->bytes output-index :varint t))))
(hash-to-scalar data)))
(defun derive-output-public-key (derivation output-index public-spend-key)
"Compute an output's public key from a key DERIVATION, an
OUTPUT-INDEX and a PUBLIC-SPEND-KEY."
(check-type derivation (octet-vector #.+key-length+))
(check-type output-index (integer 0))
(check-type public-spend-key (octet-vector #.+key-length+))
(let ((x (bytes->integer (derivation->scalar derivation output-index)))
(p (bytes->point public-spend-key)))
(point->bytes (point+ p (point* +g+ x)))))
(defun derive-output-secret-key (derivation output-index secret-spend-key)
"Compute an output's secret key from a key DERIVATION, an
OUTPUT-INDEX and a SECRET-SPEND-KEY."
(check-type derivation (octet-vector #.+key-length+))
(check-type output-index (integer 0))
(check-type secret-spend-key (octet-vector #.+key-length+))
(let ((x (bytes->integer (derivation->scalar derivation output-index)))
(s (bytes->integer secret-spend-key)))
(integer->bytes (mod (+ x s) +l+) :size +key-length+)))
(define-constant +subkey-prefix+ (map 'octet-vector #'char-code '(#\S #\u #\b #\A #\d #\d #\r #\nul))
:test #'equalp)
(defun derive-subkey-secret (secret-view-key major-index minor-index)
"Compute the secret component of a subkey from its MAJOR-INDEX,
its MINOR-INDEX and the main SECRET-VIEW-KEY."
(check-type secret-view-key (octet-vector #.+key-length+))
(check-type major-index (integer 0 *))
(check-type minor-index (integer 0 *))
(let ((data (concatenate 'octet-vector
+subkey-prefix+
secret-view-key
(integer->bytes major-index :size 4)
(integer->bytes minor-index :size 4))))
(hash-to-scalar data)))
(defun derive-output-secret-subkey (derivation output-index secret-view-key secret-spend-key major-index minor-index)
"Compute the secret key of an output to a subaddress from a key
DERIVATION, an OUTPUT-INDEX, a SECRET-VIEW-KEY, a SECRET-SPEND-KEY,
and the subaddress' MAJOR-INDEX and MINOR-INDEX."
(check-type derivation (octet-vector #.+key-length+))
(check-type output-index (integer 0 *))
(check-type secret-view-key (octet-vector #.+key-length+))
(check-type secret-spend-key (octet-vector #.+key-length+))
(check-type major-index (integer 0 *))
(check-type minor-index (integer 0 *))
(let ((x (bytes->integer (derive-output-secret-key derivation output-index secret-spend-key)))
(s (bytes->integer (derive-subkey-secret secret-view-key major-index minor-index))))
(integer->bytes (mod (+ x s) +l+) :size +key-length+)))
(defun derive-secret-spend-subkey (secret-view-key secret-spend-key major-index minor-index)
"Compute the secret spend key of a subaddress from its MAJOR-INDEX,
its MINOR-INDEX, the main SECRET-VIEW-KEY and the main
SECRET-SPEND-KEY."
(check-type secret-view-key (octet-vector #.+key-length+))
(check-type secret-spend-key (octet-vector #.+key-length+))
(check-type major-index (integer 0 *))
(check-type minor-index (integer 0 *))
(let* ((b (bytes->integer secret-spend-key))
(h (bytes->integer (derive-subkey-secret secret-view-key major-index minor-index)))
(d (mod (+ b h) +l+)))
(integer->bytes d :size +key-length+)))
(defun derive-public-spend-subkey (secret-view-key public-spend-key major-index minor-index)
"Compute the public spend key of a subaddress from its MAJOR-INDEX,
its MINOR-INDEX, the main SECRET-VIEW-KEY and the main
PUBLIC-SPEND-KEY."
(check-type secret-view-key (octet-vector #.+key-length+))
(check-type public-spend-key (octet-vector #.+key-length+))
(check-type major-index (integer 0 *))
(check-type minor-index (integer 0 *))
(let* ((b (bytes->point public-spend-key))
(h (bytes->integer (derive-subkey-secret secret-view-key major-index minor-index)))
(d (point+ b (point* +g+ h))))
(point->bytes d)))
(defun output-public-key->public-spend-subkey (derivation output-index output-public-key)
"Derive the public spend key of a subaddress from the DERIVATION, OUTPUT-INDEX
and OUTPUT-PUBLIC-KEY of a transaction output for that subaddress."
(check-type derivation (octet-vector #.+key-length+))
(check-type output-index (integer 0 *))
(check-type output-public-key (octet-vector #.+key-length+))
(let* ((x (bytes->integer (derivation->scalar derivation output-index)))
(p (bytes->point output-public-key))
(d (point- p (point* +g+ x))))
(point->bytes d)))
(defun public-spend-subkey->public-view-subkey (secret-view-key public-spend-subkey)
"Compute the public view key of a subaddress from the main SECRET-VIEW-KEY and
the PUBLIC-SPEND-SUBKEY."
(check-type secret-view-key (octet-vector #.+key-length+))
(check-type public-spend-subkey (octet-vector #.+key-length+))
(let* ((a (bytes->integer secret-view-key))
(d (bytes->point public-spend-subkey))
(c (point* d a)))
(point->bytes c)))
(defun compute-subaddress-indexes-table (secret-view-key public-spend-key max-major-index max-minor-index)
"Compute a hash table in which keys are public-spend-subkeys and values are
the indexes associated to the public-spend-subkeys."
(check-type secret-view-key (octet-vector #.+key-length+))
(check-type public-spend-key (octet-vector #.+key-length+))
(check-type max-major-index (integer 0 *))
(check-type max-minor-index (integer 0 *))
(let ((table (make-hash-table :test #'equalp)))
(setf (gethash public-spend-key table) '(0 0))
(dotimes (i (1+ max-major-index))
(dotimes (j (1+ max-minor-index))
(let ((public-spend-subkey (derive-public-spend-subkey secret-view-key
public-spend-key
i j)))
(setf (gethash public-spend-subkey table) (list i j)))))
table))
| 8,207 | Common Lisp | .lisp | 153 | 48.287582 | 117 | 0.682599 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 181ee5da7a71c4ed67ab64007f2aa4905cd5b987e4622d866d1a4da951e770d6 | 8,050 | [
-1
] |
8,051 | random-math.lisp | glv2_cl-monero-tools/monero-tools/crypto/random-math.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2019 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-tools)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defconstant +total-latency+ (* 15 3))
(defconstant +num-instructions-min+ 60)
(defconstant +num-instructions-max+ 70)
(defconstant +alu-count-mul+ 1)
(defconstant +alu-count+ 3)
(defconstant +mul+ 0)
(defconstant +add+ 1)
(defconstant +sub+ 2)
(defconstant +ror+ 3)
(defconstant +rol+ 4)
(defconstant +xor+ 5)
(defconstant +ret+ 6)
(defconstant +instruction-count+ 6)
(define-constant +op-latency+
(make-array +instruction-count+
:element-type 'fixnum
:initial-contents '(3 2 1 2 2 1))
:test #'equalp)
(define-constant +asic-op-latency+
(make-array +instruction-count+
:element-type 'fixnum
:initial-contents '(3 1 1 1 1 1))
:test #'equalp)
(define-constant +op-alus+
(make-array +instruction-count+
:element-type 'fixnum
:initial-contents (list +alu-count-mul+
+alu-count+
+alu-count+
+alu-count+
+alu-count+
+alu-count+))
:test #'equalp)
(defstruct instruction
(opcode 0 :type (unsigned-byte 8))
(dst-index 0 :type (unsigned-byte 8))
(src-index 0 :type (unsigned-byte 8))
(c 0 :type (unsigned-byte 32))))
(declaim (inline random-math-init))
(defun random-math-init (code height)
(declare (type (simple-array instruction (*)) code)
(type fixnum height)
(optimize (speed 3) (space 0) (safety 0) (debug 0)))
(let* ((data-index 32)
(data (make-array data-index :element-type '(unsigned-byte 8) :initial-element 0))
(code-size 0)
(r8-used nil))
(declare (type (integer 0 32) data-index)
(type (simple-array (unsigned-byte 8) (32)) data)
(dynamic-extent data)
(type fixnum code-size)
(type boolean r8-used))
(flet ((check-data (bytes-needed data data-size)
(declare (type (integer 0 32) bytes-needed data-size)
(type (simple-array (unsigned-byte 8) (32)) data))
(when (> (+ data-index bytes-needed) data-size)
(digest-sequence :blake256 data :digest data)
(setf data-index 0)))
(decode-opcode (c)
(declare (type (unsigned-byte 8) c))
(ldb (byte 3 0) c))
(decode-dst-index (c)
(declare (type (unsigned-byte 8) c))
(ldb (byte 2 3) c))
(decode-src-index (c)
(declare (type (unsigned-byte 8) c))
(ldb (byte 3 5) c)))
(declare (inline check-data decode-opcode decode-dst-index decode-src-index))
(setf (ub64ref/le data 0) height
(aref data 20) #xda)
(loop do (let ((latency (make-array 9
:element-type 'fixnum
:initial-element 0))
(asic-latency (make-array 9
:element-type 'fixnum
:initial-element 0))
(inst-data (make-array 9
:element-type 'fixnum
:initial-contents '(0 1 2 3 #xffffff #xffffff
#xffffff #xffffff #xffffff)))
(alu-busy (make-array (list (1+ +total-latency+) +alu-count+)
:element-type 'boolean
:initial-element nil))
(is-rotation (make-array +instruction-count+
:element-type 'boolean
:initial-contents '(nil nil nil t t nil)))
(rotated (make-array 4
:element-type 'boolean
:initial-element nil))
(rotate-count 0)
(num-retries 0)
(total-iterations 0))
(declare (type (simple-array fixnum (9)) latency asic-latency inst-data)
(type (simple-array boolean (46 3)) alu-busy)
(type (simple-array boolean (6)) is-rotation)
(type (simple-array boolean (4)) rotated)
(dynamic-extent latency asic-latency inst-data alu-busy is-rotation rotated)
(type fixnum rotate-count num-retries total-iterations))
(setf code-size 0)
(loop while (and (or (< (aref latency 0) +total-latency+)
(< (aref latency 1) +total-latency+)
(< (aref latency 2) +total-latency+)
(< (aref latency 3) +total-latency+))
(< num-retries 64))
do (progn
(incf total-iterations)
(when (> total-iterations 256)
(return))
(check-data 1 data (length data))
(let* ((c (aref data data-index))
(opcode (decode-opcode c))
(dst-index (decode-dst-index c))
(src-index (decode-src-index c)))
(declare (type (unsigned-byte 8) c opcode dst-index src-index))
(incf data-index)
(cond
((= opcode 5)
(check-data 1 data (length data))
(setf opcode (if (< (aref data data-index) 128) +ror+ +rol+))
(incf data-index))
((>= opcode 6)
(setf opcode +xor+))
(t
(setf opcode (if (<= opcode 2) +mul+ (- opcode 2)))))
(let ((a dst-index)
(b src-index))
(declare (type (unsigned-byte 8) a b))
(when (and (or (= opcode +add+) (= opcode +sub+) (= opcode +xor+))
(= a b))
(setf b 8
src-index 8))
(unless (or (and (aref is-rotation opcode) (aref rotated a))
(and (/= opcode +mul+)
(= (logand (aref inst-data a) #xffff00)
(+ (ash opcode 8)
(ash (logand (aref inst-data b) 255) 16)))))
(let ((next-latency (max (aref latency a) (aref latency b)))
(alu-index -1))
(declare (type fixnum next-latency alu-index))
(loop while (< next-latency +total-latency+) do
(loop for i from (1- (aref +op-alus+ opcode)) downto 0 do
(unless (or (aref alu-busy next-latency i)
(and (= opcode +add+)
(aref alu-busy (1+ next-latency) i))
(and (aref is-rotation opcode)
(< next-latency (* rotate-count (aref +op-latency+ opcode)))))
(setf alu-index i)
(return)))
(when (>= alu-index 0)
(return))
(incf next-latency))
(unless (> next-latency (+ (aref latency a) 7))
(incf next-latency (aref +op-latency+ opcode))
(if (<= next-latency +total-latency+)
(progn
(when (aref is-rotation opcode)
(incf rotate-count))
(setf (aref alu-busy (- next-latency (aref +op-latency+ opcode)) alu-index) t
(aref latency a) next-latency
(aref asic-latency a) (+ (max (aref asic-latency a) (aref asic-latency b))
(aref +asic-op-latency+ opcode))
(aref rotated a) (aref is-rotation opcode)
(aref inst-data a) (+ code-size
(ash opcode 8)
(ash (logand (aref inst-data b) 255) 16))
(aref code code-size) (make-instruction :opcode opcode
:dst-index dst-index
:src-index src-index
:c 0))
(when (= src-index 8)
(setf r8-used t))
(when (= opcode +add+)
(setf (aref alu-busy (1+ (- next-latency (aref +op-latency+ opcode))) alu-index) t)
(check-data 4 data (length data))
(setf (instruction-c (aref code code-size)) (ub32ref/le data data-index))
(incf data-index 4))
(incf code-size)
(when (>= code-size +num-instructions-min+)
(return)))
(incf num-retries)))))))))
(let ((prev-code-size code-size))
(declare (type fixnum prev-code-size))
(loop while (and (< code-size +num-instructions-max+)
(< (aref asic-latency 0) +total-latency+)
(< (aref asic-latency 1) +total-latency+)
(< (aref asic-latency 2) +total-latency+)
(< (aref asic-latency 3) +total-latency+))
do (let* ((min-idx 0)
(max-idx 0)
(pattern (make-array 3
:element-type '(unsigned-byte 8)
:initial-contents (list +ror+ +mul+ +mul+)))
(opcode (aref pattern (mod (- code-size prev-code-size) 3))))
(declare (type fixnum min-idx max-idx)
(type (simple-array (unsigned-byte 8) (3)) pattern)
(dynamic-extent pattern)
(type (unsigned-byte 8) opcode))
(loop for i from 1 below 4 do
(when (< (aref asic-latency i) (aref asic-latency min-idx))
(setf min-idx i))
(when (> (aref asic-latency i) (aref asic-latency max-idx))
(setf max-idx i)))
(setf (aref latency min-idx) (+ (aref latency max-idx)
(aref +op-latency+ opcode))
(aref asic-latency min-idx) (+ (aref asic-latency max-idx)
(aref +asic-op-latency+ opcode))
(aref code code-size) (make-instruction :opcode opcode
:dst-index min-idx
:src-index max-idx
:c 0))
(incf code-size)))))
while (or (not r8-used)
(< code-size +num-instructions-min+)
(> code-size +num-instructions-max+)))
(setf (aref code code-size) (make-instruction :opcode +ret+
:dst-index 0
:src-index 0
:c 0))
code-size)))
(declaim (inline generate-random-math-forms))
(defun generate-random-math-forms (height)
(declare (type fixnum height)
(optimize (speed 3) (space 0) (safety 0) (debug 0)))
(let ((code (make-array (1+ +num-instructions-max+)
:element-type 'instruction
:initial-element (make-instruction :opcode +ret+
:dst-index 0
:src-index 0
:c 0))))
(declare (type (simple-array instruction (#.(1+ +num-instructions-max+))) code)
(dynamic-extent code))
(random-math-init code height)
(flet ((choose-register (index)
(declare (type (integer 0 8) height)
(optimize (speed 3) (space 0) (safety 0) (debug 0)))
(case index
(0 'r0)
(1 'r1)
(2 'r2)
(3 'r3)
(4 'r4)
(5 'r5)
(6 'r6)
(7 'r7)
(8 'r8))))
(loop for op across code
until (= (instruction-opcode op) #.+ret+)
collect (let ((src (choose-register (instruction-src-index op)))
(dst (choose-register (instruction-dst-index op))))
(case (instruction-opcode op)
(#.+mul+ `(setf ,dst (mod32* ,dst ,src)))
(#.+add+ `(setf ,dst (mod32+ ,dst (mod32+ ,(instruction-c op) ,src))))
(#.+sub+ `(setf ,dst (mod32- ,dst ,src)))
(#.+ror+ `(setf ,dst (ror32 ,dst (logand ,src #x1f))))
(#.+rol+ `(setf ,dst (rol32 ,dst (logand ,src #x1f))))
(#.+xor+ `(setf ,dst (logxor ,dst ,src)))))))))
(declaim (inline generate-random-math-function))
(defun generate-random-math-function (height)
(declare (type fixnum height)
(optimize (speed 3) (space 0) (safety 0) (debug 0)))
(let ((forms (generate-random-math-forms height))
(*compile-print* nil)
(*compile-verbose* nil))
(compile nil
`(lambda (r)
(declare (type (simple-array (unsigned-byte 32) (9)) r)
(optimize (speed 3) (space 0) (safety 0) (debug 0)))
(let ((r0 (aref r 0))
(r1 (aref r 1))
(r2 (aref r 2))
(r3 (aref r 3))
(r4 (aref r 4))
(r5 (aref r 5))
(r6 (aref r 6))
(r7 (aref r 7))
(r8 (aref r 8)))
(declare (type (unsigned-byte 32) r0 r1 r2 r3 r4 r5 r6 r7 r8))
,@forms
(setf (aref r 0) r0
(aref r 1) r1
(aref r 2) r2
(aref r 3) r3
(aref r 4) r4
(aref r 5) r5
(aref r 6) r6
(aref r 7) r7
(aref r 8) r8))
(values)))))
| 17,111 | Common Lisp | .lisp | 294 | 30.751701 | 129 | 0.377655 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 48cdfddb266fa7b6158be1c12470c80eae79ec93d99cdb8115e50750a2026e95 | 8,051 | [
-1
] |
8,052 | randomx-service.lisp | glv2_cl-monero-tools/monero-tools/crypto/randomx-service.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-tools)
(defparameter *randomx-service-host* "127.0.0.1"
"Location of the randomx-service server.")
(defparameter *randomx-service-port* 39093
"Port on which the randomx-service server expects connections.")
(defun randomx-service-info (&key (host *randomx-service-host*) (port *randomx-service-port*))
"Get information about a running randomx-service daemon."
(let* ((url (format nil "http://~a:~d/info" host port))
(body (dex:get url)))
(decode-json-from-string body)))
(defun randomx-service-reseed (seed &key (host *randomx-service-host*) (port *randomx-service-port*))
"Reinitialize a randomx-service daemon with the provided SEED."
(check-type seed octet-vector)
(let ((url (format nil "http://~a:~d/seed" host port))
(headers '(("Content-Type" . "application/x.randomx+bin"))))
(dex:post url :headers headers :content seed)
t))
(defun randomx-service-hash (data &key seed (host *randomx-service-host*) (port *randomx-service-port*))
"Calculate a RandomX hash of the DATA octet vector. If SEED is provided and
if it is not equal to the seed the randomx-service daemon has been initialized
with, an error is signalled."
(check-type data octet-vector)
(check-type seed (or null octet-vector))
(let* ((url (format nil "http://~a:~d/hash" host port))
(headers (append '(("Content-Type" . "application/x.randomx+bin")
("Accept" . "application/x.randomx+bin"))
(when seed
(list (cons "RandomX-Seed"
(bytes->hex-string seed))))))
(body (dex:post url :headers headers :content data)))
body))
(defun randomx-service-hash-batch (inputs &key seed (host *randomx-service-host*) (port *randomx-service-port*))
"Calculate the RandomX hashes of the INPUTS. INPUTS must be a list of at most
256 octet-vectors. If SEED is provided and if it is not equal to the seed the
randomx-service daemon has been initialized with, an error is signalled."
(check-type inputs list)
(check-type seed (or null octet-vector))
(when (> (length inputs) 256)
(error "Too many inputs. The maximum size is 256."))
(let* ((url (format nil "http://~a:~d/batch" host port))
(headers (append '(("Content-Type" . "application/x.randomx.batch+bin")
("Accept" . "application/x.randomx.batch+bin"))
(when seed
(list (cons "RandomX-Seed"
(bytes->hex-string seed))))))
(content (with-octet-output-stream (out)
(mapc (lambda (data)
(let ((length (length data)))
(when (> length 127)
(error "Too much data."))
(write-byte length out)
(write-sequence data out)))
inputs)))
(body (dex:post url :headers headers :content content)))
(iter (repeat (length inputs))
(for i from 0 by 33)
(unless (= (aref body i) 32)
(error "Malformed binary response"))
(collect (subseq body (1+ i) (+ i 33))))))
| 3,462 | Common Lisp | .lisp | 63 | 44.31746 | 112 | 0.604363 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 2b3794039c622649d6e4dd7b5ceb4f92ac56c4ef79a3f1d93930cf814c8fa707 | 8,052 | [
-1
] |
8,053 | randomx.lisp | glv2_cl-monero-tools/monero-tools/crypto/randomx.lisp | ;;;; This file is part of monero-tools
;;;; Copyright 2020 Guillaume LE VAILLANT
;;;; Distributed under the GNU GPL v3 or later.
;;;; See the file LICENSE for terms of use and distribution.
(in-package :monero-tools)
(defconstant +seed-hash-epoch-blocks+ 2048)
(defconstant +seed-hash-epoch-lag+ 64)
(defun randomx-seed-height (height)
"Find the height at which RandomX was last seeded."
(if (<= height (+ +seed-hash-epoch-blocks+ +seed-hash-epoch-lag+))
0
(logand (- height +seed-hash-epoch-lag+ 1)
(lognot (1- +seed-hash-epoch-blocks+)))))
(defun randomx (data seed)
(let* ((info (ignore-errors (randomx-service-info)))
(current-seed (geta info :seed)))
(unless info
(error "Connection to randomx-service failed."))
(unless (and current-seed
(string= current-seed (bytes->hex-string seed)))
(randomx-service-reseed seed))
(randomx-service-hash data :seed seed)))
| 952 | Common Lisp | .lisp | 22 | 38.318182 | 68 | 0.674595 | glv2/cl-monero-tools | 19 | 4 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | dd6740322a3cc2f48d69b20d5d8cd9996dfa1b45fba610d03da2b4a37c558720 | 8,053 | [
-1
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.